home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The World of Computer Software
/
World_Of_Computer_Software-02-385-Vol-1of3.iso
/
m
/
motifpg2.zip
/
ch13
/
xpopup.c
< prev
next >
Wrap
C/C++ Source or Header
|
1992-08-18
|
3KB
|
120 lines
/*
* Copyright 1989, 1992 O'Reilly and Associates, Inc.
* See ../Copyright for complete rights and liability information.
*/
/*
* xpopup.c - basic Motif popup menu
*/
/*
* So that we can use fprintf:
*/
#include <stdio.h>
/*
* Standard Toolkit include files:
*/
#include <Xm/Xm.h>
/*
* Public include files for widgets used in this file.
*/
#include <Xm/RowColumn.h>
#include <Xm/PushB.h>
#include <Xm/Label.h>
/*
* quit button callback function
*/
/*ARGSUSED*/
void Quit(w, client_data, call_data)
Widget w;
XtPointer client_data, call_data;
{
exit(0);
}
/*
* menu pane button callback function
*/
/*ARGSUSED*/
void PaneChosen(w, client_data, call_data)
Widget w;
XtPointer client_data; /* cast to pane_number */
XtPointer call_data;
{
int pane_number = (int) client_data;
printf("Pane %d chosen.\n", pane_number);
}
static void
PostMenu (w, client_data, event)
Widget w;
XtPointer client_data;
XEvent *event;
{
Widget popup = (Widget) client_data;
XmMenuPosition(popup, event);
XtManageChild (popup);
}
main(argc, argv)
int argc;
char **argv;
{
XtAppContext app_context;
Widget topLevel, box, quit, label, menu, menupane[10];
int i;
String buf[50];
XtSetLanguageProc(NULL, (XtLanguageProc)NULL, NULL);
topLevel = XtVaAppInitialize(
&app_context, /* Application context */
"XPopup", /* application class name */
NULL, 0, /* command line option list */
&argc, argv, /* command line args */
NULL, /* for missing app-defaults file */
NULL); /* terminate varargs list */
box = XtVaCreateManagedWidget(
"box", /* widget name */
xmRowColumnWidgetClass, /* widget class */
topLevel, /* parent widget*/
NULL); /* terminate varargs list*/
label = XtVaCreateManagedWidget(
"label", /* widget name */
xmLabelWidgetClass, /* widget class */
box, /* parent widget*/
NULL); /* terminate varargs list*/
quit = XtVaCreateManagedWidget(
"quit", /* widget name */
xmPushButtonWidgetClass,/* widget class */
box, /* parent widget*/
NULL); /* argument list*/
XtAddCallback(quit, XmNactivateCallback, Quit, NULL);
menu = XmCreatePopupMenu(label, "menu", NULL, 0);
XtAddEventHandler(label, ButtonPressMask, False, PostMenu, menu);
for (i = 0; i < 10; i++) {
sprintf(buf, "entry%d", i);
menupane[i] = XtVaCreateManagedWidget(buf, /* widget name */
xmPushButtonWidgetClass, menu, NULL);
XtAddCallback(menupane[i], XmNactivateCallback, PaneChosen, i);
}
XtRealizeWidget(topLevel);
XtAppMainLoop(app_context);
}