-
Notifications
You must be signed in to change notification settings - Fork 0
/
testdialog.c
290 lines (252 loc) · 8.24 KB
/
testdialog.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
/**** testdialog.c ****/ /**** formatted with 4-column tabs ****/
#include <stdio.h>
#include "dialog.h"
#include <Xm/RowColumn.h>
#include <Xm/Protocols.h>
/*
Functions:
*/
static void Quit(), Dismiss(), TestDialog();
static void DialogSelection1(), DialogSelection2(), DialogSelection3();
static void DialogCancel();
static void handle_close_buttons();
/*
Private data:
*/
static Widget topLevel, buttonBox, buttonTest1, buttonTest2,
buttonTest3, buttonQuit;
static Dialog dialog1, dialog2, dialog3;
/*
main() creates a top-level window with four buttons, three
of which activate top-level or transient dialog boxes. There are
several possible combinations of modal/nonmodal, stay-up/no-stay-up,
and string-input/no-string-input dialog boxes; three combinations
are tested here.
*/
void main(argc, argv)
int argc;
char *argv[];
{
Arg args[10];
int i;
static int one = 1, two = 2, three = 3;
static DialogButtonItem items1[] = {
{"Button 1", DialogSelection1, (XtPointer) &one},
{"Button 2", DialogSelection1, (XtPointer) &two},
{"Button 3", DialogSelection1, (XtPointer) &three},
{NULL, NULL, NULL},
/* NULL ** or just provide a NULL tuple ** */
};
static DialogButtonItem items2[] = {
{"Dismiss", Dismiss, (XtPointer) "one"},
{"Button 2", DialogSelection2, (XtPointer) "two"},
{"Button 3", DialogSelection2, (XtPointer) "three"},
{"Button 4", DialogSelection2, (XtPointer) "four"},
{NULL, NULL, NULL},
};
static DialogButtonItem items3[] = {
{" OK ", DialogSelection3, (XtPointer) "one"},
{"Cancel", DialogSelection3, (XtPointer) "two"},
{NULL, NULL, NULL},
};
XtAppContext app;
topLevel = XtAppInitialize(&app, "TestDialog",
(XrmOptionDescList) NULL, 0,
&argc, argv, (String *) NULL, (ArgList) NULL, 0);
i = 0;
XtSetArg(args[i], XmNorientation, (XtArgVal) XmHORIZONTAL); i++;
XtSetArg(args[i], XmNentryAlignment,
(XtArgVal) XmALIGNMENT_CENTER); i++;
buttonBox = XtCreateManagedWidget("buttonBox",
xmRowColumnWidgetClass, topLevel, args, i);
i = 0;
XtSetArg(args[i], XmNlabelString,
XmStringCreateLtoR("Quit",
XmSTRING_DEFAULT_CHARSET)); i++;
buttonQuit = XtCreateManagedWidget("buttonQuit",
xmPushButtonWidgetClass, buttonBox, args, i);
XtAddCallback(buttonQuit, XmNactivateCallback, Quit, NULL);
i = 0;
XtSetArg(args[i], XmNlabelString,
XmStringCreateLtoR("Test Dialog #1",
XmSTRING_DEFAULT_CHARSET)); i++;
buttonTest1 = XtCreateManagedWidget("buttonTest1",
xmPushButtonWidgetClass, buttonBox, args, i);
XtAddCallback(buttonTest1, XmNactivateCallback, TestDialog, NULL);
i = 0;
XtSetArg(args[i], XmNlabelString,
XmStringCreateLtoR("Test Dialog #2",
XmSTRING_DEFAULT_CHARSET)); i++;
buttonTest2 = XtCreateManagedWidget("buttonTest2",
xmPushButtonWidgetClass, buttonBox, args, i);
XtAddCallback(buttonTest2, XmNactivateCallback, TestDialog, NULL);
i = 0;
XtSetArg(args[i], XmNlabelString,
XmStringCreateLtoR("Test Dialog #3",
XmSTRING_DEFAULT_CHARSET)); i++;
buttonTest3 = XtCreateManagedWidget("buttonTest3",
xmPushButtonWidgetClass, buttonBox, args, i);
XtAddCallback(buttonTest3, XmNactivateCallback, TestDialog, NULL);
/***********************************************************************
dialog_create(app, parent, instance_name, items, num_columns,
title, prompt, char_set, dialog_position, modal_dialog,
max_win_mgr, string_input, auto_popdown, default_button);
***********************************************************************/
dialog1 = dialog_create(app, topLevel, "dialog1", items1, 30,
"Dialog Box #1", "This is only a test...",
XmSTRING_DEFAULT_CHARSET, dialog_CENTER, TRUE, FALSE, FALSE, TRUE, 0);
dialog2 = dialog_create(app, topLevel, "dialog2", items2, 50,
"Dialog Box #2", "This is only a test...",
XmSTRING_DEFAULT_CHARSET, dialog_DEFAULT, FALSE, TRUE, TRUE, FALSE,
dialog_NO_DEFAULT_BTN);
dialog_forget_text(dialog2);
dialog3 = dialog_create(app, topLevel, "dialog3", items3, 0,
"Dialog Box #3", "This is only a test...",
XmSTRING_DEFAULT_CHARSET, dialog_POINTER, FALSE, FALSE, FALSE, TRUE, 0);
XtRealizeWidget(topLevel);
dialog_realize(dialog1);
dialog_realize(dialog2);
dialog_realize(dialog3);
handle_close_buttons(topLevel);
XtAppMainLoop(app);
} /* main */
/*
Quit() terminates the application.
*/
/*ARGSUSED*/
static void Quit(w, client_data, call_data)
Widget w;
XtPointer client_data;
XtPointer call_data;
{
int *int_data = (int *) dialog_get_most_recent_button_response(dialog1);
char *char_data1 = (char *) dialog_get_most_recent_button_response(dialog2);
char *char_data2 = (char *) dialog_get_most_recent_button_response(dialog3);
if (int_data)
printf(
"The most recently selected button's value for dialog #1 is: %d\n",
*int_data);
else
printf(
"The most recently selected button's value for dialog #1 is: %s\n",
"(null)");
printf("The most recently selected button's value for dialog #2 is: %s\n",
char_data1 ? char_data1 : "(null)");
printf("The most recently selected button's value for dialog #3 is: %s\n",
char_data2 ? char_data2 : "(null)");
printf("Normal application termination...\n");
dialog_destroy(dialog1);
dialog_destroy(dialog2);
dialog_destroy(dialog3);
exit(0);
} /* Quit */
/*
Dismiss() terminates the application.
*/
/*ARGSUSED*/
static void Dismiss(w, client_data, call_data)
Widget w;
XtPointer client_data;
XtPointer call_data;
{
dialog_deactivate(dialog2);
} /* Dismiss */
/*
TestDialog() activates the dialog box.
*/
/*ARGSUSED*/
static void TestDialog(w, client_data, call_data)
Widget w;
XtPointer client_data;
XtPointer call_data;
{
if (w == buttonTest1) {
int n;
n = dialog_modal_prompt(dialog1, "Please make a selection:");
printf("Returning from modal dialog; you selected button: %d\n", n);
}
else if (w == buttonTest2)
dialog_activate(dialog2);
else
dialog_activate(dialog3);
} /* TestDialog */
/*
DialogSelection1() performs an application-specific action
in response to a dialog box selection by the user.
*/
/*ARGSUSED*/
static void DialogSelection1(w, client_data, call_data)
Widget w;
int *client_data;
XtPointer call_data;
{
printf("You selected the button with value: %d\n", *client_data);
} /* DialogSelection1 */
/*
DialogSelection2() performs an application-specific action
in response to a dialog box selection by the user.
*/
/*ARGSUSED*/
static void DialogSelection2(w, client_data, call_data)
Widget w;
XtPointer client_data;
XtPointer call_data;
{
printf("You selected the button with value: %s\n",
(char *) client_data);
printf("The dialog box's current string response data is: %s\n",
!dialog_get_text(dialog2) ? "(null)" : dialog_get_text(dialog2));
} /* DialogSelection2 */
/*
DialogSelection3() performs an application-specific action
in response to a dialog box selection by the user.
*/
/*ARGSUSED*/
static void DialogSelection3(w, client_data, call_data)
Widget w;
XtPointer client_data;
XtPointer call_data;
{
printf("You selected the button with value: %s\n", (char *) client_data);
} /* DialogSelection2 */
/*
DialogCancel() performs an application-specific action
in response to a window manager "Close" request. This
test application simply interprets the "Close" operation
as being equivalent to pressing the leftmost (0th)
mouse button.
*/
/*ARGSUSED*/
static void DialogCancel(w, client_data, call_data)
Widget w;
XtPointer client_data;
XtPointer call_data;
{
dialog_cancel((Dialog) client_data, 0);
} /* DialogCancel */
/*
handle_close_buttons() accommodates the "Close" buttons. The actions
should be hardcoded -- the user should not be allowed to override the
XmUNMAP default for pop-ups.
*/
static void handle_close_buttons(w)
Widget w;
{
Atom WM_DELETE_WINDOW;
Arg arg;
WM_DELETE_WINDOW = XmInternAtom(XtDisplay(w),
"WM_DELETE_WINDOW", False);
XtSetArg(arg, XmNdeleteResponse, (XtArgVal) XmDO_NOTHING);
XtSetValues(w, &arg, 1);
XtSetValues(dialog_dialogShell(dialog1), &arg, 1);
XtSetValues(dialog_dialogShell(dialog2), &arg, 1);
XtSetValues(dialog_dialogShell(dialog3), &arg, 1);
XmAddWMProtocolCallback(w, WM_DELETE_WINDOW,
Quit, (caddr_t) w);
XmAddWMProtocolCallback(dialog_dialogShell(dialog1),
WM_DELETE_WINDOW, DialogCancel, (caddr_t) dialog1);
XmAddWMProtocolCallback(dialog_dialogShell(dialog2),
WM_DELETE_WINDOW, DialogCancel, (caddr_t) dialog2);
XmAddWMProtocolCallback(dialog_dialogShell(dialog3),
WM_DELETE_WINDOW, DialogCancel, (caddr_t) dialog3);
} /* handle_close_buttons */