Exposing Callbacks and Event Methods

In addition to customizing the appearance of your class, you might also want to customize its behavior. The behavior, or interaction between your UI and the rest of your application is generally controlled with callbacks in Motif, and with event methods in Java. For more information, see Callback Procedures and Event Methods .

As you build your classes, you build a great deal of functionality into your UI classes using the callbacks and event methods for the class elements and the methods, (public, private, and protected) for the class itself.

You can give instances of a class access to the callbacks or event methods of its elements by exposing them just as you would any other resource. The process with which you do this is identical regardless of the language you are using. The results, however, differ slightly.

Note: This is an area where it is very easy to break "good" object-oriented programming practice. Consider very carefully whether you want to use an exposed callback or event method, or whether you should use a subclass instead.

Note: In ViewKit, it is better practice to use ViewKit's callback mechanism, provided by VkCallbackObject, rather than exposed callback resources.

Exposing Callbacks

Exposing a resource

To expose a callback or event method, follow these steps:

1. Switch the Browser to Classes view.

2. Update the Resource Editor for the desired component object.

3. Scroll the Resource Editor to the desired callback or event method.

4. Set the resource to the value that you want each instance to take by default.

5. Select Expose from the option menu to the right of the resource text field.

Note: Exposed resources are designated on the Resource Editor with an "open eye" icon to the left of the option menu.

Callback Source Code

With Motif, you can choose whether the instance callback routine augments or replaces the class's exposed callback. This is controlled by the Remove Overridden Exposed Callbacks toggle on the Code Generation tab of the Code Generation Preferences dialog (Browser:Options). Refer to Toggle options for more information.

Callbacks for class members (Motif) are generated in source code as two separate methods, described in detail in Object-Oriented Programming with C++ and OSF/Motif (Prentice Hall, 1995, 2nd Ed. ISBN 0-13-209255-7) by Doug Young. Exposing a callback results in a third, public method.

See Using Callbacks in C++ Classes for detailed information on these methods.