[comp.sys.amiga.programmer] Gadget "BUG"

specter@disk.uucp (Byron Max Guernsey) (06/05/91)

I'm having a small problem with the gadget interface in a program I have 
written. At times the gadgets seem to get offset:: when I click on one
gadget another gadget's operation is performed. I think it happens after
quickly clicking twice on one gadget. It extends to the system gadgets in
my window as well...the close gadget gets offset to where I click on it and
nothing happens, then I go down and click on a gadget in my window and it
closes the window. :)

I know this in itself isn't a BUG, but it is a bug locally until I find out
what I am doing wrong. Maybe it has something to do with GADGIMMEDIATE flag?
I use it and RELVERIFY both.

I'm sure someone else has had this problem???

Byron
-- 
Byron 'Maxwell' Guernsey                       |       ///  //\\
specter@disk.UUCP     or                       |      ///  //  \\
uunet!ukma!corpane!disk!specter                |  \\\///  //====\\
"Great programs aren't written, they're fathered." \\\/  //      \\ m i g a

ken@cbmvax.commodore.com (Ken Farinsky - CATS) (06/05/91)

In article <1991Jun05.081036.20165@disk.uucp> specter@disk.uucp (Byron Max Guernsey) writes:
>I'm having a small problem with the gadget interface in a program I have 
>written. At times the gadgets seem to get offset:: when I click on one
>gadget another gadget's operation is performed. I think it happens after
>quickly clicking twice on one gadget. It extends to the system gadgets in
>my window as well...the close gadget gets offset to where I click on it and
>nothing happens, then I go down and click on a gadget in my window and it
>closes the window. :)

If I had to guess, I would say that your event loop is wrong.  When Wait()
returns, you have to get all of the messages off of the port.  Are you
doing something like:

	while (!done)    /* example of how NOT to process messages */
		{
		Wait(...);

		/* Check for a message, process if available.
		** Take only the first message and return.
		*/
		if (NULL != (msg = GetMsg(...)))
			{
			done = processMessage(msg);
			ReplyMsg(msg);
			}
		}

This will clear the signal from the port, but only get one message at
a time.  If there are two messages waiting, one will stay on the port
but the Wait() will not return until the next message arrives and sets
the signal.  This would give the behavior that you indicated (the window
not closing until you hit the next gadget.)  Try something like:

	while (!done)    /* example of how to process messages */
		{
		Wait(...);

		/* Get all messages until done or all of the messages
		** have been removed from the port.
		*/
		while ((!done) && (NULL != (msg = GetMsg(...))))
			{
			done = processMessage(msg);
			ReplyMsg(msg);
			}
		}

-- 
--
Ken Farinsky - CATS - (215) 431-9421 - Commodore Business Machines
uucp: ken@cbmvax.commodore.com   or  ...{uunet,rutgers}!cbmvax!ken
bix:  kfarinsky

phorgan@cup.portal.com (Patrick John Horgan) (06/06/91)

Byron 'Maxwell' Guernsey said:
> I'm having a small problem with the gadget interface in a program I have 
> written. At times the gadgets seem to get offset:: when I click on one
> gadget another gadget's operation is performed. I think it happens after
> quickly clicking twice on one gadget. It extends to the system gadgets in
> my window as well...the close gadget gets offset to where I click on it and
> nothing happens, then I go down and click on a gadget in my window and it
> closes the window. :)
> 
Byron, when you receive an event from Intuition, you have to handle all the
events at your port.  If you get another while or before handling the first,
you won't get another signal.  This means that you'll have an event on your
queue, but won't react until another event happens.  Suddenly you're out
of sync, reacting to a different event than caused a signal!  Just loop
after handling an IntuiMessage back up to the GetMsg till no more are there.
Then you can wait on the port again.

Patrick J. Horgan                        pjh70@zeus.ras.amdahl.com

fjrei@kbsaar.UUCP (Franz-Josef Reichert) (06/06/91)

In article <1991Jun05.081036.20165@disk.uucp> specter@disk.uucp (Byron Max Guernsey) writes:
>I'm having a small problem with the gadget interface in a program I have 
>written. At times the gadgets seem to get offset:: when I click on one
>gadget another gadget's operation is performed. I think it happens after
>quickly clicking twice on one gadget. It extends to the system gadgets in
>my window as well...the close gadget gets offset to where I click on it and
>nothing happens, then I go down and click on a gadget in my window and it
>closes the window. :)

Obviously, you are not handling intuition messages properly. Make sure
that your task has processed _all_ messages before going to sleep:

	while(1) {
		Wait(1L << mp->mp_SigBit);
		/* note this loop! */
		while(msg = GetMsg(mp)) {
			/* copy relevant fields, e.g. */
			class = msg->Class;
			code = msg->Code;
			/* ... */
			/* here and now! */
			ReplyMsg(msg);
			switch(class) {
				case GADGETUP:
					/* etc. */
			}
		}
	}

Otherwise, remaining messages may not be processed until a new one arrives.
This will cause the "offset" you encountered.

>Byron

--
Best regards,
Franz-Josef Reichert      VOICE: +49 6805 7417
Kuchlingerstrasse 13      UUCP:  ...uunet!cbmvax!cbmehq!cbmger!kbsaar!fjrei
D-6601 Kleinblittersdorf  GERMANY