UpPreviousNext

Callback Procedures and Event Methods

To connect your interface to the rest of your application, you must add callback procedures (for Motif) or event methods (for Java). These callbacks and event methods respond to various actions, or events, on the interface, such as a key press or window exposure.

Adding callbacks and methods

You add a callback procedure or an event method by assigning its name to one of an object's callback or event resources. You can then edit the resource using the Resource Editor as you edit any other resource.

To add a callback as the activateCallback of a push button, follow these steps:

1. Update the Resource Editor for the push button.

2. Click the (...) button to the right of the activateCallback text field to display the Callback Editor:

 

Callback Editor

3. Enter the Procedure Name, select a Parameter Type, and enter the Parameter Name in the appropriate fields, hitting enter to apply the value to the callbacks list. After adding whatever other callbacks you wish to associated with the activateCallback, press Apply.

4. To add code to the callback, select it in the Callback List and press Edit. Builder Xcessory generates code and brings up your favorite editor with the correct file loaded and positioned at your new callback.


Note: You can edit only procedures that have been applied.

Adding an event method

To add an event method for the ActionEvent of a Java push button, follow these steps:

1. Update the Resource Editor for the push button.

2. Bring up the extended editor for the ActionEvent resource ( ActionEvent Editor ).

 

ActionEvent Editor

3. Enter the procedure name in the ActionEvent Editor's text field, and apply the value to the resource (Apply).

4. To edit the code for the method, be sure that the method name has been applied, then press the Edit button to the right of the text field. Builder Xcessory generates Java code and brings up your favorite editor with the correct file loaded and positioned at your new method.

Predefined Callbacks

Click on the arrow button to the right of the Procedure Name field to display the list of predefined callbacks. Predefined callbacks are provided for common operations such as setting values, managing and unmanaging windows, etc. These predefined callbacks also behave correctly when Builder Xcessory is in Play Mode, allowing you to test the look of the interface without building the application. For more detailed information on these callbacks, refer to the Builder Xcessory Reference Manual .

Using Classes predefined callbacks

To set a callback resource to a predefined callback, follow these steps:

1. Display the Callback Editor for the appropriate resource.

2. Click on the arrow button to display the list of predefined callbacks.

3. Click on a predefined callback on the list.

4. Apply the contents of the Callback Editor to the resource.

Predefined callbacks are especially useful for rapidly prototyping your application. They allow you to preview many common actions that are performed in your interface, during the development process when the efficient execution of the application is not as important.

Using Callbacks in C++ Classes

For a general introduction to classes, refer to Classes . For more detailed information about using exposed resources and methods, refer to Exposing Resources and Exposing Callbacks and Event Methods .

Adding callbacks to classes

Whenever you add a callback to an object within a class, Builder Xcessory generates two methods:

· A private static method assigned to the widget using XtAddCallback() . This is static because Xt is a C library, and thus cannot use a non-static method. This method is automatically named your_callback_name Callback(Widget, XtPointer, XtPointer) .

· A protected virtual method containing the actual code for your callback. This method is given the name you specified for the callback, your_callback_name (Widget, XtPointer, XtPointer) .

The static method is passed a structure pointer that contains a pointer to the instance of the class that initiated the callback and a pointer to any client data that you specified for the callback. The static method then calls the actual class method (the real callback) and passes all of the standard Xt callback parameters ( w , client_data , call_data ).

Exposing callbacks

When you expose a callback in a class, Builder Xcessory generates the two methods described previously, and a public method that adds additional callback functions to the widget. This method's name incorporates the widget's instance name and callback resource name. It uses XtAddCallback() to optionally append to, or replace, the existing callback list. Appending or replacing is controlled with the Remove Overridden Exposed Callbacks toggle on the Code Generation tab (Browser:Options:Language Settings).

Builder Xcessory also allows you to set callbacks defined by the various ViewKit components (ViewKit Callbacks). In the Resource Editor, these callbacks appear identical to Xt callbacks. However, during code generation, these ViewKit callbacks are generated only as methods of the ViewKit component and are added using VkAddCallbackMethod().

Using Event Methods in Java Classes

For a general introduction to classes, refer to Classes . For a detailed discussion of using exposed resources and methods, refer to Exposing Resources and Exposing Callbacks and Event Methods .

Adding event methods to classes

When you add an event method to an object within a class, Builder Xcessory adds your routine as a public method.

Exposing event methods

When you expose an event method in a class, you can then specify an additional method (on a per instance basis) to be called in response to the event.


Note: Exposing methods in Java is meaningful only if the original event method, specified in the class definition, allows the event to propagate up the instance chain to the parent (original event method returns "false"). Refer to you Java documentation for more information on AWT event processing.
UpPreviousNext