Gadget handlers

Introduction

When the Window module wishes to notify a gadget of an event or operation it will call the gadget handler through the SWI supplied on registration (if the gadget's FeatureMask indicates that a 'Private handler' is present). These handler entry points have been extended in recent versions of the Window module. This document duplicates and extends on some of the details in AppNote 281.

The gadget handler is entered with the following conditions :

OffsetContents
R0Operation flags (dependent on reason code)
R1Gadget type
R2Reason code (see below)
R3...Reason code dependent

The reason codes are:

ReasonMeaning
0Reserved
1Create new gadget
2Delete gadget
3Fade gadget
4Gadget method
5Reserved
6Mouse click on gadget icon
7Reserved
8Reserved
9Plot gadget
10Set focus to gadget
11Move gadget
12Reserved
13Parent window shown notification
14Mouse scroll gadget
15Gadget lost focus notification
16Redraw request
17Timer triggered
18+Reserved

Over time more handlers may become available and so the SWI handler should not assume that only the handlers it has requested will result in a call out. For a handler in C this would result in nothing being done by the default case.

Entry Points

GADGET_ADD
Create a new gadget
R2=GADGET_ADD (1)
R3=Pointer to gadget template
R4=ObjectId of parent window
R5=Wimp window handle
R0=Handle to use in future calls
R1=Pointer to icon list
Interrupts are undefined
Fast interrupts are undefined
Processor is in undefined mode
Not defined

On receiving this reason code an extension module should create the new gadget from the given data and return its icon list and private handle. The template will already have been checked for valid flags. Any attached objects (like the Click show objects attached to action buttons) should be created using the GLib calls.

GADGET_REMOVE
Remove a gadget
R0=Flags:
Bit(s)Meaning
0Set if gadget should remove attached objects
1-31Reserved, must be 0
R2=GADGET_REMOVE (2)
R3=Pointer to private data
R0 - R12=Preserved
Interrupts are undefined
Fast interrupts are undefined
Processor is in undefined mode
Not defined

On receiving this reason code an extension module should remove the gadget. If the recurse bit is set then any attached objects such as Windows or Menus should not be removed. This is in common with the flag bit in the SWI Toolbox_DeleteObject.

GADGET_FADE
Fade or unfade a gadget
R2=GADGET_FADE (3)
R3=Pointer to private data
R4=State (non zero = fade)
R5=ObjectId of window to which this Gadget belongs
R0 - R12=Preserved
Interrupts are undefined
Fast interrupts are undefined
Processor is in undefined mode
Not defined

On receiving this reason code an extension module should fade or unfade the gadget, according to the value in R4. A Gadget will have been faded by the client making a call to the Gadget_SetFlags method.

GADGET_METHOD
Perform a gadget method
R2=GADGET_METHOD (4)
R3=Pointer to private data
R4=Pointer to registers passed to Toolbox_ObjectMiscOp SWI
R=Depends on Method
Interrupts are undefined
Fast interrupts are undefined
Processor is in undefined mode
Not defined

The window module raises this reason code when a task uses the Toolbox_ObjectMiscOp SWI on a Gadget which is provided by an extension module. R4 points to a register bank (in C terms this is the _kernel_swi_regs type) which contains the values that the client passed to the SWI. If any information is to be returned to the client then this bank should be updated. i.e. to return a value in R0 do not set R0 to the value but update the contents of the location pointed to by R4+0. Note that the generic Gadget methods such as Gadget_SetFlags do not result in a call to GADGET_METHOD.

GADGET_MCLICK
Mouse click on a gadget icon
R2=GADGET_MCLICK (6)
R3=Pointer to private data
R4=Pointer to wimp event block
R1=Claim
Interrupts are undefined
Fast interrupts are undefined
Processor is in undefined mode
Not defined

The window module raises this reason code when an icon belonging to the Gadget is clicked on. The event block in R4 is just like the one returned by Wimp_Poll when an icon is clicked on. An extension module would typically use this to update the state of the Gadget or return a 'high-level' Toolbox Event. By setting R1 to be non-zero the Window module will update the task's ID block so that when the wimp mouse click event is delivered it is marked as belonging to this Gadget. Although it is unlikely that the task will be interested in the underlying event it should still be claimed. Possible exceptions to this rule are when the menu mouse button is used - in this case, not claiming the click (R1 = 0) passes the mouse click on which would allow the Window's menu to be viewed. This is not true for a popup menu type Gadget though.

It is also possible to claim the event entirely so that the task will not see the mouse click. This is achieved by setting R1 to -1 on exit, but this should be avoided as this does not fit the Toolbox model and so should only be done in specialist cases.

GADGET_PLOT
Plot a gadget (for !ResEd)
R2=GADGET_PLOT (9)
R3=Pointer to gadget template definition
R0 - R12=Preserved
Interrupts are undefined
Fast interrupts are undefined
Processor is in undefined mode
Not defined

The window module raises this reason code when !ResEd is plotting Gadgets. The extension module should use Wimp_PlotIcon or Window_PlotGadget (for composite Gadgets) to display the Gadget which is defined by the template.

GADGET_SETFOCUS
Set the focus to a gadget
R0=Flags:
Bit(s)Meaning
0Set if the focus is being set 'upwards', clear if the focus is being set 'downwards'
1-31Reserved, must be 0
R2=GADGET_SETFOCUS (10)
R3=Pointer to private data
R0 - R12=Preserved
Interrupts are undefined
Fast interrupts are undefined
Processor is in undefined mode
Not defined

This call will be made when the Window module wishes to set the focus to a Gadget. The direction signals whether to set the focus to the before or after Gadget in the event of this Gadget being faded. Care should be taken when 'passing on' the focus as an infinite loop will be entered if all members of the list are faded. Gadgets which are composite and consist of a writable Gadget do not need to worry about this and should just set focus to their writable without checking their faded status, assuming that the before and after fields of the underlying writable have been set.

GADGET_MOVE
Move a gadget
R2=GADGET_MOVE (11)
R3=Pointer to private data
R4=Wimp window handle
R5=Pointer to new bounding box
R6=Window ObjectId
R0 - R12=Preserved
Interrupts are undefined
Fast interrupts are undefined
Processor is in undefined mode
Not defined

This call is made when the Gadget_Move method is applied to a Gadget. A composite gadget must supply a handler if it is going to be moved after creation as the default handler can only move the icons which belong directly to a Gadget. It is also of use if the Gadget supports resizing - the default mover will only move by an offset as it generally does not know how to handle any change in the size of the bounding box.

GADGET_POSTADD
Gadget post-add notification (reason 12)
R2=GADGET_POSTADD (12)
None
Interrupts are undefined
Fast interrupts are undefined
Processor is in undefined mode
Not defined

FIXME: The entry and exit conditions of this reason code are not documented.

GADGET_WINDOWSHOW
Parent window shown or hidden
R2=GADGET_WINDOWSHOW (13)
R3=Pointer to private data
R4=Window ObjectId
R5=Wimp window handle
R6=1 if window is being shown, 0 if window is being hidden
R0 - R12=Preserved
Interrupts are undefined
Fast interrupts are undefined
Processor is in undefined mode
Not defined

This call is made to inform the gadget that its parent Window has been shown or has been hidden. Gadgets may wish to take action the first time they are shown or to stop an action once the window is hidden. A typical example of such a gadget might be a timer.

GADGET_MSCROLL
Mouse scroll on a gadget
R2=GADGET_MSCROLL (14)
R3=Pointer to private data
R4=Window ObjectId
R5=Wimp window handle
R6=Pointer to wimp event block
R0 - R12=Preserved
Interrupts are undefined
Fast interrupts are undefined
Processor is in undefined mode
Not defined

This call is made when the Window module receives a scroll event for an icon belonging to the gadget. In order for the WindowScroll module to generate such events the icons must have the correct validation string set. See the WindowScroll module document for more details.

GADGET_LOSTFOCUS
Gadget lost the focus
R2=GADGET_LOSTFOCUS (15)
R3=Pointer to private data
R4=Window ObjectId
R5=Wimp window handle
R6=Pointer to wimp event block
R0 - R12=Preserved
Interrupts are undefined
Fast interrupts are undefined
Processor is in undefined mode
Not defined

This call is made when the Window module detects that a gadget has lost the focus, either due to a cursor movement or the focus being moved to another icon (even temporarily by a Menu). Gadgets may wish to take action based on having lost the focus, such as validating input.

GADGET_REDRAW
Redraw a region of a gadget
R0=Flags:
Bit(s)Meaning
01 if the gadget needs to be redrawn entirely, 0 if part of the gadget is obscured
11 if the gadget should be rendered faded, 0 if the gadget should be rendered normally
2-31Reserved
R2=GADGET_REDRAW (16)
R3=Pointer to private data
R4=Pointer to redraw bounding box in workspace coordinates
R5=Pointer to window state block (as returned from Wimp_GetWindowState)
R6=Pointer to gadget bounding box in workspace coordinates
R7=X screen coordinate of workspace coordinate 0,0
R8=Y screen coordinate of workspace coordinate 0,0
R0 - R12=Preserved
Interrupts are undefined
Fast interrupts are undefined
Processor is in undefined mode
Not defined

This call is made when the Window module needs to redraw a region of the window covered by a gadget. Gadgets which have the 'redraw' Feature set to include a 'Private Handler' will be automatically registered with the RedrawManager module and this entry point will be called to redraw their content. The 'Gadget_AtBack' flag is used to control whether the redraw occurs before or after icon rendering. Because the redraw operation uses the RedrawManager, the order of such gadgets within the window will be arbitrary, but always before or after all other (non-Redraw) gadgets. The Redraw region will be bounded by the graphics window. See the Rendering into Windows document for more details.

GADGET_TIMER
A gadget timer was triggered
R2=GADGET_TIMER (17)
R3=Pointer to private data
R4=Window ObjectId
R5=Wimp window handle
R0 - R12=Preserved
Interrupts are undefined
Fast interrupts are undefined
Processor is in undefined mode
Not defined

This call is made when a Gadget's timer is triggered. The accuracy of gadget timers cannot be guaranteed. Gadget timers are started either on creation or when the window is shown. They are stopped when the window is hidden.