[comp.sys.amiga.tech] software selecting string gadgets

lphillips@lpami.wimsey.bc.ca (Larry Phillips) (02/12/90)

In <575@galadriel.bt.co.uk>, stevep@galadriel.bt.co.uk (Steve Paine) writes:
>SCENARIO:
>	Five string Gadgets set up on a window.
>PROBLEM:
>	Want to be able to cycle through them one at a time, putting strings
>	in them and going on to the next one when I press return.

Use ActivateGadget() to make them active.  This was added in 1.2 or 1.3, and so
wasn't in the original RKMs.

-larry

--
Gallium Arsenide is the technology of the future;
  always has been, always will be.
+-----------------------------------------------------------------------+ 
|   //   Larry Phillips                                                 |
| \X/    lphillips@lpami.wimsey.bc.ca -or- uunet!van-bc!lpami!lphillips |
|        COMPUSERVE: 76703,4322  -or-  76703.4322@compuserve.com        |
+-----------------------------------------------------------------------+

stevep@galadriel.bt.co.uk (Steve Paine) (02/12/90)

SCENARIO:
	Five string Gadgets set up on a window.
PROBLEM:
	Want to be able to cycle through them one at a time, putting strings
	in them and going on to the next one when I press return.

	I know about the SELECTED flag and i've tried using it by
	setting it and calling RefreshGadgets(). Obviously this function
	is only a graphical refresh function because although the cursor
	appears in the string gadget, the keyboard input is still
	arriving at my UserPort and not going to the gadget. 

	How do I, by software, select a string gadget so that I can
	type in data as if I had selected it with the mouse?

	Any help would be greatly appreciated. 

	Thanks 	S.F.Paine
		British Telecom,
		Ipswich,
		ENGLAND.

P.S. Does anyone know when the ROM kernel manual (latest release, libraries) 
will be available here? I understand it has been released in the USA. Is 
this correct?

griffin@frith.egr.msu.edu (02/13/90)

In message <575@galadriel.bt.co.uk> Steve Paine writes:

>SCENARIO:
>	Five string Gadgets set up on a window.
>PROBLEM:
>	Want to be able to cycle through them one at a time, putting strings
>	in them and going on to the next one when I press return.
        [stuff deleted...]
>	How do I, by software, select a string gadget so that I can
>	type in data as if I had selected it with the mouse?

Add this code to your event processing function...

ULONG class;
APTR address;
struct IntuiMessage *message;

while(message = GetMessage(window->UserPort)) {
  class = message->Class;
  address = (struct Gadget *)message->IAddress;	/* addr of selected gadget */
  ReplyMsg(message);

  switch(class) {
    case GADGETUP:
      return(dogadget(address->GadgetID));
      break;
  }
}

Then, your gadget processing function could be something like...

dogadget(gadnum)
USHORT gadnum;
{
  switch(gadnum) {
    case 1: ActivateGadget(&Gadget2, window, NULL); break;
    case 2: ActivateGadget(&Gadget3, window, NULL); break;
    case 3: ActivateGadget(&Gadget4, window, NULL); break;
    case 4: ActivateGadget(&Gadget5, window, NULL); break;
    case 5: return(1); break;   
  }
  return(0);	        	
}

Now what you need to do is define the next-to-the-last field in your
struct Gadget definition.  This is a user definable field - the ordinal
gadget number.  This is the gadget's 'address'.  I used a 1 for Gadget1.
This will step through your gadgets with the return key.  If you click
on a gadget, the return key will continue on from there.  It is up to
you to do something with the info in the string gadgets, of course.
Using returns as I did will return a value to the original calling
function.  It can use this value to determine what to do next (continue
processing records, etc. - e.g. a '1' means that the user has finished
with string gadget #5).  Excuse my non-ANSI calls here.  ;^)
        
Dan Griffin
griffin@frith.egr.msu.edu		"We're waiting for Godot..."