jstravis@athena.mit.edu (John S. Travis) (08/02/89)
Below is Douglas Youngs menu package from his book and it seems flawed?
Has anyone got it working? The problem appears to be in create_pane where he
declares "menu_struct *menulist" then later he accesses menulist[i].name
and .func & .data. When compiling i get:invalid type argumenmt 'array indexing'
What's up? It's not an array as declared. What you send in is
a staic array of menu struct ( n items). Is this in other's books? How should
i declare it menu_struct *menulist[]....seems wrong?
thanks,
john travis
/**********************************
* menu.c simple menu package
********************************/
#include <X11/StringDefs.h>
#include <X11/Intrinsic.h>
#include <X11/Shell.h>
#include <Xw/Xw.h>
#include <Xw/MenuBtn.h>
#include <Xw/Cascade.h>
#include <Xw/PopupMgr.h>
typedef struct {
char* name;
void (*func)()
caddr_t data;
} menu_struct;
Widget create_menu_manger(parent,mgrname)
Widget parent;
char *mgrname;
{
Widget shell = XtCreatePopupShell(mgrname,shellWidgetClass,parent,NULL,0);
Widget menu_mgr = XtCreateManagedWidget(mgrname,XwpopupmgrWidgetClass,
shell,NULL,0);
return(menu_mgr);
}
create_pane(mgr,mgrname,name,menulist,nitems)
Widget mgr;
char *name, *mgrname;
menu_struct *menulist;
int nitems;
{
Arg wargs[1];
Widget menupane, pane_shell;
int i;
WidgetList buttons;
/*
* allocate a widgetlist to hold all the button widgets
*/
buttons = (WidgetList) XtMalloc(nitems * sizeof(Widget));
/*
* create a popus shell to this pane
*/
pane_shell = XtCreatePopupShell("pane_shell",shellWidgetClass,mgr,NULL,0);
/*
* create a cascade menu pan and attach it to the given menu manager
*/
XtSetArg(wargs[0],XtNattachTo,(XtArgVal) mgrname);
menupane = XtCreateManagedWidget(name,XwcascadeWidgetClass,
pane_shell,wargs,1);
/*
* create a menu button for each item in the menu
*/
for (i=0; i < nitems; i++){
buttons[i] = XtCreateWidget(menulist[i].name,XwmenubuttonWidgetClass,
menupane,NULL,0);
XtAddCallback(buttons[i],XtNselect,menulist[i].func, menulist[i].data);
}
/*
* manage all button widgets
*/
XtManageChildren(buttons,nitems);
}