Rogue Wave Views Gadgets > Understanding Gadgets > Common Gadget Properties > Associating a Callback with a Gadget
 
Associating a Callback with a Gadget
You can associate a callback function with a gadget using the method IlvGraphic::addCallback. A callback function is generally invoked by the handleEvent member function of its associated gadget when the user performs an action on it. The prototype of the callback function is defined by the IlvGraphicCallback type.
A gadget can define several callback types, each one corresponding to a specific user action. Each callback type stores a list of callback functions that will be invoked when the related action is performed.
Predefined Callback Types
Gadgets have predefined callback types:
*Main—This callback type defines the callbacks that carry out the main action attached to a gadget.
*Focus In—This callback type defines callbacks that carry out actions performed when the gadget is given the focus. The symbol corresponding to this callback type can be retrieved by FocusInSymbol. See Focus Management.
*Focus Out—This callback type defines callbacks that carry out actions performed when the gadget loses the focus. The symbol corresponding to this callback type can be retrieved by FocusOutSymbol. See Focus Management.
*Enter Gadget—This callback type defines callbacks that carry out actions performed when the mouse enters the gadget. The symbol corresponding to this callback type can be retrieved by EnterGadgetSymbol. See Gadget Holder Events.
*Leave Gadget—This callback type defines callbacks that carry out actions performed when the mouse leaves the gadget. The symbol corresponding to this callback type can be retrieved by LeaveGadgetSymbol. See Gadget Holder Events.
For example, if you want to add a Focus In callback to a gadget, you can code:
gadget->addCallback(IlvGadget::FocusInSymbol(), callback);
where callback has been declared as follows:
void callback(IlvGraphic* g, IlAny arg) { ... }
In addition to these general predefined callback types, each gadget type has specific predefined callback types attached. For more details, see the sections describing the individual gadgets.

Version 5.7
Copyright © 2013, Rogue Wave Software, Inc. All Rights Reserved.