SysMon: remove dead code
[AROS.git] / workbench / demos / mxgads.c
blob674f374da868080c4e0889d4de360e44049e1cbc
1 /** testmxgads.c
3 * This program gives a demonstration of how to make mutual exclusion
4 * of boolean gadgets work even if they contain GadgetText.
5 * The method is still somewhat of a cludge, but then, it will last
6 * until 1.3 comes out... Hope this proves of some use.
7 *
8 * Willy.
10 * The usual disclaimer:
12 * Copyright 1986, W.G.J. Langeveld
14 * Permission is granted for unlimited commercial and/or noncommercial
15 * use. This program may not be uploaded to any commercial BBS
16 * except Byte Information Exchange. The author accepts no responsibi-
17 * lity for this program whatsoever.
19 **/
22 #include "exec/types.h"
23 #include "exec/io.h"
24 #include "exec/memory.h"
25 #include "dos/dos.h"
26 #include "intuition/intuition.h"
28 //#include "functions.h"
29 #include "intuition/iobsolete.h"
30 #include "proto/exec.h"
31 #include "proto/intuition.h"
33 #include <stdio.h>
34 #include <stdlib.h>
36 #define SHORT WORD
37 void Test(void);
41 /* The following source fragment was generated by PowerWindows */
43 WORD BorderVectors1[] = {0,0,48,0,48,14,0,14,0,0};
44 struct Border Border1 = {
45 -2,-1,
46 3,0,JAM1,
48 BorderVectors1,
49 NULL
52 struct IntuiText IText1 = {
53 1,0,JAM2,
54 6,3,
55 NULL,
56 (UBYTE *)"Quit",
57 NULL
60 struct Gadget Gadg5 = {
61 NULL,
62 89,51,
63 45,13,
64 GADGHCOMP,
65 RELVERIFY,
66 BOOLGADGET,
67 (APTR)&Border1,
68 NULL,
69 &IText1,
71 NULL,
73 NULL
76 SHORT BorderVectors2[] = {0,0,48,0,48,14,0,14,0,0};
77 struct Border Border2 = {
78 -2,-1,
79 3,0,JAM1,
81 BorderVectors2,
82 NULL
85 struct IntuiText IText2 = {
86 3,0,INVERSVID,
87 7,3,
88 NULL,
89 (UBYTE *)"Four",
90 NULL
93 struct Gadget Gadg4 = {
94 &Gadg5,
95 166,18,
96 45,13,
97 GADGHCOMP,
98 GADGIMMEDIATE,
99 BOOLGADGET,
100 (APTR)&Border2,
101 NULL,
102 &IText2,
104 NULL,
106 NULL
109 SHORT BorderVectors3[] = {0,0,48,0,48,14,0,14,0,0};
110 struct Border Border3 = {
111 -2,-1,
112 3,0,JAM1,
114 BorderVectors3,
115 NULL
118 struct IntuiText IText3 = {
119 2,0,INVERSVID,
120 2,3,
121 NULL,
122 (UBYTE *)"Three",
123 NULL
126 struct Gadget Gadg3 = {
127 &Gadg4,
128 114,18,
129 45,13,
130 GADGHCOMP,
131 GADGIMMEDIATE,
132 BOOLGADGET,
133 (APTR)&Border3,
134 NULL,
135 &IText3,
137 NULL,
139 NULL
142 SHORT BorderVectors4[] = {0,0,48,0,48,14,0,14,0,0};
143 struct Border Border4 = {
144 -2,-1,
145 3,0,JAM1,
147 BorderVectors4,
148 NULL
151 struct IntuiText IText4 = {
152 1,0,JAM1,
153 9,3,
154 NULL,
155 (UBYTE *)"One",
156 NULL
159 struct Gadget Gadg1 = {
160 &Gadg3,
161 10,18,
162 45,13,
163 GADGHCOMP+SELECTED,
164 GADGIMMEDIATE,
165 BOOLGADGET,
166 (APTR)&Border4,
167 NULL,
168 &IText4,
170 NULL,
172 NULL
175 SHORT BorderVectors5[] = {0,0,48,0,48,14,0,14,0,0};
176 struct Border Border5 = {
177 -2,-1,
178 3,0,JAM1,
180 BorderVectors5,
181 NULL
184 struct IntuiText IText5 = {
185 3,0,JAM2,
186 8,3,
187 NULL,
188 (UBYTE *)"Two",
189 NULL
192 struct Gadget Gadg2 = {
193 &Gadg1,
194 62,18,
195 45,13,
196 GADGHCOMP,
197 GADGIMMEDIATE,
198 BOOLGADGET,
199 (APTR)&Border5,
200 NULL,
201 &IText5,
203 NULL,
205 NULL
208 struct NewWindow NewWindowStructure = {
209 351,39,
210 220,70,
211 0,1,
212 GADGETDOWN+GADGETUP+CLOSEWINDOW,
213 WINDOWDRAG+WINDOWCLOSE+ACTIVATE,
214 &Gadg2,
215 NULL,
216 (UBYTE *)"Mutual Exclude Test",
217 NULL,
218 NULL,
219 5,5,
220 640,200,
221 WBENCHSCREEN
224 /* end of PowerWindows source generation */
226 #define GAD1 4
227 #define GAD2 3
228 #define GAD3 5
229 #define GAD4 6
230 #define GAD5 7
232 struct IntuitionBase *IntuitionBase = 0L;
234 struct Window *twindow;
235 void GadMXSel(), GadMXSD();
237 int main(void)
239 IntuitionBase = (struct IntuitionBase *)
240 OpenLibrary("intuition.library", 0L);
241 if (IntuitionBase == NULL) {
242 printf("Failed to open intuition\n");
243 exit(0);
246 Test(); /* Do the work: put up a "requester" */
248 if (IntuitionBase != NULL) CloseLibrary((struct Library *)IntuitionBase);
249 return(0);
254 * Routine to put up the "Requester" and handle IDCMP messages.
257 void Test(void)
259 static ULONG class;
261 static struct IntuiMessage *message;
262 static struct Gadget *gad;
263 static int looping;
265 twindow = OpenWindow(&NewWindowStructure); /* open the "Requester" */
266 if ( twindow == NULL ) {
267 printf ("open window failed\n");
268 return;
271 looping = TRUE;
272 while (looping) {
273 WaitPort(twindow->UserPort);
274 while((message = (struct IntuiMessage *)
275 GetMsg(twindow->UserPort)) != NULL) {
276 class = message->Class;
277 gad = (struct Gadget *)message->IAddress;
278 ReplyMsg((struct Message *)message);
280 if (class == CLOSEWINDOW) looping = FALSE;
282 if ((class == GADGETUP) || (class == GADGETDOWN)) {
283 switch (gad->GadgetID) {
284 case GAD5 :
285 printf("QUIT\n");
286 looping = FALSE;
287 break;
288 case GAD1 :
289 printf("ONE\n");
290 GadMXSel(twindow,&Gadg1,&Gadg2,&Gadg3,&Gadg4,NULL,NULL);
291 break;
292 case GAD2 :
293 printf("TWO\n");
294 GadMXSel(twindow,&Gadg2,&Gadg1,&Gadg3,&Gadg4,NULL,NULL);
295 break;
296 case GAD3 :
297 printf("THREE\n");
298 GadMXSel(twindow,&Gadg3,&Gadg1,&Gadg2,&Gadg4,NULL,NULL);
299 break;
300 case GAD4 :
301 printf("FOUR\n");
302 GadMXSel(twindow,&Gadg4,&Gadg1,&Gadg2,&Gadg3,NULL,NULL);
303 break;
308 CloseWindow(twindow);
309 return;
314 * This routine selects gad1 and deselects the previously selected one.
315 * Maximum number of gadgets to be mutually excluded is six, obviously.
316 * Extension to more gadgets is obvious, too. This routine assumes that
317 * only one gadget is selected at a time.
320 void GadMXSel(win,gad1,gad2,gad3,gad4,gad5,gad6)
321 struct Window *win;
322 struct Gadget *gad1,*gad2,*gad3,*gad4,*gad5,*gad6;
324 static struct Gadget *gadprev;
326 gadprev = NULL;
327 if (gad1 != NULL)
328 if (gad1->Flags & SELECTED) return;
329 if (gad2 != NULL)
330 if (gad2->Flags & SELECTED) gadprev = gad2;
331 if (gad3 != NULL)
332 if (gad3->Flags & SELECTED) gadprev = gad3;
333 if (gad4 != NULL)
334 if (gad4->Flags & SELECTED) gadprev = gad4;
335 if (gad5 != NULL)
336 if (gad5->Flags & SELECTED) gadprev = gad5;
337 if (gad6 != NULL)
338 if (gad6->Flags & SELECTED) gadprev = gad6;
340 GadMXSD(win,gad1,gadprev);
342 return;
347 * This routine selects gad1 and deselects gad2.
348 * Notice, that this version removes gadgets from the gadget list and adds
349 * them to the end. If you're sensitive to the location of the gadgets
350 * in the gadgetlist, you have to use: gadloc = RemoveGadget... and
351 * AddGadget(...,...,(long) gadloc), where gadloc is a USHORT. Then you
352 * have to refresh all gadgets to make sure the two you changed get
353 * refreshed.
356 void GadMXSD(win,gad1,gad2)
357 struct Window *win;
358 struct Gadget *gad1,*gad2;
361 * First select gad2 (yes!) and refresh.
363 if (gad2 != NULL) {
364 RemoveGadget(win,gad2);
365 gad2->Flags |= SELECTED;
366 AddGadget(win,gad2,-1L);
369 if (gad2 != NULL) RefreshGadgets(gad2,win,NULL);
371 * Now select gad1 and deselect gad2 and refresh.
373 if (gad1 != NULL) {
374 RemoveGadget(win,gad1);
375 gad1->Flags |= SELECTED;
376 AddGadget(win,gad1,-1L);
379 if (gad2 != NULL) {
380 RemoveGadget(win,gad2);
381 gad2->Flags &= ~SELECTED;
382 AddGadget(win,gad2,-1L);
385 if (gad1 != NULL) RefreshGadgets(gad1,win,NULL);
387 return;