#! rnews 4532
Path: van-bc!ubc-vision!uw-beaver!teknowledge-vaxc!sri-unix!hplabs!decwrl!labrea!navajo!ali
From: ali@navajo.STANFORD.EDU (Ali Ozer)
Newsgroups: comp.sys.amiga
Subject: Re: Question on requestors
Keywords: ActivateGadget() without 1.2
Message-ID: <1410@navajo.STANFORD.EDU>
Date: 25 Feb 87 07:26:17 GMT
References: <8136@decwrl.DEC.COM> <13570@sun.uucp>
Reply-To: ali@navajo.UUCP (Ali Ozer)
Organization: Stanford University
Lines: 109
Posted: Tue Feb 24 23:26:17 1987

In article <8136@decwrl>, wecker@cookie.dec.com (DAVE WECKER) writes:
> I have a requestor that contains a string gadget. All I want to do
> is have the requestor come up and PRESELECT the string gadget so
> if the user types, inputs will go directly to the gadget.

Well, as has been answered, you use ActivateGadget() under 1.2... A friend
of mine was pretty disappointed when she discovered this halfway through
her program, which was due for a class the next day. Anyway, quick hack 
she came up with was to actually simulate the I/O event and make intuition
think the mouse actually moved on top of the gadget and clicked it...

Anyway, here's the section of code that did this... Note that 
ActivateGadget() makes this sort of thing unnecessary, although you
might find the following code, written by Lee Taran, to be useful
if you actually want to move the mouse around (for demos, etc...).

------

/* Piece of code showing how to select a gadget by actually moving the mouse
   and selecting the gadget under program control... This code is not
   complete (the code to open libraries etc was removed as it is all
   pretty straightforward). 

   Written by Lee Taran (taran@Sushi.stanford.edu), July 1987
*/

#include <exec/types.h>
#include <exec/io.h>
#include <exec/memory.h>
#include <exec/devices.h>
#include <devices/inputevent.h>
#include <devices/input.h>
#include <intuition/intuition.h>

struct IntuitionBase *IntuitionBase; 
struct GfxBase *GfxBase;

struct Window *Window;
struct Screen *Screen;

/* used to generate my own i/o request  see Select_CmdG */
struct IOStdReq *ioreq;    

/* SetupEnvironment : Opens the libraries, initializes the screen and window
 * that will be used and then activates the command gadget. 
 */ 
SetupEnvironment()
{
  /* Code taken out to open the standard libraries (intuition,
     graphics), then open custom screen (pointed to by
     Screen) and a window within the screen (pointed to be Window) */
  
  /* Initialize the IO device stuff necessary to fake mouse events... */

  if (!(ioreq = CreateStdIO(Window->UserPort))) panic("No IO Req");
  if (OpenDevice("input.device",0,ioreq,0)) panic ("No IO Device");

  Select_CmdG();    /* The command gadget is selected at startup */
}

/* close_things : closes the Libraries that have been opened and
 * frees up whatever memory has been used.
 */
close_things()
{ 
  if (ioreq) { CloseDevice(ioreq); DeleteStdIO(ioreq); }
  /* Close window, screen, libraries, etc.. */
}


/* This is a real kludge. Select_CmdG() generates a phoney gadget
 * selection event so that Intuition will think that the user
 * has selected the cmd_gadget.  This saves the user the
 * trouble of having to select and reselect the command window
 * over and over. Set MOUSEBUTTONS IDCMP flag for window when opening it!
 * Obviously this function could be mad more general by passing the
 * gadget in as an argument, but you get the general idea.
 */
Select_CmdG()
{ struct InputEvent phoney;

  /* create a phoney i/o event */
  ioreq->io_Command = IND_WRITEEVENT;
  ioreq->io_Flags = 0;
  ioreq->io_Length = sizeof(struct InputEvent);
  ioreq->io_Data = &phoney;

  /* initialize the phoney event */
  phoney.ie_NextEvent = NULL;
  phoney.ie_Class = IECLASS_RAWMOUSE;
  phoney.ie_TimeStamp.tv_secs = 0;
  phoney.ie_TimeStamp.tv_micro = 0;
  phoney.ie_Code = IECODE_LBUTTON;
  phoney.ie_Qualifier = IEQUALIFIER_RELATIVEMOUSE;

  /* re-position mouse cursor over the command window -- somewhere
   * in the window but out of the way (so as not to distract the
   * user. The following code works for lo res non interlaced screen,
   * with the preferences mouse speed set to 1 (fastest). The factor of "2" 
   * might need to be changed for other type of screens... CMD_LEFT,
   * CMD_WIDTH, etc, define the border around the command gadget to be 
   * selected. 
   */
  phoney.ie_X = (WORD)2*(CMD_LEFT + CMD_WIDTH - 2 - Window->MouseX);
  phoney.ie_Y = (WORD)2*(CMD_TOP + 2 - Window->MouseY);
  
   /* queue up the i/o event so that Intuition will grab it */
  DoIO(ioreq);
}
