RowColumn widget. In such cases, you may want to use XmNisHomogeneous and XmNentryClass. Unless
there is some way for a user to to dynamically create widgets while an application is running, these resources are not
particularly useful.
9.5.3 Callbacks
The RowColumn does not provide any specific callback routines that react to user input. While there are no callbacks
for FocusIn and FocusOut events, the widget does have XmNmapCallback and XmNunmapCallback
callback resources. These callbacks are invoked when the window for the RowColumn is mapped and unmapped. The
callbacks are similar to those for the BulletinBoard, but since the RowColumn is not designed specifically to be a
child of a DialogShell, the routines are invoked regardless of whether the parent of the RowColumn is a DialogShell.
The XmNentryCallback is the only other callback that is associated specifically with the RowColumn widget.
This callback resource makes it possible to install a single callback function that acts as the activation callback for
each of the children of a RowColumn widget. The routine specified for the XmNentryCallback overrides the
XmNactivateCallback functions for any PushButton or CascadeButton children and the
XmNvalueChangedCallback functions for ToggleButtons. The XmNentryCallback is a convenience to the
programmer; if you use it, you don't have to install separate callbacks for each widget in the RowColumn.
XmNentryCallback functions must be installed before children are added to the RowColumn, so be sure you call
XtAddCallback() before you create any child widgets.
The callback procedure takes the standard form of an XtCallbackProc. The call_data parameter is an
XmRowColumnCallbackStruct, which is defined as follows:
typedef struct {
int reason;
XEvent *event;
Widget widget;
char *data;
char *callbackstruct;
} XmRowColumnCallbackStruct;
The reason field of this data structure is set to XmCR_ACTIVATE when the XmNentryCallback is invoked. The
event indicates the event that caused the notification. The entry callback function is called regardless of which
widget within the RowColumn was activated. Since an entry callback overrides any previously−set callback lists for
PushButtons, CascadeButtons, and ToggleButtons, the parameters that would have been passed to these callback
routines are provided in the RowColumn callback structure. The widget field specifies the child that was activated,
the widget−specific callback structure is placed in the callbackstruct field, and the client data that was set for
the widget is passed in the data field.
the source code shows the installation of an entry callback and demonstrates how the normal callback functions are
overridden. XtSetLanguageProc() is only available in X11R5; there is no corresponding function in X11R4.
/* entry_cb.c −− demonstrate how the XmNentryCallback resource works
* in RowColumn widgets. When a callback function is set for this
* resource, all the callbacks for the RowColumn's children are reset
* to point to this function. Their original functions are no longer
* called had they been set in favor of the entry−callback function.
*/
#include <Xm/PushBG.h>
#include <Xm/RowColumn.h>
char *strings[] = {
"One", "Two", "Three", "Four", "Five",
9 Manager Widgets 9.5.3 Callbacks
231
"Six", "Seven", "Eight", "Nine", "Ten",
};
void
called(widget, client_data, call_data)
Widget widget;
XtPointer client_data;
XtPointer call_data;
{
XmRowColumnCallbackStruct *cbs =
(XmRowColumnCallbackStruct *) call_data;
Widget pb = cbs−>widget;
printf ("%s: %d0, XtName (pb), cbs−>data);
}
static void
never_called(widget, client_data, call_data)
Widget widget;
XtPointer client_data;
XtPointer call_data;
{
puts ("This function is never called");
}
main(argc, argv)
int argc;
char *argv[];
{
Widget toplevel, parent, w;
XtAppContext app;
int i;
XtSetLanguageProc (NULL, NULL, NULL);
toplevel = XtVaAppInitialize (&app, "Demos",
NULL, 0, &argc, argv, NULL, NULL);
parent = XtVaCreateManagedWidget ("rowcolumn",
xmRowColumnWidgetClass, toplevel,
NULL);
XtAddCallback (parent, XmNentryCallback, called, NULL);
/* simply loop thru the strings creating a widget for each one */
for (i = 0; i < XtNumber (strings); i++) {
w = XtVaCreateManagedWidget (strings[i],
xmPushButtonGadgetClass, parent, NULL);
/* Call XtAddCallback() to install client_data only! */
XtAddCallback (w, XmNactivateCallback, never_called, i+1);
}
XtRealizeWidget (toplevel);
XtAppMainLoop (app);
}
The RowColumn is created and its XmNentryCallback is set to called(). This routine ignores the
client_data parameter, as none is provided. However, we do use the data field of the cbs because this is the
data that is specified in the call to XtAddCallback() for each of the children. We install the never_called()
routine for each PushButton and pass the position of the button in the RowColumn as the client_data. Even
though the entry callback overrides the activate callback, the client_data is preserved.
9 Manager Widgets 9.5.3 Callbacks
232

Get Volume 6A: Motif Programming Manual now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.