[comp.sys.amiga] Activating Gadgets in C

barrett@meridn.enet.dec.com (Keith Barrett) (08/02/90)

I need help with gadgets in C.  I created a database that uses string gadgets
as input.  The problem is I can't get the gadgets to auto-activate so that you
don't have to click the mouse on the string gadget to activate it.  So you
should just be able to type and when you hit return it should activate the next
gadget.  I set the SELECTED bit in the gadget but all this does is make the
cursor appear but you still have to click on the gadget.
	The only method I can think of would be feeding INTUITION false mouse
movement, but that seems a little messy.  Any help would be appreciated.



~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
		"I'm Bart Simpson - who the hell are you?"

Keith G. Barrett - Software Specialist     Internet: barrett@meridn.enet.dec.com
Digital Equipment Corp. "DEC has it now"       UUCP: decwrl!meridn.enet!barrett
  //					 "Wait'll they get a load of me" - Joker
\X/  "The Amiga is really a picoVAX"	    "You won't get it!" - the Prisoner
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

eric@cbmvax.commodore.com (Eric Cotton) (08/02/90)

In article <2384@ryn.esg.dec.com> barrett@meridn.enet.dec.com (Keith Barrett) writes:
>I need help with gadgets in C.  I created a database that uses string gadgets
>as input.  The problem is I can't get the gadgets to auto-activate so that you
>don't have to click the mouse on the string gadget to activate it.  So you
>should just be able to type and when you hit return it should activate the next
>gadget.  I set the SELECTED bit in the gadget but all this does is make the
>cursor appear but you still have to click on the gadget.
>	The only method I can think of would be feeding INTUITION false mouse
>movement, but that seems a little messy.  Any help would be appreciated.

Perhaps I am misunderstanding your predicament, but the simplest method is
the Intuition function ActivateGadget:

	Success = ActivateGadget(Gadget, Window, Request)
	D0                       A0      A1      A2

	BOOL Success;
	struct Gadget *Gadget;
	struct Window *Window;
	struct Requester *Request;

After you have processed one gadget simply ActivateGadget the next one.

-- 
Eric Cotton
Commodore-Amiga                                               (215) 431-9100
1200 Wilson Drive                        {uunet|pyramid|rutgers}!cbmvax!eric
West Chester, PA 19380            "I don't find this stuff amusing anymore."

jjszucs@cbmvax.commodore.com (John J. Szucs) (08/02/90)

In article <2384@ryn.esg.dec.com> barrett@meridn.enet.dec.com (Keith Barrett) writes:
>I need help with gadgets in C.  I created a database that uses string gadgets
>as input.  The problem is I can't get the gadgets to auto-activate so that you
>don't have to click the mouse on the string gadget to activate it.  So you
>should just be able to type and when you hit return it should activate the next
>gadget.  I set the SELECTED bit in the gadget but all this does is make the
>cursor appear but you still have to click on the gadget.
>	The only method I can think of would be feeding INTUITION false mouse
>movement, but that seems a little messy.  Any help would be appreciated.

The correct method to auto-activate a string gadget is to call the function
ActivateGadget in intuition.library, which has the following syntax:

ActivateGadget(struct Gadget *Gadget,struct Window *Window,struct Requester
	*Requester);

If the gadget is not in a requester, the Requester argument should be NULL.

So, for example, to activate the gadget FirstGadget, which is in the
window DataEntryWindow and is not in a requester, the call would be:

ActivateGadget(FirstGadget,DataEntryWindow,NULL);

For more information on this call, check the ROM Kernel Manuals or the
AutoDocs (printed in the "Includes and Autodocs" volume of the RKM or
available on disk (very convenient if you have a hard disk) from CATS).

A good idea for a database program would be to automatically activate
the next string gadget when you receive a GADGETUP message from another
string gadget. This allows the user to press <Return> and automatically
move to the next field. So, if you have a name and address database, the
flow (given below with field names on the left and user input on the right)
might be:

Name:		John Q. Public<Return>
		(cursor automatically moves to Address field)
