[comp.sys.amiga] Gadget ID codes?

mp1u+@andrew.cmu.edu (Michael Portuesi) (10/18/87)

I want to present a requester in the current window with a string
gadget for user input and two boolean gadgets for "OK" and "Cancel."
If the user selects "Cancel", obviously I don't want to do anything.
What is the correct way to determine what gadget the user activated
to end the requester?  I set the GadgetID field of each of my gadget
definitions to a unique value.  I throw the requester up on the
screen, wait for an IDCMP message, extract the code from the message
structure, then reply to it.  My assumption is that the message code
would contain the ID of the selected gadget that caused the requester
to end, although the Intuition manual doesn't really tell you what it
should contain.  Is my assumption correct?

		    --M

Michael Portuesi / Carnegie-Mellon University
ARPA/UUCP: mp1u+@andrew.cmu.edu
BITNET: rainwalker@drycas (a uVax-1 run by CMU Computer Club)

"Boys living next door are never what they seem"
		--Bananarama, "Robert DeNiro's Waiting"

cmcmanis%pepper@Sun.COM (Chuck McManis) (10/19/87)

In article <IVS3u9y00WAENjc04b@andrew.cmu.edu> (Michael Portuesi) writes:
>I want to present a requester in the current window with a string
>gadget for user input and two boolean gadgets for "OK" and "Cancel."
>If the user selects "Cancel", obviously I don't want to do anything.
>What is the correct way to determine what gadget the user activated
>to end the requester?  I set the GadgetID field of each of my gadget
>definitions to a unique value.  I throw the requester up on the
>screen, wait for an IDCMP message, extract the code from the message
>structure, then reply to it.  My assumption is that the message code
>would contain the ID of the selected gadget that caused the requester
>to end, although the Intuition manual doesn't really tell you what it
>should contain.  Is my assumption correct?

Yes, it is correct. When you put up a requester, assuming it does not
have the NOISY flag set, then all of the IDCMP events you will receive
come from that requester. If you have gadgets in the requester your 
loop looks something like :
(Note, this is from memory so some structure fields may be wrong)

done = FALSE;
do {
	Wait(mywindow->UserPort->mpSigBit);
	im = (struct IntuiMessage *)GetMsg(mywindow->UserPort);
	if (im == NULL) continue;
	class = im->Class;
	address = im->Iadress;
	x = im->MouseX;
	y = im->MouseY;
	ReplyMsg(im);
	switch (classe) {
		case GADGETUP :
		case GADGETDOWN :
			g = (struct Gadget *)address;
			done = ((g->GadgetFlags & ENDGADGET) != 0);
			id = g->GadgetID;
			switch (id) {
				case CANCELID : /* cancel here */;
				case OKID : /* process data here */;
				etc;
			}
			break; 
		default : break;
	}
} while (! done);

Which will loop around until a gadget with the ENDGADGET flag is clicked
upon. In the meantime clicking on other gadgets will be processed by this
loop. Note that if you have NOISYREQ set you can also watch for VANILLAKEY
events and let the user press 'O' or 'C' to mean OK or CANCEL on the 
requester. Anyway, when the message is received, if it is a gadget message
then the iaddress field contains a pointer to the gadget struct that was
clicked upon. You can proabably take it from their. 


--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.

higgin@cbmvax.UUCP (Paul Higginbottom SALES) (10/20/87)

in article <31230@sun.uucp>, cmcmanis%pepper@Sun.COM (Chuck McManis) says:
> If you have gadgets in the requester your > loop looks something like :
>
> done = FALSE;
> do {
> 	Wait(mywindow->UserPort->mpSigBit);
> 	im = (struct IntuiMessage *)GetMsg(mywindow->UserPort);
> 	if (im == NULL) continue;
> 	class = im->Class;
> 	address = im->Iadress;
> 	x = im->MouseX;
> 	y = im->MouseY;
> 	ReplyMsg(im);
> 	switch (classe) {
		.
		.
> 	}
> } while (! done);

I don't think loops like this should not assume one signal per message.
You may get out of sync this way and not get/reply all the message.
A 'better' way is:

done = FALSE;
do {
	Wait(mywindow->UserPort->mp_SigBit);
	while ((im=(struct IntuiMessage *)GetMsg(mywindow->UserPort))!=NULL)
	{
		class = im->Class;
		address = im->Iadress;
		x = im->MouseX;
		y = im->MouseY;
		ReplyMsg(im);
		switch (class) {
			.
			.
		}
	}
} while (!done);

Not trying to split hairs Chuck... well, maybe I am. :-)

	Paul.

peter@sugar.UUCP (Peter da Silva) (10/22/87)

How to get the GadgetID...

	case GADGETUP:
		ProcessGadget(
			((struct Gadget *)msg->IAddress)->GadgetID
		);
		break;

This is obviously a bit brute-force, but I guess (I can't recall) that I
couldn't find the info in the manuals either. Psi.
-- 
-- Peter da Silva  `-_-'  ...!hoptoad!academ!uhnix1!sugar!peter
-- Disclaimer: These U aren't mere opinions... these are *values*.

brianr@tekig4.TEK.COM (Brian Rhodefer) (10/24/87)

Realizing that the horse may be dead already,
I'd like to point out that the GadgetID field
of Gadget structures is only meaningful if one
has initialized it oneself;  Intuition doesn't
do anything with it.

Timidly,

Brian Rhodefer