home *** CD-ROM | disk | FTP | other *** search
- #include "lack.h"
-
- ki;
- extern lap *curapp;
- extern lap *lapps[NUM_APPS];
- extern int apid;
-
- /* trap2.c: */
- int _super_aes(unsigned long);
-
- #define IN_UPDATE 0x1
- #define IN_MCTRL 0x2
-
- struct wind
- {
- int w_handle, w_visible, w_owner;
- struct wind *w_ap_next, *w_gl_next;
- };
-
- Wind_create(AESP *call)
- {
- int handle, sr;
- struct wind *new;
- struct wind *old=curapp->windows;
-
- handle=call->int_out[0];
- if(handle<0) return 0;
- sr=spl7();
- new=(struct wind *)kmalloc(sizeof(*new));
- spl(sr);
- DEBUG("wind_create: handle %d, structure at %lx", handle, new);
- new->w_handle=handle;
- new->w_visible=FALSE;
- new->w_ap_next=curapp->windows;
- curapp->windows=new;
- return 0;
- }
-
- Wind_delete(AESP *call)
- {
- int handle=call->int_in[0];
- struct wind *w=curapp->windows;
- struct wind _prev;
- struct wind *prev=&_prev;
-
- DEBUG("deleting window %d", handle);
- prev->w_ap_next=w;
- while(w)
- if(w->w_handle != handle)
- {
- prev=w;
- w=w->w_ap_next;
- }
- else break;
- if(!w) ALERT("wind_delete: apid %d does not owm window %d", apid, handle);
- else
- {
- prev->w_ap_next=w->w_ap_next;
- kfree(w);
- curapp->windows=_prev.w_ap_next;
- }
- return 0;
- }
-
- Wind_open(AESP *call)
- {
- struct wind *w=curapp->windows;
- int handle=call->int_in[0];
-
- DEBUG("opening window %d", handle);
- while(w)
- if(w->w_handle != handle)
- w=w->w_ap_next;
- else break;
- if(w) w->w_visible=TRUE;
- else ALERT("wind_open apid %d does not own window handle %d",
- apid, handle);
- return 0;
- }
-
- Wind_close(AESP *call)
- {
- struct wind *w=curapp->windows;
- int handle=call->int_in[0];
-
- DEBUG("closing window %d", handle);
- while(w)
- {
- if(w->w_handle != handle)
- w=w->w_ap_next;
- else break;
- }
- if(w) w->w_visible=FALSE;
- else ALERT("wind_close apid %d does not own window handle %d",
- apid, handle);
- return 0;
- }
-
- int
- Wind_update(AESP *call)
- {
- int begend=call->int_in[0];
-
- TRACE("wind_update(%d)", begend);
- switch(begend)
- {
- case END_UPDATE:
- curapp->update &= ~IN_UPDATE;
- break;
- case BEG_UPDATE:
- curapp->update |= IN_UPDATE;
- break;
- case END_MCTRL:
- curapp->update &= ~IN_MCTRL;
- break;
- case BEG_MCTRL:
- curapp->update |= IN_MCTRL;
- break;
- default:
- DEBUG("wind_update: unknown mode");
- }
- return 0;
- }
-
- int
- _wind_cleanup(void)
- {
- /* walk down the caller's window list making the aes call wind_delete
- */
- struct wind *old, *w=curapp->windows;
- int handle;
-
- DEBUG("lack: emulating wind_new for apid %d, clearing its windows", apid);
- while(w)
- {
- if(w->w_visible) wind_close(w->w_handle);
- wind_delete(w->w_handle);
- old=w;
- w=w->w_ap_next;
- kfree(old);
- }
- curapp->windows=NULL;
- }
-
- int
- _wind_new(void)
- {
- /* delete the callers window + all ackessories windows, leave prgs
- * in ackessory slots alone.
- */
- lap *ap;
- struct wind *w, *old;
- int c;
-
- DEBUG("lack: emulating wind_new, clearing all windows");
- for(c=2; c<NUM_APPS - 1; ap=lapps[c++])
- {
- if(ap)
- if(ap->acc)
- if(!(ap->acc->free || ap->acc->isprg))
- /* neither free nor a program */
- {
- w=ap->windows;
- while(w)
- {
- if(w->w_visible) wind_close(w->w_handle);
- wind_delete(w->w_handle);
- old=w;
- w=w->w_ap_next;
- kfree(old);
- }
- ap->windows=NULL;
- }
- }
- w=lapps[0]->windows;
- while(w)
- {
- if(w->w_visible) wind_close(w->w_handle);
- wind_delete(w->w_handle);
- old=w;
- w=w->w_ap_next;
- kfree(old);
- }
- lapps[0]->windows=NULL;
- return 1;
- }
-
- Wind_new(AESP *call)
- {
- int (*old__aes__)()=__aes__;
- AESP *old_aes=_aesparams;
- NEW_AESP(a);
-
- _aesparams=&a;
- __aes__=_super_aes;
- if(apid==0) _wind_new();
- else _wind_cleanup();
- if (curapp->update & IN_UPDATE)
- {
- DEBUG("wind_new: ending update");
- wind_update(END_UPDATE);
- }
- if (curapp->update & IN_MCTRL)
- {
- DEBUG("wind_new: ending mctrl");
- wind_update(END_MCTRL);
- }
- __aes__=_super_aes;
- _aesparams=old_aes;
- __aes__=old__aes__;
- /* call->int_out[0]=1; gemlib says this is void */
- return 1;
- }
-
- void
- desk_zap_windows(void)
- {
- /* desktop has done wind_new and launched a prg */
- struct wind *die, *next;
- int c;
-
- DEBUG("desktop has cleared all windows");
- for(c=0; c<NUM_APPS; c++)
- if(lapps[c])
- {
- next=lapps[c]->windows;
- while(next)
- {
- die=next;
- next=next->w_ap_next;
- kfree(die);
- }
- lapps[c]->windows=NULL;
- }
- }
-