
When a menu button receives an ACTION_MENU down event, the button’s notify procedure is
called before the menu is displayed. This gives you the chance to modify the menu before-
hand. When the menu button is selected by clicking the SELECT button, the button’s notify
procedure is called before the menu’s notify procedure.
Menu buttons contain a triangle pointing in the direction in which the menu will be
displayed.
The btn_menu.c program in Example 7-2 demonstrates how a menu can be attached to a pan-
el button.
Example 7-2. The btn_menu.c program
/*
* btn_menu.c -- display a panel that has an OPEN LOOK menu button.
* The choices displayed are Yes, No and Quit. If Quit is selected
* in the menu, the program exits.
*/
#include <xview/xview.h>
#include <xview/panel.h>
#include <xview/openmenu.h>
main(argc, argv)
int argc;
char *argv[ ];
{
Frame frame;
Panel panel;
Menu menu;
int selected();
void menu_proc();
xv_init(XV_INIT_ARGC_PTR_ARGV, &argc, argv, NULL);
frame = (Frame)xv_create(NULL, FRAME, NULL);
panel = (Panel)xv_create(frame, PANEL, NULL);
/* Create the menu _before_ the panel button */
menu = (Menu)xv_create(NULL, MENU,
MENU_NOTIFY_PROC, menu_proc,
MENU_STRINGS, "Yes", "No", "Quit", NULL,
NULL);
(void) xv_create(panel, PANEL_BUTTON,
PANEL_LABEL_STRING, "Y/N/Q",
PANEL_NOTIFY_PROC, selected,
PANEL_ITEM_MENU, menu, /* attach menu to button */
NULL);
window_fit(panel);
window_fit(frame);
xv_main_loop(frame);
}
int