|
I think your suggestion has no problem when the parent widget is an
attach dialog box, but how to do if the parent widget is not an attach
dialog box? As in the following example, I even can't display the
separator widget.
Please give me any idea.
Thank.
/* Simple Example for Widgets*/
#include <stdio.h>
#include <DECwDwtApplProg.h>
#define windowName "Simple Widgets Examples"
#define windowClass windowName
#define mainName "mainWindow"
#define mainWidth 250
#define mainHeight 300
#define dialogName "workArea"
#define pushName "pushButton"
#define labelName "label"
#define pushLabel "Click Here"
#define helloLabel "Hello, World!"
#define goodbyeLabel "Goodbye, World!"
/* variable and structure for pop up manual */
static Widget pop_menu;
static void pop_up();
static char popup_translation[] = "<Btn2Down>: pop_up()";
static XtActionsRec our_action_table[] =
{
{"pop_up", (caddr_t)pop_up},
};
/* Button activate call back */
static XtCallbackProc ButtonActivated();
/* callback structures */
static DwtCallback activate_callback[] = {
{ButtonActivated, NULL},
{NULL, NULL}
};
main(argc, argv)
unsigned int argc;
char *argv[];
{
Widget top_level, /* top level widget */
main_widget, /* application main widget */
sep, entry1, entry2, pop_entry1, pop_entry2,
dialog_box, menu_bar, push_button, comm, label;
int n;
Arg args[10];
/* Initialize the toolkit, and create the top-level widget */
top_level = XtInitialize(windowName, windowClass, NULL, 0,
/* no options */
&argc, argv); /* command line */
/* Create a main window widget */
main_widget =
DwtMainWindow(top_level, mainName, 100, 100, mainWidth, mainHeight);
XtManageChild(main_widget);
/* Create a menu bar */
menu_bar = DwtMenuBar(main_widget, "menu_bar",
0, 0);
XtManageChild(menu_bar);
/* Create the first entry inside the menu bar */
entry1 =
DwtPullDownMenuEntry(menu_bar, "entry1", 0, 0,
DwtLatin1String("Selection 1"),
NULL, NULL, NULL);
XtManageChild(entry1);
/* Create the second entry inside the menu bar */
entry2 =
DwtPullDownMenuEntry(menu_bar, "entry2", 0, 0,
DwtLatin1String("Selection 2"),
NULL, NULL, NULL);
XtManageChild(entry2);
/* Create a dialog box */
n = 0;
XtSetArg(args[n], DwtNwidth, 150);
n++;
XtSetArg(args[n], DwtNheight, 300);
n++;
XtSetArg(args[n], DwtNunits, DwtPixelUnits);
n++;
dialog_box = DwtDialogBoxCreate(main_widget, dialogName, args, 3);
XtManageChild(dialog_box);
/* Create a label in the dialog box */
label = DwtLabel(dialog_box, labelName, 10, 20,
DwtLatin1String(helloLabel), NULL);
activate_callback[0].tag = label;
XtManageChild(label);
/* Create a seperator widget between the Label and the Push Button */
sep = DwtSeparator(dialog_box, "sep", 10, 40,
DwtOrientationHorizontal);
n = 0;
XtSetArg(args[n], DwtNadbTopAttachment, DwtAttachAdb);
++n;
XtSetArg(args[n], DwtNadbTopWidget, label);
++n;
XtSetArg(args[n], DwtNadbTopOffset, 10);
++n;
XtSetValues(sep, args, 3);
XtManageChild(sep);
/* Create a Push Button Widget */
n = 0;
XtSetArg(args[n], DwtNbordHighlight, True);
n++;
XtSetArg(args[n], DwtNx, 10);
n++;
XtSetArg(args[n], DwtNy, 60);
n++;
XtSetArg(args[n], DwtNactivateCallback, activate_callback);
n++;
XtSetArg(args[n], DwtNlabel, DwtLatin1String("Exit"));
n++;
push_button = DwtPushButtonCreate(dialog_box, pushName, args, n);
XtManageChild(push_button);
/* Create a command window */
comm = DwtCommandWindow(main_widget, "comm",
DwtLatin1String("comm>"), 5, 0, 0);
XtManageChild(comm);
/* Set up mb2 to activate pop up manual */
handle_mb2_press(dialog_box);
/* Realize the widget hierarchy, creating and mapping windows */
XtRealizeWidget(top_level);
/* Create a pop up manual */
pop_menu = DwtMenu(dialog_box, "Pop Up Menu",
0, 0, DwtMenuPopup, /* x, y, format */
DwtOrientationVertical, /* Orientation */
NULL, NULL); /* no callbacks */
/* Create two entries inside the pop up menu */
pop_entry1 =
DwtPullDownMenuEntry(pop_menu, "pop_entry1", 0, 0,
DwtLatin1String("Selection 1"),
NULL, NULL, NULL);
XtManageChild(pop_entry1);
pop_entry2 =
DwtPullDownMenuEntry(pop_menu, "pop_entry2", 0, 0,
DwtLatin1String("Selection 2"),
NULL, NULL, NULL);
XtManageChild(pop_entry2);
/* Wait for something to happen */
XtMainLoop(); /* Never returns */
}
static XtCallbackProc ButtonActivated(widget, tag, reason)
Widget widget;
Widget tag;
DwtAnyCallbackStruct *reason;
{
Arg arg;
static int changed = False;
if (changed)
exit(1);
else {
XtSetArg(arg, DwtNlabel, DwtLatin1String(goodbyeLabel));
XtSetValues(tag, &arg, 1);
changed = True;
}
}
/* Routine that will be invoked when user press MB2 inside the dialog box */
static void pop_up(widget, event, params, num_params)
Widget widget;
XButtonPressedEvent *event;
char **params;
int num_params;
{
DwtMenuPosition( pop_menu, event);
XtManageChild( pop_menu );
}
/* Set up the calling of pop_up() routine if user presses MB2 */
handle_mb2_press(widget)
Widget widget;
{
Arg arglist[2];
XtTranslations parsed_t_table;
XtAddActions(our_action_table, 1);
parsed_t_table = XtParseTranslationTable(popup_translation);
XtOverrideTranslations(widget, parsed_t_table );
}
|