The following example shows how to create and use a DtMenuButton widget. You can find this code as part of the controls.c demo in the /usr/dt/examples/dtwidget directory.
/*
* Example code for DtMenuButton
*/
#include Dt/DtMenuButton.h
/* MenuButton custom glyph */
#define menu_glyph_width 16
#define menu_glyph_height 16
static unsigned char menu_glyph_bits[] = {
0xe0, 0x03, 0x98, 0x0f, 0x84, 0x1f, 0x82, 0x3f, 0x82, 0x3f, 0x81,
0x7f, 0x81, 0x7f, 0xff, 0x7f, 0xff, 0x40, 0xff, 0x40, 0xfe, 0x20, 0xfe,
0x20, 0xfc, 0x10, 0xf8, 0x0c, 0xe0, 0x03, 0x00, 0x00};
static void CreateMenuButtons(Widget parent) {
Widget menuButton, submenu, titleLabel, button;
Pixmap cascadePixmap;
Pixel fg, bg;
Cardinal depth;
XmString labelString;
Arg args[20];
int i, n;
/* Create title label */
labelString = XmStringCreateLocalized("MenuButton Widget");
n = 0;
XtSetArg(args[n], XmNlabelString, labelString); n++;
titleLabel = XmCreateLabel(parent, "title", args, n);
XtManageChild(titleLabel);
XmStringFree(labelString);
/*
* Create a MenuButton.
* Add push buttons to the built-in popup menu.
*/
labelString = XmStringCreateLocalized("Action"); n = 0;
XtSetArg(args[n], XmNlabelString, labelString); n++;
menuButton = DtCreateMenuButton(parent, "menuButton1", args, n);
XtManageChild(menuButton);
XmStringFree(labelString);
XtVaGetValues(menuButton, DtNsubMenuId, &submenu, NULL);
button = XmCreatePushButton(submenu, "Push", NULL, 0);
XtManageChild(button);
button = XmCreatePushButton(submenu, "Pull", NULL, 0);
XtManageChild(button);
button = XmCreatePushButton(submenu, "Turn", NULL, 0);
XtManageChild(button);
/*
* Create a MenuButton.
* Replace the built-in popup menu with a tear-off menu.
* Add a custom pixmap in the colors of the MenuButton.
*/
labelString = XmStringCreateLocalized("Movement");
n = 0;
XtSetArg(args[n], XmNlabelString, labelString); n++;
menuButton = DtCreateMenuButton(parent, "menuButton1", args, n);
XtManageChild(menuButton);
XmStringFree(labelString);
/* Create a tear-off menu */
n = 0;
XtSetArg(args[0], XmNtearOffModel, XmTEAR_OFF_ENABLED); n++;
submenu = XmCreatePopupMenu(menuButton, "submenu", args, n);
button = XmCreatePushButton(submenu, "Run", NULL, 0);
XtManageChild(button);
button = XmCreatePushButton(submenu, "Jump", NULL, 0);
XtManageChild(button);
button = XmCreatePushButton(submenu, "Stop", NULL, 0);
XtManageChild(button);
XtVaSetValues(menuButton, DtNsubMenuId, submenu, NULL);
/* Create a pixmap using the menu button's colors and depth */
XtVaGetValues(menuButton,
XmNforeground, &fg,
XmNbackground, &bg,
XmNdepth, &depth,
NULL);
cascadePixmap = XCreatePixmapFromBitmapData(XtDisplay
(menuButton),DefaultRootWindow(XtDisplay
(menuButton)),
(char*)menu_glyph_bits,
menu_glyph_width, menu_glyph_height,
fg, bg, depth);
XtVaSetValues(menuButton, DtNcascadePixmap, cascadePixmap,
NULL);
}