Esta rutina crea un menú asociado a parent, que podrá ser a su vez otro menú con su correspondiente botón de cascada asociado (menu_name y menu_initial), o un menú popup. Varios botones (o tan solo uno) conformarán el menú los botones vienen especificados por el vector botones, y utiliza para su creación otra rutina incluida en esta referencia.
Devuelve el identificador.


/**************************************************************/

/* Procedure to create a pulldown,popup,option or toggle menu */

/**************************************************************/

typedef struct menubar MENUBAR_PARAM;

struct menubar{
int num;
int type;
char names[MAX_OPTIONS][40];
char initial[MAX_OPTIONS];
void (*CBprocedure[MAX_OPTIONS])();
XtPointer CBdata[MAX_OPTIONS];
MENUBAR_PARAM *submenu[MAX_OPTIONS];
};

Widget SCreateMenu(parent,menu_name,menu_initial,botones)
Widget parent;
char *menu_name;
char menu_initial;
MENUBAR_PARAM *botones;
{
Widget menu,button;
Arg args[MAX_ARGS];
register int n,i;
XmString label;
int type;

type=botones->type;

switch (type) {
case M_PULL:
n=0;
menu=(Widget)XmCreatePulldownMenu(parent,"menu",args,n);

for (i=0;inum;i++) {
if (botones->submenu[i] == (MENUBAR_PARAM *)NULL) {
button=SCreateButton(menu,PUSH,botones->names[i],botones->initial[i]);
XtAddCallback(button,XmNactivateCallback,botones->CBprocedure[i],botones->CBdata[i]);
}
else {
SCreateMenu(menu,botones->names[i],botones->initial[i],botones->submenu[i]);
}
}
break;
case M_TOGGLE:
n=0;
menu=(Widget)XmCreatePulldownMenu(parent,"menu",args,n);

for (i=0;inum;i++) {
if (botones->submenu[i] == (MENUBAR_PARAM *)NULL) {
button=SCreateButton(menu,TOGGLE,botones->names[i],botones->initial[i]);
XtAddCallback(button,XmNarmCallback,botones->CBprocedure[i],botones->CBdata[i]);
}
else {
printf("Error: Toggle menu can not have submenu\n");
exit(1);
}
}
break;
case M_POPUP:
n=0;
menu=(Widget)XmCreatePopupMenu(parent,"menu",args,n);

for (i=0;inum;i++) {
if (botones->submenu[i] == (MENUBAR_PARAM *)NULL) {
button=SCreateButton(menu,PUSH,botones->names[i],botones->initial[i]);
XtAddCallback(button,XmNactivateCallback,botones->CBprocedure[i],botones->CBdata[i]);
}
else {
SCreateMenu(menu,botones->names[i],botones->initial[i],botones->submenu[i]);
}
}
break;
case M_OPTION:
n=0;
menu=(Widget)XmCreatePulldownMenu(parent,"menu",args,n);

for (i=0;inum;i++) {
if (botones->submenu[i] == (MENUBAR_PARAM *)NULL) {
button=SCreateButton(menu,PUSH,botones->names[i],botones->initial[i]);
XtAddCallback(button,XmNactivateCallback,botones->CBprocedure[i],botones->CBdata[i]);
}
else {
printf("Error: Option menu can not have submenu\n");
exit(1);
}
}
break;
}
switch (type) {
case M_PULL:
case M_TOGGLE:
button=SCreateButton(parent,CASCADE,menu_name,menu_initial);
n=0;
XtSetArg(args[n],XmNsubMenuId,menu); n++;
XtSetValues(button,args,n);
XtManageChild(button);
break;
case M_POPUP:
break;
case M_OPTION:
n=0;
label=XmStringCreateLtoR(menu_name,CHARSET);
XtSetArg(args[n],XmNlabelString,label); n++;
XtSetArg(args[n],XmNsubMenuId,menu); n++;
button=(Widget)XmCreateOptionMenu(parent,"menu",args,n);
XmStringFree(label);
return(button);
}
return(menu);
}



Comentarios, críticas, sugerencias y demás a modesto@gias720.dis.ulpgc.es

The GIAS Group e-mail: gias@gias720.dis.ulpgc.es