[Contents] [Index] [Help] [Retrace] [Browse <] [Browse >]

GadTools gadgets follow the same input model as other Intuition
components.  When the user operates a GadTools gadget, Intuition notifies
the application about the input event by sending an IntuiMessage.  The
application can get these messages at the Window.UserPort.  However
GadTools gadgets use different message handling functions to get and reply
these messages.  Instead of the Exec functions GetMsg() and ReplyMsg(),
applications should get and reply these messages through a pair of special
GadTools functions, GT_GetIMsg() and GT_ReplyIMsg().

    struct IntuiMessage *GT_GetIMsg(struct MsgPort *iport)
    void  GT_ReplyIMsg(struct IntuiMessage *imsg)

For GT_GetIMsg(), the iport argument should be set to the window's
UserPort.  For GT_ReplyIMsg(), the imsg argument should be set to a
pointer to the IntuiMessage returned by GT_GetIMsg().

These functions ensure that the application only sees the gadget events
that concern it and in a desirable form.  For example, with a GadTools
slider gadget, a message only gets through to the application when the
slider's level actually changes and that level can be found in the
IntuiMessage's Code field:

    imsg = GT_GetIMsg(win->UserPort);
    object = imsg->IAddress;
    class = imsg->Class;
    code = imsg->Code;
    GT_ReplyIMsg(imsg);
    switch (class)
        {
        case IDCMP_MOUSEMOVE:
            if (object == slidergad)
                {
                printf("Slider at level %ld\n", code);
                }
            ...
            break;
        ...
        }

In general, the IntuiMessages received from GadTools contain more
information in the Code field than is found in regular Intuition gadget
messages.  Also, when dealing with GadTools a lot of messages (mostly
IDCMP_MOUSEMOVEs) do not have to be processed by the application.  These
are two reasons why dealing with GadTools gadgets is much easier than
dealing with regular Intuition gadgets.  Unfortunately this processing
cannot happen magically, so applications must use GT_GetIMsg() and
GT_ReplyIMsg() where they would normally have used GetMsg() and ReplyMsg().

GT_GetIMsg() actually calls GetMsg() to remove a message from the
specified window's UserPort.  If the message pertains to a GadTools gadget
then some dispatching code in GadTools will be called to process the
message.  What the program will receive from GT_GetIMsg() is actually a
copy of the real IntuiMessage, possibly with some supplementary
information from GadTools, such as the information typically found in the
Code field.

The GT_ReplyIMsg() call will take care of cleaning up and replying to the
real IntuiMessage.

    Warning:
    --------
    When an IDCMP_MOUSEMOVE message is received from a GadTools gadget,
    GadTools arranges to have the gadget's pointer in the IAddress
    field of the IntuiMessage.  While this is extremely convenient, it
    is also untrue of messages from regular Intuition gadgets (described
    in the "Intuition Gadgets" chapter).  Do not make the mistake of
    assuming it to be true.

This description of the inner workings of GT_GetIMsg() and GT_ReplyIMsg()
is provided for understanding only; it is crucial that the program make no
assumptions or interpretations about the real IntuiMessage.  Any such
inferences are not likely to hold true in the future.  See the section on
documented side-effects for more information.