Path: utzoo!attcan!uunet!husc6!uwvax!speedy!solomon From: solomon@speedy.cs.wisc.edu (Marvin Solomon) Newsgroups: comp.windows.x Subject: Re: How do I create popup menus with Xt? Keywords: menus popup toolkit x11 widgets Message-ID: <6006@spool.cs.wisc.edu> Date: 18 Jul 88 18:34:06 GMT References: <6005@spool.cs.wisc.edu> Sender: news@spool.cs.wisc.edu Reply-To: solomon@speedy.cs.wisc.edu (Marvin Solomon) Organization: U of Wisconsin CS Dept Lines: 143 Here is my best effort at popup menus using Xt and Xaw. See my previous message for discussion. (If you haven't seen the "previous message", just wait a bit). ------------------------------- #include #include #include #include #include #include #include #include /* Command line options table. Only resources are entered here...there is a pass over the remaining options after XtParseCommand is let loose. */ static XrmOptionDescRec options[] = { {"-label", "*label", XrmoptionSepArg, NULL} }; /* * Report the syntax for calling xlabel */ Syntax(call) char *call; { fprintf( stderr, "Usage: %s\n", call ); } /* ARGSUSED */ void callback(w, str, dummy) Widget w; char *str; int dummy; { printf("%s button\n", str); fflush(stdout); } /* ARGSUSED */ void done(w, str, dummy) Widget w; char *str; int dummy; { exit(0); } /* ARGSUSED */ void set_menu_position(shell_widget, enable_widget, dummy) Widget enable_widget, shell_widget; int dummy; { Position x, y; Arg args[2]; XtTranslateCoords(enable_widget, (Position)5, (Position)5, &x, &y); XtSetArg(args[0], XtNx, x); XtSetArg(args[1], XtNy, y); XtSetValues(shell_widget, args, TWO); } void main(argc, argv) unsigned int argc; char **argv; { Widget toplevel, menu_bar, button, popupshell, menu, popupbutton; XtPopdownIDRec popdown_pair; XtTranslations button_actions, popup_actions; Arg arg; toplevel = XtInitialize( "popup_test", "XPopupTest", options, XtNumber(options), &argc, argv ); if (argc != 1) Syntax(argv[0]); button_actions = XtParseTranslationTable( ": highlight() set()\n"); popup_actions = XtParseTranslationTable( ": set() MenuPopup(menu)\n"); /**** menu bar ****/ menu_bar = XtCreateManagedWidget( "menu_bar", boxWidgetClass, toplevel, (Arg *)0, ZERO); /**** menu bar items ****/ button = XtCreateManagedWidget( "yes", commandWidgetClass, menu_bar, (Arg *)0, ZERO ); XtAddCallback(button, XtNcallback, callback, (caddr_t)"yes"); popupbutton = XtCreateManagedWidget( "ShowMenu", commandWidgetClass, menu_bar, (Arg *)0, ZERO ); XtOverrideTranslations(popupbutton, popup_actions); /**** popup menu ****/ popupshell = XtCreatePopupShell("menu", overrideShellWidgetClass, toplevel, (Arg *)0, ZERO); menu = XtCreateManagedWidget( "PopupMenu", boxWidgetClass, popupshell, (Arg *)0, ZERO); XtAddCallback(popupshell, XtNpopupCallback, set_menu_position, (caddr_t)popupbutton); /* XtAddCallback(popupbutton, XtNcallback, XtCallbackExclusive, (caddr_t)popupshell); */ popdown_pair.enable_widget = popupbutton; popdown_pair.shell_widget = popupshell; /**** popup menu items ****/ /* menu option 1 */ button = XtCreateManagedWidget( "choice1", commandWidgetClass, menu, (Arg *)0, ZERO ); XtAddCallback(button, XtNcallback, callback, (caddr_t)"button1"); XtAddCallback(button, XtNcallback, XtCallbackPopdown, (caddr_t)&popdown_pair); XtOverrideTranslations(button, button_actions); /* menu option 2 */ button = XtCreateManagedWidget( "choice2", commandWidgetClass, menu, (Arg *)0, ZERO ); XtAddCallback(button, XtNcallback, callback, (caddr_t)"button2"); XtAddCallback(button, XtNcallback, XtCallbackPopdown, (caddr_t)&popdown_pair); XtOverrideTranslations(button, button_actions); /* menu option 3 */ button = XtCreateManagedWidget( "quit", commandWidgetClass, menu, (Arg *)0, ZERO ); XtAddCallback(button, XtNcallback, done, (caddr_t)"done"); XtOverrideTranslations(button, button_actions); XtRealizeWidget(toplevel); XtMainLoop(); } Marvin Solomon Computer Sciences Department University of Wisconsin, Madison WI solomon@cs.wisc.edu or seismo!uwvax!solomon