Article View: comp.sys.amiga.tech
Article #7907Re: "chip" in SAS C
From: Ron Tarrant
Date: Sun, 06 Jan 1991 16:30
Date: Sun, 06 Jan 1991 16:30
116 lines
4739 bytes
4739 bytes
> mmaston@portia.Stanford.EDU writes:
>
> Speaking of 'C', anyone have a nice example of how to perform mutual
> exclusion
> on BOOLEAN gadgets? I have been wrestling with it, but for some reason it
> hasn't come out quite right!
>
> Pls excuse my ignorance in this matter!
>
> Danke!
>
> Michael Maston
> GTE Government Systems
> Mt. View, CA 94043
Mutual exclusion of gadgets was not implemented in 1.3 (and I don't know if
it's available with 2.0 either; maybe someone else can answer that). So the
example in the RKM can be ignored.
There is a way to cheat it though, without breaking any rules. There is
an example by Peter Chema in AmigaMail (Sept/Oct '89). I've taken the liberty
of including the function that does the actual work in this message (I hope I'm
not breaking any copyright laws by doing so). :-)
I've added some comments to (hopefully) make it clear enough if you don't have
access to the article.
#include <exec/types.h>
#include <intuition/intuition.h>
#include <libraries/dos.h>
#include <libraries/dosextens.h> /* For the process structure definition. */
#include <exec/libraries.h>
/* make sure each gadget in your */
/* mutual exclude list has this */
/* value in UserData */
/* | */
/* V */
#define MX_MAGIC (APTR) 0x73EAB019
USHORT handleMXGads(struct IntuiMessage *message);
struct Gadget *ActiveGad; /* keep track of currently-selected gadget */
USHORT handleMXGads(message)
struct IntuiMessage *message;
{
struct Gadget *gad;
USHORT pos;
USHORT format;
extern struct StringInfo InFile_stringinfo;
/* first, we double check to make sure we're dealing with a mutual */
/* exclude gadget. */
if(message->Class == GADGETDOWN)
{
gad = (struct Gadget *) message->IAddress;
if(gad->UserData == MX_MAGIC)
{
/* now, we check to see if the user selected the MX gad
that's */
/* already active */
if(gad != ActiveGad)
{
pos = RemoveGList(message->IDCMPWindow, gad,
1L); /* remove the gadget from the list */
gad->Flags |= SELECTED; /* change to the
SELECTED flag */
AddGList(message->IDCMPWindow, gad, (LONG) pos,
1L, NULL); /* put the gadget back into the list */
RefreshGList(gad,
message->IDCMPWindow,NULL,1L); /* the gadget will appear to have changed it's
'selected' state */
pos =
RemoveGList(message->IDCMPWindow,ActiveGad,1L); /* do the same to the currently
active gadget */
ActiveGad->Flags &= ~SELECTED;
AddGList(message->IDCMPWindow,ActiveGad
,(LONG)pos,1L,NULL);
RefreshGList(ActiveGad,message->IDCMPWi
ndow,NULL,1L);
ActiveGad = gad; /* update this flag to reflect
the newly selected gadget */
}
else
{
pos = RemoveGList(message->IDCMPWindow,gad,1L);
if(!(gad->Flags & SELECTED))
;
AddGList(message->IDCMPWindow,gad,(LONG
)pos,1L,NULL);
RefreshGList(gad,message->IDCMPWindow,N
ULL,1L);
}
}
format = (USHORT) ActiveGad->GadgetID;
return(format); /* we're returning a flag that tells us what
output format has been selected */
}
}
Once you get your IntuiMessage and have determined that Class = GADGETDOWN,
pass the message to this function. The "format" variable will return the
GadgetID from the currently active gadget (after finding out which gadget in
your mutual exclude list was clicked on and
making it the active gadget). You can use this value for any decision-
making outside the function.
-Ron Tarrant
a976@Mindlink.UUCP
p.s. - Sorry about the formatting. If you have any more questions about this,
let me know by e-mail or here in this message group.
Technical Details
Message-ID:
<4346@mindlink.UUCP>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!van-bc!rsoft!mindlink!a976Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!van-bc!rsoft!mindlink!a976 From: a976@mindlink.UUCP (Ron Tarrant) Newsgroups: comp.sys.amiga.tech Subject: Re: "chip" in SAS C Message-ID: <4346@mindlink.UUCP> Date: 6 Jan 91 16:30:39 GMT Organization: MIND LINK! - British Columbia, Canada Lines: 116