~ubuntu-branches/ubuntu/vivid/imaze/vivid

« back to all changes in this revision

Viewing changes to source/motif_fenster.c

  • Committer: Bazaar Package Importer
  • Author(s): Hans Freitag
  • Date: 2002-11-28 13:24:12 UTC
  • Revision ID: james.westby@ubuntu.com-20021128132412-lw82xl9oq1j36g8b
Tags: upstream-1.4
ImportĀ upstreamĀ versionĀ 1.4

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
** - - -  iMaze  - - -
 
3
**
 
4
** Copyright (c) 1993-2001 by Hans-Ulrich Kiel & Joerg Czeranski
 
5
** All rights reserved.
 
6
**
 
7
** Redistribution and use in source and binary forms, with or without
 
8
** modification, are permitted provided that the following conditions are
 
9
** met:
 
10
**
 
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
 
18
**    permission.
 
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.
 
21
**
 
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.
 
33
**
 
34
**
 
35
** Datei: motif_fenster.c
 
36
**
 
37
** Kommentar:
 
38
**  Fensterverwaltung auf Basis von Motif
 
39
*/
 
40
 
 
41
 
 
42
#include <stdio.h>
 
43
#include <X11/Intrinsic.h>
 
44
#include <Xm/Xm.h>
 
45
#include <Xm/BulletinB.h>
 
46
#include <Xm/CascadeBG.h>
 
47
#include <Xm/DialogS.h>
 
48
#include <Xm/DrawingA.h>
 
49
#include <Xm/Form.h>
 
50
#include <Xm/Label.h>
 
51
#include <Xm/PushB.h>
 
52
#include <Xm/PushBG.h>
 
53
#include <Xm/RowColumn.h>
 
54
#include <Xm/Separator.h>
 
55
#include <Xm/TextF.h>
 
56
#include <Xm/ToggleB.h>
 
57
 
 
58
#include "argv.h"
 
59
#include "grafik.h"
 
60
#include "signale.h"
 
61
#include "ereignisse.h"
 
62
#include "einaus.h"
 
63
#include "client.h"
 
64
#include "speicher.h"
 
65
#include "system.h"
 
66
#include "X_grafik.h"
 
67
#include "X_tasten.h"
 
68
#include "X_daten.h"
 
69
#include "X_icon.h"
 
70
#include "Xt_appdefs.h"
 
71
#include "Xt_fenster.h"
 
72
 
 
73
static char sccsid[] = "@(#)motif_fenster.c     3.26 12/3/01";
 
74
 
 
75
 
 
76
#define STR_LENGTH 256
 
77
 
 
78
/* Pfusch! Irix doesn't know XmFONTLIST_DEFAULT_TAG */
 
79
#define DEFAULT_FONTLIST_TAG "XmFONTLIST_DEFAULT_TAG_STRING"
 
80
 
 
81
 
 
82
XtAppContext xt_app_context;
 
83
Arg xt_icon_arglist[1];
 
84
 
 
85
Widget xt_toplevel;
 
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;
 
91
 
 
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;
 
97
 
 
98
static int request_result;
 
99
 
 
100
 
 
101
static void request_handler(Widget widget, XtPointer client_data,
 
102
        XtPointer call_data)
 
103
{
 
104
        request_result = *(int *)client_data;
 
105
}
 
106
 
 
107
 
 
108
static void view_input(Widget widget, XtPointer client_data,
 
109
        XtPointer call_data)
 
110
{
 
111
        X_event_routine(XtDisplay(widget),
 
112
                ((XmAnyCallbackStruct *)call_data)->event);
 
113
}
 
114
 
 
115
 
 
116
static Widget create_input_box(char *name, Widget parent_w)
 
117
{
 
118
        Widget form_w, label_w, text_w;
 
119
 
 
120
        form_w = XtCreateManagedWidget(name,
 
121
                xmFormWidgetClass, parent_w, NULL, 0);
 
122
 
 
123
        label_w = XtCreateManagedWidget("label",
 
124
                xmLabelWidgetClass, form_w, NULL, 0);
 
125
 
 
126
        text_w = XtCreateManagedWidget("input",
 
127
                xmTextFieldWidgetClass, form_w, NULL, 0);
 
128
 
 
129
        return text_w;
 
130
}
 
131
 
 
132
 
 
133
static Widget create_toggle_button(char *name, Widget parent_w)
 
134
{
 
135
        Widget form_w, toggle_w;
 
136
 
 
137
        form_w = XtCreateManagedWidget(name,
 
138
                xmFormWidgetClass, parent_w, NULL, 0);
 
139
 
 
140
        toggle_w = XmCreateToggleButton(form_w, "button", NULL, 0);
 
141
        XtManageChild(toggle_w);
 
142
 
 
143
        return toggle_w;
 
144
}
 
145
 
 
146
 
 
147
/* bis hier lokaler Teil                       */
 
148
/***********************************************/
 
149
/* ab hier globaler Teil                       */
 
150
 
 
151
 
 
152
void xt_popup_view(struct xt_view *view)
 
153
{
 
154
        if (view->is_open)
 
155
                return;
 
156
 
 
157
        if (!view->is_initialized)
 
158
        {
 
159
                view->w = XtCreatePopupShell(view->name,
 
160
                        topLevelShellWidgetClass, xt_toplevel, xt_icon_arglist,
 
161
                        sizeof xt_icon_arglist / sizeof *xt_icon_arglist);
 
162
 
 
163
                XtAddCallback(view->w, XtNdestroyCallback,
 
164
                        xt_view_destroy, (XtPointer)view);
 
165
        }
 
166
 
 
167
        XtPopup(view->w, XtGrabNone);
 
168
        view->is_open = 1;
 
169
 
 
170
        if (!view->is_initialized)
 
171
        {
 
172
                Widget draw_area;
 
173
 
 
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);
 
178
                xt_view_init(view);
 
179
 
 
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);
 
185
 
 
186
                view->is_initialized = 1;
 
187
        }
 
188
}
 
189
 
 
190
 
 
191
void xt_set_status_label(char *message)
 
192
{
 
193
        Arg arglist[1];
 
194
 
 
195
        XtSetArg(arglist[0], XmNlabelString,
 
196
                XmStringCreate(message, DEFAULT_FONTLIST_TAG));
 
197
        XtSetValues(status_w, arglist, 1);
 
198
}
 
199
 
 
200
 
 
201
void xt_set_option_sensitivity(int sensitive)
 
202
{
 
203
        Arg arglist[1];
 
204
 
 
205
        XtSetArg(arglist[0], XmNsensitive, sensitive);
 
206
        XtSetValues(connect_button_w, arglist, 1);
 
207
 
 
208
        XtSetArg(arglist[0], XmNeditable, sensitive);
 
209
        XtSetValues(xt_server_field_w, arglist, 1);
 
210
        XtSetValues(xt_message_field_w, arglist, 1);
 
211
 
 
212
        XtSetArg(arglist[0], XmNsensitive, sensitive);
 
213
        XtSetValues(xt_camera_toggle_w, arglist, 1);
 
214
}
 
215
 
 
216
 
 
217
char *xt_get_string_value(Widget w)
 
218
{
 
219
        Arg arglist[1];
 
220
        String str;
 
221
 
 
222
        XtSetArg(arglist[0], XmNvalue, &str);
 
223
        XtGetValues(w, arglist, 1);
 
224
 
 
225
        return str;
 
226
}
 
227
 
 
228
 
 
229
Boolean xt_get_toggle_value(Widget w)
 
230
{
 
231
        return XmToggleButtonGetState(w);
 
232
}
 
233
 
 
234
 
 
235
void xt_fill_main(Widget main_w)
 
236
{
 
237
        Widget form_w, menubar_w, menu_w;
 
238
        Arg arglist[2];
 
239
        char *field_value, *default_server;
 
240
        int override;
 
241
 
 
242
        form_w = XtCreateManagedWidget("form",
 
243
                xmFormWidgetClass, main_w, NULL, 0);
 
244
 
 
245
        menubar_w = XmCreateMenuBar(form_w, "menuBar", arglist, 0);
 
246
        XtManageChild(menubar_w);
 
247
 
 
248
        menu_w = XmCreatePulldownMenu(menubar_w, "menu", NULL, 0);
 
249
 
 
250
        XtAddCallback(XtCreateManagedWidget("exit",
 
251
                xmPushButtonGadgetClass, menu_w, NULL, 0),
 
252
                XmNactivateCallback, xt_exit_handler, NULL);
 
253
 
 
254
        XtSetArg(arglist[0], XmNsubMenuId, menu_w);
 
255
        XtCreateManagedWidget("fileMenu",
 
256
                xmCascadeButtonGadgetClass, menubar_w, arglist, 1);
 
257
 
 
258
        menu_w = XmCreatePulldownMenu(menubar_w, "menu", NULL, 0);
 
259
 
 
260
        XtAddCallback(XtCreateManagedWidget("frontView",
 
261
                xmPushButtonGadgetClass, menu_w, NULL, 0),
 
262
                XmNactivateCallback, xt_view_toggle, (XtPointer)&xt_frontview);
 
263
 
 
264
        XtAddCallback(XtCreateManagedWidget("rearView",
 
265
                xmPushButtonGadgetClass, menu_w, NULL, 0),
 
266
                XmNactivateCallback, xt_view_toggle, (XtPointer)&xt_rearview);
 
267
 
 
268
        XtAddCallback(XtCreateManagedWidget("map",
 
269
                xmPushButtonGadgetClass, menu_w, NULL, 0),
 
270
                XmNactivateCallback, xt_view_toggle, (XtPointer)&xt_mapview);
 
271
 
 
272
        XtAddCallback(XtCreateManagedWidget("compass",
 
273
                xmPushButtonGadgetClass, menu_w, NULL, 0),
 
274
                XmNactivateCallback, xt_view_toggle,
 
275
                (XtPointer)&xt_compassview);
 
276
 
 
277
        XtAddCallback(XtCreateManagedWidget("score",
 
278
                xmPushButtonGadgetClass, menu_w, NULL, 0),
 
279
                XmNactivateCallback, xt_view_toggle, (XtPointer)&xt_scoreview);
 
280
 
 
281
        XtSetArg(arglist[0], XmNsubMenuId, menu_w);
 
282
        XtCreateManagedWidget("toggleMenu",
 
283
                xmCascadeButtonGadgetClass, menubar_w, arglist, 1);
 
284
 
 
285
        menu_w = XmCreatePulldownMenu(menubar_w, "menu", NULL, 0);
 
286
 
 
287
        XtAddCallback(connect_button_w =
 
288
                XtCreateManagedWidget("connect",
 
289
                        xmPushButtonGadgetClass, menu_w, NULL, 0),
 
290
                XmNactivateCallback, xt_connect_handler, NULL);
 
291
 
 
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);
 
297
 
 
298
        XtSetArg(arglist[0], XmNsubMenuId, menu_w);
 
299
        XtCreateManagedWidget("serverMenu",
 
300
                xmCascadeButtonGadgetClass, menubar_w, arglist, 1);
 
301
 
 
302
        menu_w = XmCreatePulldownMenu(menubar_w, "menu", NULL, 0);
 
303
 
 
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);
 
309
 
 
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);
 
315
 
 
316
        XtSetArg(arglist[0], XmNsubMenuId, menu_w);
 
317
        XtCreateManagedWidget("gameMenu",
 
318
                xmCascadeButtonGadgetClass, menubar_w, arglist, 1);
 
319
 
 
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);
 
323
 
 
324
        XtSetArg(arglist[0], XmNmaxLength, STR_LENGTH - 1);
 
325
        XtSetValues(xt_server_field_w, arglist, 1);
 
326
        XtSetValues(xt_message_field_w, arglist, 1);
 
327
 
 
328
        XtSetArg(arglist[0], XmNvalue, &field_value);
 
329
        XtGetValues(xt_server_field_w, arglist, 1);
 
330
 
 
331
        default_server = get_server_name(&override);
 
332
        if (!field_value[0] || override)
 
333
        {
 
334
                XtSetArg(arglist[0], XmNvalue, default_server);
 
335
                XtSetValues(xt_server_field_w, arglist, 1);
 
336
        }
 
337
 
 
338
        XtSetArg(arglist[0], XmNvalue, &field_value);
 
339
        XtGetValues(xt_message_field_w, arglist, 1);
 
340
 
 
341
        if (!field_value[0])
 
342
        {
 
343
                char *message;
 
344
 
 
345
                if ((message = benutzer_name()) == NULL)
 
346
                {
 
347
                        speicher_belegen((void **)&message, 10);
 
348
                        strcpy(message, "Gotcha!");
 
349
                }
 
350
                else
 
351
                {
 
352
                        speicher_vergroessern((void **)&message,
 
353
                                strlen(message) + 20);
 
354
                        strcat(message, " shouts: Gotcha!");
 
355
                }
 
356
 
 
357
                XtSetArg(arglist[0], XmNvalue, message);
 
358
                XtSetValues(xt_message_field_w, arglist, 1);
 
359
 
 
360
                speicher_freigeben((void **)&message);
 
361
        }
 
362
 
 
363
        status_w = XtCreateManagedWidget("status",
 
364
                xmLabelWidgetClass, form_w, NULL, 0);
 
365
        xt_set_status_label("Not connected");
 
366
}
 
367
 
 
368
 
 
369
int xt_request_window(char **message, char *label1, char *label2,
 
370
        int two_buttons, char *widget_name)
 
371
{
 
372
        Widget w, q_w, form_w, sep_w, ok_w, cancel_w;
 
373
        Widget line_w;
 
374
        Arg arglist[3];
 
375
        int result_ok = 1, result_cancel = 2;
 
376
 
 
377
        w = XmCreateDialogShell(xt_toplevel, "dialog", xt_icon_arglist,
 
378
                sizeof xt_icon_arglist / sizeof *xt_icon_arglist);
 
379
 
 
380
        q_w = XtCreateWidget(widget_name, xmBulletinBoardWidgetClass,
 
381
                w, NULL, 0);
 
382
 
 
383
        form_w = XtCreateManagedWidget("form", xmFormWidgetClass,
 
384
                q_w, NULL, 0);
 
385
 
 
386
        line_w = NULL;
 
387
        while (*message != NULL)
 
388
        {
 
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);
 
393
 
 
394
                line_w = XtCreateManagedWidget(line_w == NULL ?
 
395
                        "text1" : "text", xmLabelWidgetClass,
 
396
                        form_w, arglist, 3);
 
397
 
 
398
                message++;
 
399
        }
 
400
 
 
401
        XtSetArg(arglist[0], XmNtopAttachment, XmATTACH_WIDGET);
 
402
        XtSetArg(arglist[1], XmNtopWidget, line_w);
 
403
        sep_w = XtCreateManagedWidget("separator", xmSeparatorWidgetClass,
 
404
                form_w, arglist, 2);
 
405
 
 
406
        ok_w = XtCreateManagedWidget("default", xmPushButtonWidgetClass,
 
407
                form_w, NULL, 0);
 
408
        if (label1 != NULL)
 
409
        {
 
410
                XtSetArg(arglist[0], XmNlabelString,
 
411
                        XmStringCreate(label1, DEFAULT_FONTLIST_TAG));
 
412
                XtSetValues(ok_w, arglist, 1);
 
413
        }
 
414
 
 
415
        if (two_buttons)
 
416
        {
 
417
                cancel_w = XtCreateManagedWidget("cancel",
 
418
                        xmPushButtonWidgetClass, form_w, NULL, 0);
 
419
                if (label2 != NULL)
 
420
                {
 
421
                        XtSetArg(arglist[0], XmNlabelString,
 
422
                                XmStringCreate(label2, DEFAULT_FONTLIST_TAG));
 
423
                        XtSetValues(cancel_w, arglist, 1);
 
424
                }
 
425
 
 
426
                XtCreateManagedWidget("space", xmPrimitiveWidgetClass,
 
427
                        form_w, NULL, 0);
 
428
        }
 
429
 
 
430
        XtSetArg(arglist[0], XmNdefaultButton, ok_w);
 
431
        XtSetValues(q_w, arglist, 1);
 
432
 
 
433
        if (two_buttons)
 
434
        {
 
435
                XtSetArg(arglist[0], XmNcancelButton, cancel_w);
 
436
                XtSetValues(q_w, arglist, 1);
 
437
        }
 
438
 
 
439
        XtManageChild(q_w);
 
440
        XtRealizeWidget(w);
 
441
 
 
442
        if (!two_buttons)
 
443
        {
 
444
                Dimension form_width, button_width;
 
445
 
 
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);
 
450
 
 
451
                XtSetArg(arglist[0], XmNleftOffset,
 
452
                        ((int)form_width - (int)button_width) / 2);
 
453
                XtSetValues(ok_w, arglist, 1);
 
454
        }
 
455
 
 
456
        XtManageChild(w);
 
457
 
 
458
        XtAddCallback(ok_w, XmNactivateCallback,
 
459
                request_handler, (XtPointer)&result_ok);
 
460
 
 
461
        if (two_buttons)
 
462
                XtAddCallback(cancel_w, XmNactivateCallback,
 
463
                        request_handler, (XtPointer)&result_cancel);
 
464
 
 
465
        XtAddCallback(w, XtNdestroyCallback, request_handler,
 
466
                two_buttons ? (XtPointer)&result_cancel :
 
467
                        (XtPointer)&result_ok);
 
468
 
 
469
        request_result = 0;
 
470
        while (!request_result)
 
471
        {
 
472
                XEvent ev;
 
473
 
 
474
                XtAppNextEvent(xt_app_context, &ev);
 
475
                XtDispatchEvent(&ev);
 
476
        }
 
477
 
 
478
        XtRemoveCallback(w, XtNdestroyCallback, request_handler,
 
479
                two_buttons ? (XtPointer)&result_cancel :
 
480
                        (XtPointer)&result_ok);
 
481
        XtDestroyWidget(w);
 
482
        return request_result;
 
483
}