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.
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.
22 #include "exec/types.h"
24 #include "exec/memory.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"
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
= {
52 struct IntuiText IText1
= {
60 struct Gadget Gadg5
= {
76 SHORT BorderVectors2
[] = {0,0,48,0,48,14,0,14,0,0};
77 struct Border Border2
= {
85 struct IntuiText IText2
= {
93 struct Gadget Gadg4
= {
109 SHORT BorderVectors3
[] = {0,0,48,0,48,14,0,14,0,0};
110 struct Border Border3
= {
118 struct IntuiText IText3
= {
126 struct Gadget Gadg3
= {
142 SHORT BorderVectors4
[] = {0,0,48,0,48,14,0,14,0,0};
143 struct Border Border4
= {
151 struct IntuiText IText4
= {
159 struct Gadget Gadg1
= {
175 SHORT BorderVectors5
[] = {0,0,48,0,48,14,0,14,0,0};
176 struct Border Border5
= {
184 struct IntuiText IText5
= {
192 struct Gadget Gadg2
= {
208 struct NewWindow NewWindowStructure
= {
212 GADGETDOWN
+GADGETUP
+CLOSEWINDOW
,
213 WINDOWDRAG
+WINDOWCLOSE
+ACTIVATE
,
216 (UBYTE
*)"Mutual Exclude Test",
224 /* end of PowerWindows source generation */
232 struct IntuitionBase
*IntuitionBase
= 0L;
234 struct Window
*twindow
;
235 void GadMXSel(), GadMXSD();
239 IntuitionBase
= (struct IntuitionBase
*)
240 OpenLibrary("intuition.library", 0L);
241 if (IntuitionBase
== NULL
) {
242 printf("Failed to open intuition\n");
246 Test(); /* Do the work: put up a "requester" */
248 if (IntuitionBase
!= NULL
) CloseLibrary((struct Library
*)IntuitionBase
);
254 * Routine to put up the "Requester" and handle IDCMP messages.
261 static struct IntuiMessage
*message
;
262 static struct Gadget
*gad
;
265 twindow
= OpenWindow(&NewWindowStructure
); /* open the "Requester" */
266 if ( twindow
== NULL
) {
267 printf ("open window failed\n");
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
) {
290 GadMXSel(twindow
,&Gadg1
,&Gadg2
,&Gadg3
,&Gadg4
,NULL
,NULL
);
294 GadMXSel(twindow
,&Gadg2
,&Gadg1
,&Gadg3
,&Gadg4
,NULL
,NULL
);
298 GadMXSel(twindow
,&Gadg3
,&Gadg1
,&Gadg2
,&Gadg4
,NULL
,NULL
);
302 GadMXSel(twindow
,&Gadg4
,&Gadg1
,&Gadg2
,&Gadg3
,NULL
,NULL
);
308 CloseWindow(twindow
);
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
)
322 struct Gadget
*gad1
,*gad2
,*gad3
,*gad4
,*gad5
,*gad6
;
324 static struct Gadget
*gadprev
;
328 if (gad1
->Flags
& SELECTED
) return;
330 if (gad2
->Flags
& SELECTED
) gadprev
= gad2
;
332 if (gad3
->Flags
& SELECTED
) gadprev
= gad3
;
334 if (gad4
->Flags
& SELECTED
) gadprev
= gad4
;
336 if (gad5
->Flags
& SELECTED
) gadprev
= gad5
;
338 if (gad6
->Flags
& SELECTED
) gadprev
= gad6
;
340 GadMXSD(win
,gad1
,gadprev
);
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
356 void GadMXSD(win
,gad1
,gad2
)
358 struct Gadget
*gad1
,*gad2
;
361 * First select gad2 (yes!) and refresh.
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.
374 RemoveGadget(win
,gad1
);
375 gad1
->Flags
|= SELECTED
;
376 AddGadget(win
,gad1
,-1L);
380 RemoveGadget(win
,gad2
);
381 gad2
->Flags
&= ~SELECTED
;
382 AddGadget(win
,gad2
,-1L);
385 if (gad1
!= NULL
) RefreshGadgets(gad1
,win
,NULL
);