Global Callbacks
Gadget behavior can be customized using callbacks. Data Access supports four ways of defining callbacks.
-
Callback function—The callback is a C++ function directly attached to the gadget. The following example shows how a callback function can be attached directly to a gadget.
void CustomCallback(IlvGraphic*g, IlvAny userdata) { ... }
int main(int argc, char* argv[]) { ... IlvSymbol* callbackType; IlvGadget* g; IlvAny userData; ... g->setCallback(callbackType, CustomCallback, userData); ... } |
-
Named callback—The registerCallback member function is used to associate a name with a C++ function. This name can then be used as a callback for any gadgets in the container. The following example shows how this can be done:
void CustomCallback(IlvGraphic*g, IlvAny userdata) { ... }
int main() { ... // Register the callback. IlvContainer* cont; ... cont->registerCallback(“MyCallbackName”, CustomCallback); ...
// Use this callback. IlvGadget* g; IlvSymbol* callbackType; ... g->setCallback(callbackType, “MyCallbackName”); ... } |
-
Script callback—The callback is a Script function. These callbacks are usually defined from within the Views Studio environment.
-
Global callback— Data Access adds a way to define and use callbacks globally. The IliCallbackManager class can be used to register callbacks that are globally available and that can have parameters. The callback manager is the unique instance of the IliCallbackManager class and it can be retrieved by calling the IliGetCallbackManager function. For the callback manager to be active, the file <ilviews/dataccess/gcallbak.h> must be included in at least one of the application modules. If this is not the case, the global callbacks will not be available. The following example shows how a callback can be set up as global:
#include <ilviews/dataccess/gcallbak.h> // Define the callback function. void MessageBoxCallbak(IlvGraphic* g, IlAny arg, IlInt paramsCount, const char* const* params) { IlvContainer* view = IlvContainer::getContainer(g); if (paramsCount == 1 && views != NULL) { IlvIMessageDialog msgBox(view->getDisplay(), params[0], NULL, IlvDialogOk, view->getSystemView()); msgBox.show(); } } int main() { ... // Register the global callback. IlvSymbol* callbackName = IlvGetSymbol(“MsgBox”); IliGetCallbackManager().registerCallback(callbackName, MessageBoxCallback); ... } |
Once a global callback has been registered as shown above, it can be used by prefixing its name with the “@” character.
Using a Global Callback in Views Studio
Guidelines for Defining Global Callbacks
Some general guidelines can help you determine which method to use for defining global callbacks:
-
For C++ programmers:
In a pure C++ application where Views Studio is not used, the callback function approach is the most convenient as it results in less coding.
When Views Studio is used to design the panels of the application, the named callback and the global callback approaches are recommended since they enable you to enter the callback name directly in the required inspector in Views Studio.
If a callback is needed in only one panel, the named callback approach is the most suitable. However, if the same callback is required in many panels, the global callback approach is the most appropriate.
-
For Script programmers:
Global callbacks are of little help to Script programmers since it is as convenient and straightforward to define a Script function and use it as a callback as it would be to use a global callback. In effect, we consider that global callbacks have been superseded by the capability to program in Script.
Predefined Global Callbacks
The following is a list of the predefined global callbacks that are available in Data Access:
-
@Quit()
-
@ShowPanel(panelName)
-
@HidePanel(panelName)
-
@Validate(dataSourceName)
-
@Cancel(dataSourceName)
-
@Clear(dataSourceName)
-
@Select(dataSourceName)
-
@StartInsert(dataSourceName)
-
@Commit(sessionName)
-
@Rollback(sessionName)
-
@Connect(sessionName)
-
@QueryConnect(sessionName)