Methods are similar to callbacks and are application procedures which are called in response to events within the user interface. The difference lies in the fact that Methods are called slightly differently and are declared as member functions of a C++ class.
The X toolkit knows nothing of C++ and hence WorkShop Visual uses indirection in order to interface between your C++ class and Motif.
When generating code for your Method, WorkShop Visual in fact generates TWO entries for each Method you declare. A static member function is declared by WorkShop Visual and registered as the callback for the given event with Motif. This callback utilizes the private data parameter - it is always a pointer to the class instance - colloquially 'this'. The static member function when called references through the private data parameter to find the class instance data, then calls a second non-static member function - YOUR function - passing on the widget and callback specific-data from Motif. This second class procedure is declared virtual so that you can override the behavior in derived classes.
For example, suppose you want to declare a Method 'my_method' in class 'my_class'. WorkShop Visual will generate the following declarations and code for you:
class my_class: public ... {
...
/* WorkShop Visual Generated Callback as Motif Sees It */
static void my_method(Widget,XtPointer,XtPointer);
/* YOUR APPLICATION PROCEDURE - CALLED FROM ABOVE */
virtual void my_method(Widget,XtPointer);
...
} ;
...
typedef my_class_p *my_class ;
...
/* WorkShop Visual Generated implementation of the static member function */
void my_class::my_method(Widget widget,
XtPointer client_data,
XtPointer call_data)
{
my_class_p instance = (my_class_p) client_data ;
/* CALL USER-DEFINED APPLICATION PROCEDURE */
instance->my_method(widget,call_data) ;
}
When WorkShop Visual registers the callback with Motif (in the generated class create procedure), it will take the form:
XtAddCallback(widget,XmNactivateCallback,my_method,(XtPointer) this)
The my_method parameter here is the WorkShop Visual generated static member function, not the (virtual) application-defined Method.
Note that your application-defined Methods are different from Callbacks in that they only expect two parameters:
void my_class::my_method(Widget widget, XtPointer call_data)
{
XmAnyCallbackStruct *cb = (XmAnyCallbackStruct *) call_data ;
...
}
WorkShop Visual therefore generates TWO member functions for each declared method; one is declared static, the other, virtual. WorkShop Visual also generates the implementation of the static member function, whose sole purpose is to find the class instance data then call the second application-defined class procedure with appropriate parameters.
You can search for a method (or a string in a method name) through all the widgets in your design using the search facility.
NOTES
The Method which is called in response to an event is the one which belongs to the widget (if it is itself a class) or to the most immediate ancestor of the widget which has been declared as a class.
See also: