4
** Copyright (c) 1993-2001 by Hans-Ulrich Kiel & Joerg Czeranski
5
** All rights reserved.
7
** Redistribution and use in source and binary forms, with or without
8
** modification, are permitted provided that the following conditions are
11
** 1. Redistributions of source code must retain the above copyright
12
** notice, this list of conditions and the following disclaimer.
13
** 2. Redistributions in binary form must reproduce the above copyright
14
** notice, this list of conditions and the following disclaimer in the
15
** documentation and/or other materials provided with the distribution.
16
** 3. The name of the authors may not be used to endorse or promote
17
** products derived from this software without specific prior written
19
** 4. The name ``iMaze'' may not be used for products derived from this
20
** software unless a prefix or a suffix is added to the name.
22
** THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
23
** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
24
** WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25
** DISCLAIMED. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT,
26
** INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
27
** (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
28
** SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29
** HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
30
** STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
31
** IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32
** POSSIBILITY OF SUCH DAMAGE.
35
** Datei: motif_fenster.c
38
** Fensterverwaltung auf Basis von Motif
43
#include <X11/Intrinsic.h>
45
#include <Xm/BulletinB.h>
46
#include <Xm/CascadeBG.h>
47
#include <Xm/DialogS.h>
48
#include <Xm/DrawingA.h>
52
#include <Xm/PushBG.h>
53
#include <Xm/RowColumn.h>
54
#include <Xm/Separator.h>
56
#include <Xm/ToggleB.h>
61
#include "ereignisse.h"
70
#include "Xt_appdefs.h"
71
#include "Xt_fenster.h"
73
static char sccsid[] = "@(#)motif_fenster.c 3.26 12/3/01";
76
#define STR_LENGTH 256
78
/* Pfusch! Irix doesn't know XmFONTLIST_DEFAULT_TAG */
79
#define DEFAULT_FONTLIST_TAG "XmFONTLIST_DEFAULT_TAG_STRING"
82
XtAppContext xt_app_context;
83
Arg xt_icon_arglist[1];
86
static Widget status_w;
87
static Widget connect_button_w;
88
Widget xt_disconnect_button_w;
89
Widget xt_pause_button_w, xt_resume_button_w;
90
Widget xt_server_field_w, xt_message_field_w, xt_camera_toggle_w;
92
struct xt_view xt_frontview;
93
struct xt_view xt_rearview;
94
struct xt_view xt_compassview;
95
struct xt_view xt_scoreview;
96
struct xt_view xt_mapview;
98
static int request_result;
101
static void request_handler(Widget widget, XtPointer client_data,
104
request_result = *(int *)client_data;
108
static void view_input(Widget widget, XtPointer client_data,
111
X_event_routine(XtDisplay(widget),
112
((XmAnyCallbackStruct *)call_data)->event);
116
static Widget create_input_box(char *name, Widget parent_w)
118
Widget form_w, label_w, text_w;
120
form_w = XtCreateManagedWidget(name,
121
xmFormWidgetClass, parent_w, NULL, 0);
123
label_w = XtCreateManagedWidget("label",
124
xmLabelWidgetClass, form_w, NULL, 0);
126
text_w = XtCreateManagedWidget("input",
127
xmTextFieldWidgetClass, form_w, NULL, 0);
133
static Widget create_toggle_button(char *name, Widget parent_w)
135
Widget form_w, toggle_w;
137
form_w = XtCreateManagedWidget(name,
138
xmFormWidgetClass, parent_w, NULL, 0);
140
toggle_w = XmCreateToggleButton(form_w, "button", NULL, 0);
141
XtManageChild(toggle_w);
147
/* bis hier lokaler Teil */
148
/***********************************************/
149
/* ab hier globaler Teil */
152
void xt_popup_view(struct xt_view *view)
157
if (!view->is_initialized)
159
view->w = XtCreatePopupShell(view->name,
160
topLevelShellWidgetClass, xt_toplevel, xt_icon_arglist,
161
sizeof xt_icon_arglist / sizeof *xt_icon_arglist);
163
XtAddCallback(view->w, XtNdestroyCallback,
164
xt_view_destroy, (XtPointer)view);
167
XtPopup(view->w, XtGrabNone);
170
if (!view->is_initialized)
174
draw_area = XtCreateManagedWidget("draw",
175
xmDrawingAreaWidgetClass, view->w, NULL, 0);
176
view->window.display = XtDisplay(view->w);
177
view->window.window = XtWindow(draw_area);
180
XtAddCallback(draw_area, XmNexposeCallback,
181
xt_view_redraw, (XtPointer)view);
182
XtAddCallback(draw_area, XmNresizeCallback,
183
xt_view_resize, (XtPointer)view);
184
XtAddCallback(draw_area, XmNinputCallback, view_input, NULL);
186
view->is_initialized = 1;
191
void xt_set_status_label(char *message)
195
XtSetArg(arglist[0], XmNlabelString,
196
XmStringCreate(message, DEFAULT_FONTLIST_TAG));
197
XtSetValues(status_w, arglist, 1);
201
void xt_set_option_sensitivity(int sensitive)
205
XtSetArg(arglist[0], XmNsensitive, sensitive);
206
XtSetValues(connect_button_w, arglist, 1);
208
XtSetArg(arglist[0], XmNeditable, sensitive);
209
XtSetValues(xt_server_field_w, arglist, 1);
210
XtSetValues(xt_message_field_w, arglist, 1);
212
XtSetArg(arglist[0], XmNsensitive, sensitive);
213
XtSetValues(xt_camera_toggle_w, arglist, 1);
217
char *xt_get_string_value(Widget w)
222
XtSetArg(arglist[0], XmNvalue, &str);
223
XtGetValues(w, arglist, 1);
229
Boolean xt_get_toggle_value(Widget w)
231
return XmToggleButtonGetState(w);
235
void xt_fill_main(Widget main_w)
237
Widget form_w, menubar_w, menu_w;
239
char *field_value, *default_server;
242
form_w = XtCreateManagedWidget("form",
243
xmFormWidgetClass, main_w, NULL, 0);
245
menubar_w = XmCreateMenuBar(form_w, "menuBar", arglist, 0);
246
XtManageChild(menubar_w);
248
menu_w = XmCreatePulldownMenu(menubar_w, "menu", NULL, 0);
250
XtAddCallback(XtCreateManagedWidget("exit",
251
xmPushButtonGadgetClass, menu_w, NULL, 0),
252
XmNactivateCallback, xt_exit_handler, NULL);
254
XtSetArg(arglist[0], XmNsubMenuId, menu_w);
255
XtCreateManagedWidget("fileMenu",
256
xmCascadeButtonGadgetClass, menubar_w, arglist, 1);
258
menu_w = XmCreatePulldownMenu(menubar_w, "menu", NULL, 0);
260
XtAddCallback(XtCreateManagedWidget("frontView",
261
xmPushButtonGadgetClass, menu_w, NULL, 0),
262
XmNactivateCallback, xt_view_toggle, (XtPointer)&xt_frontview);
264
XtAddCallback(XtCreateManagedWidget("rearView",
265
xmPushButtonGadgetClass, menu_w, NULL, 0),
266
XmNactivateCallback, xt_view_toggle, (XtPointer)&xt_rearview);
268
XtAddCallback(XtCreateManagedWidget("map",
269
xmPushButtonGadgetClass, menu_w, NULL, 0),
270
XmNactivateCallback, xt_view_toggle, (XtPointer)&xt_mapview);
272
XtAddCallback(XtCreateManagedWidget("compass",
273
xmPushButtonGadgetClass, menu_w, NULL, 0),
274
XmNactivateCallback, xt_view_toggle,
275
(XtPointer)&xt_compassview);
277
XtAddCallback(XtCreateManagedWidget("score",
278
xmPushButtonGadgetClass, menu_w, NULL, 0),
279
XmNactivateCallback, xt_view_toggle, (XtPointer)&xt_scoreview);
281
XtSetArg(arglist[0], XmNsubMenuId, menu_w);
282
XtCreateManagedWidget("toggleMenu",
283
xmCascadeButtonGadgetClass, menubar_w, arglist, 1);
285
menu_w = XmCreatePulldownMenu(menubar_w, "menu", NULL, 0);
287
XtAddCallback(connect_button_w =
288
XtCreateManagedWidget("connect",
289
xmPushButtonGadgetClass, menu_w, NULL, 0),
290
XmNactivateCallback, xt_connect_handler, NULL);
292
XtSetArg(arglist[0], XtNsensitive, False);
293
XtAddCallback(xt_disconnect_button_w =
294
XtCreateManagedWidget("disconnect",
295
xmPushButtonGadgetClass, menu_w, arglist, 1),
296
XmNactivateCallback, xt_disconnect_handler, NULL);
298
XtSetArg(arglist[0], XmNsubMenuId, menu_w);
299
XtCreateManagedWidget("serverMenu",
300
xmCascadeButtonGadgetClass, menubar_w, arglist, 1);
302
menu_w = XmCreatePulldownMenu(menubar_w, "menu", NULL, 0);
304
XtSetArg(arglist[0], XtNsensitive, False);
305
XtAddCallback(xt_pause_button_w =
306
XtCreateManagedWidget("pause",
307
xmPushButtonGadgetClass, menu_w, arglist, 1),
308
XmNactivateCallback, xt_pause_handler, NULL);
310
XtSetArg(arglist[0], XtNsensitive, False);
311
XtAddCallback(xt_resume_button_w =
312
XtCreateManagedWidget("resume",
313
xmPushButtonGadgetClass, menu_w, arglist, 1),
314
XmNactivateCallback, xt_resume_handler, NULL);
316
XtSetArg(arglist[0], XmNsubMenuId, menu_w);
317
XtCreateManagedWidget("gameMenu",
318
xmCascadeButtonGadgetClass, menubar_w, arglist, 1);
320
xt_server_field_w = create_input_box("server", form_w);
321
xt_message_field_w = create_input_box("message", form_w);
322
xt_camera_toggle_w = create_toggle_button("camera", form_w);
324
XtSetArg(arglist[0], XmNmaxLength, STR_LENGTH - 1);
325
XtSetValues(xt_server_field_w, arglist, 1);
326
XtSetValues(xt_message_field_w, arglist, 1);
328
XtSetArg(arglist[0], XmNvalue, &field_value);
329
XtGetValues(xt_server_field_w, arglist, 1);
331
default_server = get_server_name(&override);
332
if (!field_value[0] || override)
334
XtSetArg(arglist[0], XmNvalue, default_server);
335
XtSetValues(xt_server_field_w, arglist, 1);
338
XtSetArg(arglist[0], XmNvalue, &field_value);
339
XtGetValues(xt_message_field_w, arglist, 1);
345
if ((message = benutzer_name()) == NULL)
347
speicher_belegen((void **)&message, 10);
348
strcpy(message, "Gotcha!");
352
speicher_vergroessern((void **)&message,
353
strlen(message) + 20);
354
strcat(message, " shouts: Gotcha!");
357
XtSetArg(arglist[0], XmNvalue, message);
358
XtSetValues(xt_message_field_w, arglist, 1);
360
speicher_freigeben((void **)&message);
363
status_w = XtCreateManagedWidget("status",
364
xmLabelWidgetClass, form_w, NULL, 0);
365
xt_set_status_label("Not connected");
369
int xt_request_window(char **message, char *label1, char *label2,
370
int two_buttons, char *widget_name)
372
Widget w, q_w, form_w, sep_w, ok_w, cancel_w;
375
int result_ok = 1, result_cancel = 2;
377
w = XmCreateDialogShell(xt_toplevel, "dialog", xt_icon_arglist,
378
sizeof xt_icon_arglist / sizeof *xt_icon_arglist);
380
q_w = XtCreateWidget(widget_name, xmBulletinBoardWidgetClass,
383
form_w = XtCreateManagedWidget("form", xmFormWidgetClass,
387
while (*message != NULL)
389
XtSetArg(arglist[0], XmNlabelString,
390
XmStringCreate(*message, DEFAULT_FONTLIST_TAG));
391
XtSetArg(arglist[1], XmNtopAttachment, XmATTACH_WIDGET);
392
XtSetArg(arglist[2], XmNtopWidget, line_w);
394
line_w = XtCreateManagedWidget(line_w == NULL ?
395
"text1" : "text", xmLabelWidgetClass,
401
XtSetArg(arglist[0], XmNtopAttachment, XmATTACH_WIDGET);
402
XtSetArg(arglist[1], XmNtopWidget, line_w);
403
sep_w = XtCreateManagedWidget("separator", xmSeparatorWidgetClass,
406
ok_w = XtCreateManagedWidget("default", xmPushButtonWidgetClass,
410
XtSetArg(arglist[0], XmNlabelString,
411
XmStringCreate(label1, DEFAULT_FONTLIST_TAG));
412
XtSetValues(ok_w, arglist, 1);
417
cancel_w = XtCreateManagedWidget("cancel",
418
xmPushButtonWidgetClass, form_w, NULL, 0);
421
XtSetArg(arglist[0], XmNlabelString,
422
XmStringCreate(label2, DEFAULT_FONTLIST_TAG));
423
XtSetValues(cancel_w, arglist, 1);
426
XtCreateManagedWidget("space", xmPrimitiveWidgetClass,
430
XtSetArg(arglist[0], XmNdefaultButton, ok_w);
431
XtSetValues(q_w, arglist, 1);
435
XtSetArg(arglist[0], XmNcancelButton, cancel_w);
436
XtSetValues(q_w, arglist, 1);
444
Dimension form_width, button_width;
446
XtSetArg(arglist[0], XmNwidth, &form_width);
447
XtGetValues(form_w, arglist, 1);
448
XtSetArg(arglist[0], XmNwidth, &button_width);
449
XtGetValues(ok_w, arglist, 1);
451
XtSetArg(arglist[0], XmNleftOffset,
452
((int)form_width - (int)button_width) / 2);
453
XtSetValues(ok_w, arglist, 1);
458
XtAddCallback(ok_w, XmNactivateCallback,
459
request_handler, (XtPointer)&result_ok);
462
XtAddCallback(cancel_w, XmNactivateCallback,
463
request_handler, (XtPointer)&result_cancel);
465
XtAddCallback(w, XtNdestroyCallback, request_handler,
466
two_buttons ? (XtPointer)&result_cancel :
467
(XtPointer)&result_ok);
470
while (!request_result)
474
XtAppNextEvent(xt_app_context, &ev);
475
XtDispatchEvent(&ev);
478
XtRemoveCallback(w, XtNdestroyCallback, request_handler,
479
two_buttons ? (XtPointer)&result_cancel :
480
(XtPointer)&result_ok);
482
return request_result;