Next version of JABA
[jabaws.git] / binaries / src / fasta34 / checkevent.c
1
2 /* Copyright 1995 William R. Pearson */
3
4 /* used only in Mac versions to provide mac multitasking */
5
6 #include <stdlib.h>
7
8 #ifdef __MWERKS__
9 #include <sioux.h>
10 #endif
11
12 #define SLEEP                   2L
13 #define NIL_MOUSE_REGION        0L
14
15 #define WNE_TRAP_NUM    0x60
16 #define UNIMPL_TRAP_NUM 0x9F
17 #define SUSPEND_RESUME_BIT      0x0001
18 #define ACTIVATING              1
19 #define RESUMING                1
20
21 Boolean         gDone, gWNEImplemented=0;
22 EventRecord     gTheEvent;
23 Rect            gDragRect, gSizeRect;
24
25 void
26 InitEvent()
27 {
28         gWNEImplemented=(NGetTrapAddress(WNE_TRAP_NUM,ToolTrap)!=
29                 NGetTrapAddress(UNIMPL_TRAP_NUM,ToolTrap));
30         }
31
32
33 #define hiword(x)               (((short *) &(x))[0])
34 #define loword(x)               (((short *) &(x))[1])
35 static MenuHandle aMenu;
36
37 /*
38 ChkEvent()
39 {}
40 */
41
42 #ifdef TPLOT
43 extern WindowPtr gDrawWindow;
44 extern PicHandle aPic;
45 #endif
46
47 static long checkTime=0;
48
49 void
50 ChkEvent()
51 {
52         EventRecord event;
53         WindowPeek wp;
54         Boolean gotEvent, SIOUXDidEvent;
55         long choice;
56         Str255 buf;
57         
58         if (TickCount() < checkTime) return;
59         checkTime = TickCount()+60L;
60
61         if (gWNEImplemented)
62                 gotEvent=WaitNextEvent(everyEvent-diskMask,&event,SLEEP,NIL_MOUSE_REGION);
63         else {
64                 SystemTask();
65                 gotEvent=GetNextEvent(everyEvent-diskMask,&event);
66                 }
67
68         if (gotEvent) SIOUXDidEvent=SIOUXHandleOneEvent(&event);
69         if (SIOUXDidEvent) return;
70
71         if (event.what == nullEvent) {
72                 if (FrontWindow() == 0) InitCursor();
73                 return;
74                 }
75         
76         if (SystemEvent(&event)) return;
77
78         if (event.what == mouseDown) {
79                 switch (FindWindow(event.where, (WindowPtr *)&wp)) {
80                         case inMenuBar:
81                                 InitCursor();
82                                 choice = MenuSelect(event.where);
83                                 goto doMenu;
84                         case inDrag :
85                                 DragWindow((WindowPtr)wp, event.where, &gDragRect);
86                                 break;
87                         case inSysWindow:
88                                 SystemClick(&event, (WindowPtr)wp);
89                                 break;
90                         }
91                 }
92         
93         return;
94
95 doMenu: 
96         switch (hiword(choice)) {
97                 case 1:
98                         GetMenuItemText(aMenu, loword(choice), buf);
99                         OpenDeskAcc(buf);
100                         break;
101                 case 2:
102                         exit(0);
103                 
104                 case 3: 
105                         SystemEdit(loword(choice) - 1);
106                         break;
107         }
108         HiliteMenu(0);
109 }
110
111 #ifdef TPLOT
112
113 Waitkey(keyval)
114         int keyval;
115 {
116         int key;
117         EventRecord event;
118         WindowPeek wp;
119         long choice;
120         Str255 buf;
121         
122         SystemTask();
123         if (gWNEImplemented)
124                 WaitNextEvent(everyEvent-diskMask,&event,SLEEP,NIL_MOUSE_REGION);
125         else {
126                 SystemTask();
127                 GetNextEvent(everyEvent-diskMask,&event);
128                 }
129
130                         
131         InitCursor();
132         if (event.what == nullEvent) {
133                 return 0;
134                 }
135         
136         if (SystemEvent(&event)) return 0;
137
138         if (event.what == updateEvt) {
139                 if ((WindowPtr)event.message == gDrawWindow) {
140                         BeginUpdate((WindowPtr)event.message);
141                         DrawPicture(aPic,&gDrawWindow->portRect);
142                         EndUpdate((WindowPtr)event.message);
143                         }
144                 else {
145                         BeginUpdate((WindowPtr)event.message);
146                         EndUpdate((WindowPtr)event.message);
147                         }
148                 return 0;
149                 }
150
151         if (event.what == keyDown) return 1;
152         if (event.what == mouseDown) {
153                 switch (FindWindow(event.where, (WindowPtr *)&wp)) {
154                         case inMenuBar:
155                                 InitCursor();
156                                 choice = MenuSelect(event.where);
157                                 goto doMenu;
158                         case inDrag :
159                                 DragWindow((WindowPtr)wp, event.where, &gDragRect);
160                                 break;
161                         case inSysWindow:
162                                 SystemClick(&event, (WindowPtr)wp);
163                                 break;
164                         case inGoAway :
165                                 return 1;
166                         case inContent:
167                                 SelectWindow((WindowPtr)wp);
168                                 SetPort(gDrawWindow);
169                                 DrawPicture(aPic,&gDrawWindow->portRect);
170                                 break;
171                         }
172                 }
173         
174         return 0;
175
176 doMenu: 
177         switch (hiword(choice)) {
178                 case 1:
179                         GetItem(aMenu, loword(choice), buf);
180                         OpenDeskAcc(buf);
181                         break;
182                 case 2:
183                         return 1;
184                 
185                 case 3: 
186                         SystemEdit(loword(choice) - 1);
187                         break;
188         }
189         HiliteMenu(0);
190         return 0;
191 }
192 #endif
193
194