Address:	123 Main Street<Return>
		(cursor automatically moves to City field)
City:		West Chester<Return>
		(cursor automatically moves to State field)
State:		PA<Enter>
		(cursor automatically moves to ZIP field)
ZIP:		19380<Enter>
		(cursor automatically moves to Telephone field)
Telephone:	(215)-431-1234<Enter>

>Keith G. Barrett - Software Specialist     Internet: barrett@meridn.enet.dec.com
>Digital Equipment Corp. "DEC has it now"       UUCP: decwrl!meridn.enet!barrett

================================================================================
|| John J. Szucs                    || The opinions expressed are my own and  ||
|| Systems Evaluation Group         || in no way represent the opinions or    ||
|| Product Assurance Department     || policies of Commodore Technology, Inc. ||
|| Commodore Technology, Inc.       || or any associated entity.              ||
================================================================================
...{rutgers|uunet|pyramid}!cbmvax!jjszucs
jjszucs@cbmvax.commodore.com

"Everything is deeply intertwingled." - Ted Nelson, Computer Lib/Dream Machines

peter@cbmvax.commodore.com (Peter Cherna) (08/02/90)

In article <2384@ryn.esg.dec.com> barrett@meridn.enet.dec.com (Keith Barrett) writes:
>I need help with gadgets in C.  I created a database that uses string gadgets
>as input.  The problem is I can't get the gadgets to auto-activate so that you
>don't have to click the mouse on the string gadget to activate it.

Two of my colleagues already mentioned the ActivateGadget() function that
was added to Intuition in 1.2.  If you do any significant work with gadgets
you should buy a copy of the 1.3 Libraries and Devices volume of the
ROM Kernal Manual, and get the 1.3 Includes and Autodocs book or order
the disk-version from CATS.  There are a number of gadget functions
added in 1.2 that are not documented in the 1.1 RKMs.  The 1.1 volumes
are white with a colored stripe.  The 1.3 editions are blue.

As well, if you intend to activate the first gadget when your window opens,
you should know that you should wait for the ACTIVEWINDOW IntuiMessage
before activating your gadget.  This is because a lot of Intuition work
happens asynchronously to your task, so when you call

	OpenWindow(...);
	ActivateGadget(...);

the window may not yet be open or active when ActivateGadget() is called.

So add ACTIVEWINDOW to your NewWindow.IDCMPFlags and rock on.

>Keith G. Barrett - Software Specialist     Internet: barrett@meridn.enet.dec.com

     Peter
--
     Peter Cherna, Software Engineer, Commodore-Amiga, Inc.
     {uunet|rutgers}!cbmvax!peter    peter@cbmvax.cbm.commodore.com
My opinions do not necessarily represent the opinions of my employer.
"This is a one line proof...if we start sufficiently far to the left."

kevin@modcomp.UUCP (Kevin Smith) (08/03/90)

peter@cbmvax.commodore.com (Peter Cherna) writes:

>In article <2384@ryn.esg.dec.com> barrett@meridn.enet.dec.com (Keith Barrett) writes:
>>I need help with gadgets in C.  I created a database that uses string gadgets
>>as input.  The problem is I can't get the gadgets to auto-activate so that you
>>don't have to click the mouse on the string gadget to activate it.

>Two of my colleagues already mentioned the ActivateGadget() function that
>was added to Intuition in 1.2.  If you do any significant work with gadgets
>you should buy a copy of the 1.3 Libraries and Devices volume of the
>ROM Kernal Manual, and get the 1.3 Includes and Autodocs book or order
>the disk-version from CATS.  There are a number of gadget functions
>added in 1.2 that are not documented in the 1.1 RKMs.  The 1.1 volumes
>are white with a colored stripe.  The 1.3 editions are blue.

>As well, if you intend to activate the first gadget when your window opens,
>you should know that you should wait for the ACTIVEWINDOW IntuiMessage
>before activating your gadget.  This is because a lot of Intuition work
>happens asynchronously to your task, so when you call

