home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Usenet 1994 January
/
usenetsourcesnewsgroupsinfomagicjanuary1994.iso
/
sources
/
games
/
volume13
/
engarde
/
part02
/
menus.c
< prev
next >
Wrap
C/C++ Source or Header
|
1992-02-11
|
2KB
|
66 lines
/*********************************************************************
Engarde
File: menus.c
This file contains a convenience function to create menus from
a structure tree.
Version 1: 1/9/92 (Bill James)
*********************************************************************/
#include <X11/Intrinsic.h>
#include <X11/StringDefs.h>
#include <Xm/Xm.h>
#include <Xm/Separator.h>
#include <Xm/PushB.h>
#include <Xm/CascadeB.h>
#include <Xm/RowColumn.h>
#include <Xm/Label.h>
#include "menus.h"
void xs_create_menu_buttons(title, menu, menulist, nitems)
char *title;
Widget menu;
xs_menu_struct *menulist;
int nitems;
{
Arg wargs[1];
int i;
WidgetList buttons;
int separators = 0;
buttons = (WidgetList) XtMalloc (nitems * sizeof(Widget));
if (title) {
XtCreateManagedWidget(title, xmLabelWidgetClass, menu, NULL, 0);
XtCreateManagedWidget("separator", xmSeparatorWidgetClass, menu, NULL,0);
}
for (i = 0; i < nitems; i++) {
if (menulist[i].name == NULL) {
XtCreateManagedWidget("separator", xmSeparatorWidgetClass,
menu, NULL, 0);
separators++;
}
else if (menulist[i].func) {
buttons[i-separators] = XtCreateWidget(menulist[i].name,
xmPushButtonWidgetClass,
menu, NULL, 0);
XtAddCallback(buttons[i-separators], XmNactivateCallback,
menulist[i].func, menulist[i].data);
}
else if (!menulist[i].sub_menu)
buttons[i-separators] = XtCreateWidget(menulist[i].name,
xmLabelWidgetClass,
menu, NULL, 0);
else {
Widget sub_menu;
sub_menu = XmCreatePulldownMenu(menu, menulist[i].sub_menu_title,
NULL, 0);
XtSetArg(wargs[0], XmNsubMenuId, sub_menu);
buttons[i-separators] = XtCreateWidget(menulist[i].name,
xmCascadeButtonWidgetClass,
menu, wargs, 1);
xs_create_menu_buttons(menulist[i].sub_menu_title, sub_menu,
menulist[i].sub_menu, menulist[i].n_sub_items);
}
}
XtManageChildren(buttons, nitems - separators);
}