🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.sys.amiga.tech
Article #1358

Re: MutualExclude for Gadgets

#1358
From: Chuck McManis
Date: Wed, 20 Sep 1989 19:44
71 lines
3698 bytes
In article <1849@cbnewsd.ATT.COM> ead@cbnewsd.ATT.COM (eric.a.duesing) writes:
>1)  Could someone PLEASE send me a declaration of 2 or more gadgets
>    that are Mutually Exclusive?  I tried it, and it doesn't seem to
>    work. (Read: What am I doing wrong?)

These don't "work" either, never did. They have been documented as such
in a couple of places. There are several examples on how one can do
mutual exclusion of gadgets. My personal favorite is to group excluded
gadgets by putting a pointer to a structure in the UserData field, and
then using it to point the the gadgets that need to be excluded.

For example, say I had a structure like this :

struct Gadget	*foo_Current;	/* "global" that holds the current gadget */

struct ExcludeList {
	unsigned long	ListType;	/* Magic number ('M'+'X'+'G'+'D') */
	struct Gadget	*MX_Gad,	/* This gadget */
			**MX_Current;	/* The one currently selected */
	void		*MX_Data;	/* Further extension possible */
};

A copy of this structure is malloc'd and a pointer to it is stuck in the
userdata field. 

All excluded gadgets in a set will point to a single "current" gadget
that is in MX_Current. Let's say it was pointing at &foo_Current. So in 
the code itself whenever I get a gadget message I process it with :

/*
 * One of many defines that identify the kinds of custom structure I hang
 * off of gadgets, if UserData is NULL is looks at location 0 but that is
 * always 0 (:-)) so that is ok too. Of course third party hacks that 
 * diddle with my gadgets will crash the system...
 */
#define GADGET_MAGIC(g) (*((unsigned long *)((struct Gadget *)(g)->UserData)))

	case GADGETUP : 
		if (GADGET_MAGIC(msg->IAddress) == MX_GAD) {
			e = (struct ExcludeList *)
				((struct Gadget *)(msg->IAddress))->UserData;
			DeSelect(*(e->MX_Current));
			Select(e->MX_Gad);
			*(e->MX_Current) = e->MX_Gad;
		}
		...

And when ever I want to know which of the possible choices are made I
can look at foo_Current. 

>2)  Is there somewhere I missed that says that all of the gadgets of
>    one type must be grouped in a gadget list?   I had a gadget list
>    with several bool gadgets and some string gadgets.  But, they 
>    didn't all work until I grouped them. (Bool gadgets first, String
>    gadgets next.)

No this is not a requirement, but all of the NextGadget pointers had
better point to a valid gadget because otherwise the pointer stops
there. Gadgets for a window all reside on a single linked list whose
head is Window->FirstGadget and the next pointers are Gadget->NextGadget
the only way to add or remove gadgets from this list are with the
routines AddGadget()/RemoveGadget() and AddGList/RemGList. The list
functions expect the pointers to all be correct. If you are setting
up your gadgets by pointing NewWindow->FirstGadget at them then
they still have to have the link list initialized properly.


--Chuck McManis
uucp: {anywhere}!sun!cmcmanis   BIX: cmcmanis  ARPAnet: cmcmanis@sun.com
These opinions are my own and no one elses, but you knew that didn't you.
"If I were driving a Macintosh, I'd have to stop before I could turn the wheel."
Technical Details
Message-ID: <125013@sun.Eng.Sun.COM>
Path: arc1-ca.pugleaf.net!utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!cs.utexas.edu!sun-barr!newstop!sun!pepper!cmcmanis
References: <1849@cbnewsd.ATT.COM>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!cs.utexas.edu!sun-barr!newstop!sun!pepper!cmcmanis
From: cmcmanis%pepper@Sun.COM (Chuck McManis)
Newsgroups: comp.sys.amiga.tech
Subject: Re: MutualExclude for Gadgets
Keywords: Amiga MutualExclude
Message-ID: <125013@sun.Eng.Sun.COM>
Date: 20 Sep 89 19:44:12 GMT
References: <1849@cbnewsd.ATT.COM>
Sender: news@sun.Eng.Sun.COM
Reply-To: cmcmanis@sun.UUCP (Chuck McManis)
Distribution: usa
Organization: Sun Microsystems, Mountain View
Lines: 71