>	OpenWindow(...);
>	ActivateGadget(...);

>the window may not yet be open or active when ActivateGadget() is called.


I was hoping somebody someone from C= was going to give the real problem
and solution about waiting for ACTIVEWINDOW.  I have seen this question
asked and answered before and am wondering if this bit about waiting for
ACTIVEWINDOW is documented anywhere, like in the new RKM's or any other
book.

When I upgraded to 1.2 I was excited to have new gadget functions
but when I used ActivateGadget it still didn't work since I wasn't waiting
for ACTIVEWINDOW.  I must of cussed at this problem for two weeks before
somebody gave me a working solution. Actually I had this problem when
popping up a requester with gadgets in it and the string gadget would
never activate.  The solution I got and still use today is to
open up the requester then use a Delay() of a couple seconds and then 
do an ActivateGadget().


Kevin Smith   uunet!modcomp!kevin

lphillips@lpami.wimsey.bc.ca (Larry Phillips) (08/03/90)

In <325@modcomp.UUCP>, kevin@modcomp.UUCP (Kevin Smith) writes:
>
>I was hoping somebody someone from C= was going to give the real problem
>and solution about waiting for ACTIVEWINDOW.  I have seen this question
>asked and answered before and am wondering if this bit about waiting for
>ACTIVEWINDOW is documented anywhere, like in the new RKM's or any other
>book.

It's in the new RKM, as well as in the disk based autodocs available from CATS
for about $20-25 

--------------excerpt-----------------

	The success of this function depends on a rather complex set
	of conditions.  The intent is that the user is never interrupted from
	what interactions he may have underway.

	The current set of conditions includes:
	-   The Window must be active. (Use the ACTIVEWINDOW IDCMP).
	-   No other gadgets may be in use.  This includes system gadgets,
	    such as those for window sizing, dragging, etc.
	-   If the gadget is in a Requester, that Requester must
	    be active. (Use the REQSET and REQCLEAR IDCMP).
	-   The right mouse button cannot be held down (e.g. menus

-------------------------------

For anyone doing development work, I cannot recommend the disk based autodocs
highly enough.  With Mike Sinz's Getautodoc program, it becomes VERY easy to
look this sort of thing up (took me about 1/5 second with CEDPro to place the
cursor on the word 'ActivateGadget' in your posting, press ALT-L, and have the
info appear in another window), and the information is the latest stuff, which
might be different than what's in the hard copy manuals.

-larry

--
Sex is better than logic, but I can't prove it.
+-----------------------------------------------------------------------+ 
|   //   Larry Phillips                                                 |
| \X/    lphillips@lpami.wimsey.bc.ca -or- uunet!van-bc!lpami!lphillips |
|        COMPUSERVE: 76703,4322  -or-  76703.4322@compuserve.com        |
+-----------------------------------------------------------------------+

peter@cbmvax.commodore.com (Peter Cherna) (08/06/90)

In article <325@modcomp.UUCP> kevin@modcomp.UUCP (Kevin Smith) writes:
>When I upgraded to 1.2 I was excited to have new gadget functions
>but when I used ActivateGadget it still didn't work since I wasn't waiting
>for ACTIVEWINDOW.  I must of cussed at this problem for two weeks before
>somebody gave me a working solution. Actually I had this problem when
>popping up a requester with gadgets in it and the string gadget would
>never activate.  The solution I got and still use today is to
>open up the requester then use a Delay() of a couple seconds and then 
>do an ActivateGadget().

Using Delay() only mostly works.  Its success would depend on what
processor you're running and what load the CPU is under, among other
things.  Waiting for ACTIVEWINDOW is reliable, and documented in the 1.3
RKMs.

>Kevin Smith   uunet!modcomp!kevin

     Peter
--
     Peter Cherna, Software Engineer, Commodore-Amiga, Inc.
     {uunet|rutgers}!cbmvax!peter    peter@cbmvax.cbm.commodore.com
My opinions do not necessarily represent the opinions of my employer.
"This is a one line proof...if we start sufficiently far to the left."