I am trying to create an option menu using Motif toolkit.
If I try this, it works:
#include <stdlib.h>
#include <stdio.h>
#include <dirent.h>
#include <Xm/Xm.h>
#include <Xm/Form.h>
#include <Xm/Label.h>
#include <Xm/PushB.h>
#include <Xm/RowColumn.h>
Widget make_menu_item(char *item_name, Widget menu);
/* XT/XM RELATED VARIABLES */
XtAppContext context;
XmStringCharSet char_set = XmSTRING_DEFAULT_CHARSET;
/* WIDGETS */
Widget toplevel;
Widget form;
Widget pulldown_menu;
Widget option_menu;
Widget option_item[100];
int option_items = 0;
int main(int argc, char *argv[]) {
Arg al[10];
int ac;
/* CREATE TOP SHELL WIDGET */
toplevel = XtAppInitialize(&context, "", NULL, 0, &argc, argv, NULL, NULL, 0);
/* RESIZE TOP LEVEL*/
ac = 0;
XtSetArg(al[ac], XmNheight, 900); ac++;
XtSetArg(al[ac], XmNwidth, 600); ac++;
XtSetValues(toplevel, al, ac);
/* PULLDOWN MENU */
ac = 0;
pulldown_menu = XmCreatePulldownMenu(toplevel, "pulldown_menu", al, ac);
ac = 0;
XtSetArg(al[ac], XmNsubMenuId, pulldown_menu); ac++;
XtSetArg(al[ac], XmNlabelString, XmStringCreate("Pulldown Menu", char_set)); ac++;
option_menu = XmCreateOptionMenu(toplevel, "option_menu", al, ac);
XtManageChild(option_menu);
make_menu_item("FOO", pulldown_menu);
make_menu_item("BAR", pulldown_menu);
/* REALIZE TOPLEVEL */
XtRealizeWidget(toplevel);
XtAppMainLoop(context);
return 0;
}
Widget make_menu_item(char *item_name, Widget menu) {
int ac;
Arg al[10];
Widget item;
ac = 0;
XtSetArg(al[ac], XmNlabelString, XmStringCreateLtoR(item_name, char_set)); ac++;
item = XmCreatePushButton(menu, item_name, al, ac);
XtManageChild(item);
/*XtAddCallback(item, XmNactivateCallback, menuCB, client_data);*/
XtSetSensitive(item, True);
return(item);
}
However, when I try to use form
as parent for PulldownMenu and OptionMenu it does not work.
How can I attach an option menu to a form? Why the option menu is not displayed in this case?
#include <stdlib.h>
#include <stdio.h>
#include <dirent.h>
#include <Xm/Xm.h>
#include <Xm/Form.h>
#include <Xm/Label.h>
#include <Xm/PushB.h>
#include <Xm/RowColumn.h>
Widget make_menu_item(char *item_name, Widget menu);
/* XT/XM RELATED VARIABLES */
XtAppContext context;
XmStringCharSet char_set = XmSTRING_DEFAULT_CHARSET;
/* WIDGETS */
Widget toplevel;
Widget form;
Widget pulldown_menu;
Widget option_menu;
Widget option_item[100];
int option_items = 0;
int main(int argc, char *argv[]) {
Arg al[10];
int ac;
/* CREATE TOP SHELL WIDGET */
toplevel = XtAppInitialize(&context, "", NULL, 0, &argc, argv, NULL, NULL, 0);
/* RESIZE TOP LEVEL*/
ac = 0;
XtSetArg(al[ac], XmNheight, 900); ac++;
XtSetArg(al[ac], XmNwidth, 600); ac++;
XtSetValues(toplevel, al, ac);
/* CREATE FORM MANAGER WIDGET */
form = XmCreateForm(toplevel, "form", al, ac);
/* PULLDOWN MENU */
ac = 0;
pulldown_menu = XmCreatePulldownMenu(form, "pulldown_menu", al, ac);
ac = 0;
XtSetArg(al[ac], XmNsubMenuId, pulldown_menu); ac++;
XtSetArg(al[ac], XmNlabelString, XmStringCreate("Pulldown Menu", char_set)); ac++;
option_menu = XmCreateOptionMenu(form, "option_menu", al, ac);
XtManageChild(option_menu);
make_menu_item("FOO", pulldown_menu);
make_menu_item("BAR", pulldown_menu);
/* REALIZE TOPLEVEL */
XtRealizeWidget(toplevel);
XtAppMainLoop(context);
return 0;
}
Widget make_menu_item(char *item_name, Widget menu) {
int ac;
Arg al[10];
Widget item;
ac = 0;
XtSetArg(al[ac], XmNlabelString, XmStringCreateLtoR(item_name, char_set)); ac++;
item = XmCreatePushButton(menu, item_name, al, ac);
XtManageChild(item);
/*XtAddCallback(item, XmNactivateCallback, menuCB, client_data);*/
XtSetSensitive(item, True);
return(item);
}
Add after the line:
XtManageChild(option_menu);
Code to manage the form:
XtManageChild(form);
This will show the option menu.