
Widget dialog = NULL;
/* first see if this menu item's dialog has been created yet */
XtVaGetValues(w, XmNuserData, &dialog, NULL);
if (!dialog) {
/* menu item hasn't been chosen yet −− create the dialog.
* Use the toplevel as the parent because we don't want the
* parent of a dialog to be a menu item.
*/
dialog = (*func)(toplevel, "dialog", NULL, 0);
XtVaSetValues (XtParent (dialog), XmNtitle, XtName (w), NULL);
XtVaSetValues (dialog, XmNautoUnmanage, True, NULL);
/* store the newly created dialog in the XmNuserData for the menu
* item for easy retrieval next time. (see get−values above.)
*/
XtVaSetValues (w, XmNuserData, dialog, NULL);
}
XtManageChild (dialog);
XtPopup (XtParent (dialog), XtGrabNone);
/* If the dialog was already open, XtPopup does nothing. In
* this case, at least make sure the window is raised to the top
* of the window tree (or as high as it can get).
*/
XRaiseWindow (XtDisplay (dialog), XtWindow (XtParent (dialog)));
}
The output of the program is shown in the figure.
Output of popups.c
The program displays two PushButtons, one of which is a gadget and the other a widget. We get the ButtonPress
event by specifically asking for it using XtAddEventHandler(). This routine requires a widget because it needs a
window. To add an event handler for a gadget, you would have to install it on the gadget's parent, which is a manager
widget. Anytime a ButtonPress event occurs ...