Search the FAQ Archives

3 - A - B - C - D - E - F - G - H - I - J - K - L - M
N - O - P - Q - R - S - T - U - V - W - X - Y - Z
faqs.org - Internet FAQ Archives

Motif FAQ (Part 6 of 9)
Section - 181) What is the best way to create popup menus?

( Part1 - Part2 - Part3 - Part4 - Part5 - Part6 - Part7 - Part8 - Part9 - Single Page )
[ Usenet FAQs | Web FAQs | Documents | RFC Index | Airports ]


Top Document: Motif FAQ (Part 6 of 9)
Previous Document: 180) Should I have a cascade button without a submenu in a pulldown
Next Document: 182) How do popup menus work?
See reader questions & answers on this topic! - Help others by sharing your knowledge
[Last modified: August 92]

Susan Murdock Thompson (from OSF): In general, create a popupMenu as the child
from which you will be posting it from (ie: if you have a bulletinBoard with a
PushButton in it and want MB2 on the pushButton to post the popupMenu, create
the popupMenu as a child of the pushButton).  [This parent-child relationship
seems to make a big difference in the behavior of the popups.]  Add an event
handler to handle buttonPress events.  You'll need to check for the correct
button (what you've specified menuPost to be) before posting the menu.

To create a popup that can be accessible from within an entire client window,
create it as the child of the top-most widget (but not the shell) and add
event handlers for the top-most widget and children widgets.

ie:


{

XtManageChild(rc=XmCreateRowColumn(Shell1, "rc", NULL, 0));
XtManageChild(label = XmCreateLabel(rc, "label", NULL, 0));
XtManageChild(text = XmCreateText(rc, "text", NULL, 0));
XtManageChild(pushbutton = XmCreatePushButton(rc, "pushbutton", NULL, 0));

n = 0;
XtSetArg(args[n], XmNmenuPost, "<Btn3Down>"); n++;
popup = XmCreatePopupMenu(rc, "popup", args, n);

XtAddEventHandler(rc, ButtonPressMask, False, PostMenu3, popup);
XtAddEventHandler(text, ButtonPressMask, False, PostMenu3, popup);
XtAddEventHandler(label, ButtonPressMask, False, PostMenu3, popup);
XtAddEventHandler(pushbutton, ButtonPressMask, False, PostMenu3, popup);

XtManageChild(m1 = XmCreatePushButton(popup, "m1", NULL, 0));
XtManageChild(m2 = XmCreatePushButton(popup, "m2", NULL, 0));
XtManageChild(m3 = XmCreatePushButton(popup, "m3", NULL, 0));

XtAddCallback(m1, XmNactivateCallback, SayCB, "button M1");
XtAddCallback(m2, XmNactivateCallback, SayCB, "button M2");
XtAddCallback(m3, XmNactivateCallback, SayCB, "button M3");
}

/* where PostMenu3 is ... */

PostMenu3 (w, popup, event)
Widget w;
Widget popup;
XButtonEvent * event;
{
printf("menuPost = 3, button %d\n", event->button);

if (event->button != Button3)
return;
XmMenuPosition(popup, event);
XtManageChild(popup);
}


User Contributions:

Comment about this article, ask questions, or add new information about this topic:




Top Document: Motif FAQ (Part 6 of 9)
Previous Document: 180) Should I have a cascade button without a submenu in a pulldown
Next Document: 182) How do popup menus work?

Part1 - Part2 - Part3 - Part4 - Part5 - Part6 - Part7 - Part8 - Part9 - Single Page

[ Usenet FAQs | Web FAQs | Documents | RFC Index ]

Send corrections/additions to the FAQ Maintainer:
kenton@rahul.net (Ken Lee)





Last Update March 27 2014 @ 02:11 PM