Libhelp Context sensitive help example

OSF/Motif(tm) widgets provide context sensitive help with the XmNhelpCallback resource. It allows you to have a 'Help' menu entry 'On Context' to point to a specific widget (graphical element of your application) or press the Help or F1 Key on the widget having the keyboard focus to get your callback function called.

The libhelp interface function get_help is designed to be usable as a callback function. The help file can be specified as client data.

Registering get_help as help callback.

Suppose you have a PushButton widget instance called button.

Widget button;
button = XtVaCreateManagedWidget 
    ("button", xmPushButtonWidgetClass, 
     parent, NULL);

The following code registers get_help as help callback for this button. The HTML help document is in the file buttons.html.

XtAddCallback (button, XmNhelpCallback, 
	       (XtCallbackProc) get_help, 
	       (XtPointer) "buttons.html");

Useful indirection

To have help file specification at a common place we recommend another style of context sensitive help using it's own context callback. All widgets use this context callback with different help symbols passed as client data.

Each help symbol is associated to a help file in the context callback.

For example:

#define context_button 0
XtAddCallback (button, XmNhelpCallback, 
	       (XtCallbackProc) context_cb, 
	       (XtPointer) context_button);
static void 
context_cb (Widget w, XtPointer client_data, XtPointer call_data)
{
    /* you can use an array or a switch statement ... */	
    static char* help_files[] = {
	"buttons.html", 
	"menus.html",
	...
    };
    /* range checking should go in here */
    get_help (w, help_files [(int) client_data], call_data);
}

-----------

Libhelp version 1.8.1 (Jun 28. 95).
Thomas Harrer