Subversion Repositories eduke32

Rev

Rev 197 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
194 terminx 1
/* NOTE: Glade will generate code for a dialogue box which you should
2
 * then patch into this file whenever you make a change to the Glade
3
 * template.
4
 */
5
 
6
#include <sys/types.h>
7
#include <sys/stat.h>
8
#include <unistd.h>
9
#include <string.h>
10
#include <stdio.h>
11
#include <stdlib.h>
12
 
13
#include <gdk-pixbuf/gdk-pixdata.h>
14
#include <gdk-pixbuf/gdk-pixbuf.h>
15
#include <gdk/gdkkeysyms.h>
16
#include <gtk/gtk.h>
17
 
18
#include "duke3d.h"
19
#include "build.h"
20
#include "compat.h"
21
#include "baselayer.h"
22
 
23
#define TAB_CONFIG 0
24
#define TAB_MESSAGES 1
25
 
26
static struct {
27
    int fullscreen;
28
    int xdim3d, ydim3d, bpp3d;
29
    int forcesetup;
30
    int usemouse, usejoy;
31
} settings;
32
 
33
extern int gtkenabled;
34
 
35
static GtkWidget *startwin = NULL;
36
static int retval = -1, mode = 0;
37
 
38
// -- SUPPORT FUNCTIONS -------------------------------------------------------
39
 
40
#define GLADE_HOOKUP_OBJECT(component,widget,name) \
41
  g_object_set_data_full (G_OBJECT (component), name, \
42
    gtk_widget_ref (widget), (GDestroyNotify) gtk_widget_unref)
43
 
44
#define GLADE_HOOKUP_OBJECT_NO_REF(component,widget,name) \
45
  g_object_set_data (G_OBJECT (component), name, widget)
46
 
47
#define lookup_widget(x,w) \
48
        (GtkWidget*) g_object_get_data(G_OBJECT(x), w)
49
 
50
static GdkPixbuf *load_banner(void)
51
{
52
    extern const GdkPixdata startbanner_pixdata;
53
    return gdk_pixbuf_from_pixdata(&startbanner_pixdata, FALSE, NULL);
54
}
55
 
56
static void SetPage(int n)
57
{
58
    if (!gtkenabled || !startwin) return;
59
    gtk_notebook_set_current_page(GTK_NOTEBOOK(lookup_widget(startwin,"tabs")), n);
60
}
61
 
62
static void EnableConfig(int n)
63
{
64
    // each control in the config page vertical layout plus the dialogue buttons should be made (in)sensitive
65
    mode = n;
66
    gtk_container_foreach(GTK_CONTAINER(lookup_widget(startwin,"buttons")),
67
                          (GtkCallback)gtk_widget_set_sensitive, (gpointer)mode);
68
    gtk_container_foreach(GTK_CONTAINER(lookup_widget(startwin,"configvlayout")),
69
                          (GtkCallback)gtk_widget_set_sensitive, (gpointer)mode);
70
}
71
 
72
static void on_vmode3dcombo_changed(GtkComboBox *, gpointer);
73
static void PopulateForm(void)
74
{
75
    int mode3d, i;
76
    GtkListStore *modes3d;
77
    GtkTreeIter iter;
78
    GtkComboBox *box3d;
79
    char buf[64];
80
 
81
    mode3d = checkvideomode(&settings.xdim3d, &settings.ydim3d, settings.bpp3d, settings.fullscreen, 1);
82
    if (mode3d < 0) {
83
        int i, cd[] = { 32, 24, 16, 15, 8, 0 };
84
        for (i=0; cd[i]; ) { if (cd[i] >= settings.bpp3d) i++; else break; }
85
        for ( ; cd[i]; i++) {
86
            mode3d = checkvideomode(&settings.xdim3d, &settings.ydim3d, cd[i], settings.fullscreen, 1);
87
            if (mode3d < 0) continue;
88
            settings.bpp3d = cd[i];
89
            break;
90
        }
91
    }
92
 
93
    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(lookup_widget(startwin,"fullscreencheck")), settings.fullscreen);
94
    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(lookup_widget(startwin,"alwaysshowcheck")), settings.forcesetup);
95
 
96
    box3d = GTK_COMBO_BOX(lookup_widget(startwin,"vmode3dcombo"));
97
    modes3d = GTK_LIST_STORE(gtk_combo_box_get_model(box3d));
98
    gtk_list_store_clear(modes3d);
99
 
100
    for (i=0; i<validmodecnt; i++) {
101
        if (validmode[i].fs != settings.fullscreen) continue;
102
 
103
        // all modes get added to the 3D mode list
104
        Bsprintf(buf, "%ld x %ld %dbpp", validmode[i].xdim, validmode[i].ydim, validmode[i].bpp);
105
        gtk_list_store_append(modes3d, &iter);
106
        gtk_list_store_set(modes3d, &iter, 0,buf, 1,i, -1);
107
        if (i == mode3d) {
108
            g_signal_handlers_block_by_func(box3d, on_vmode3dcombo_changed, NULL);
109
            gtk_combo_box_set_active_iter(box3d, &iter);
110
            g_signal_handlers_unblock_by_func(box3d, on_vmode3dcombo_changed, NULL);
111
        }
112
    }
113
 
114
    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(lookup_widget(startwin,"inputmousecheck")), settings.usemouse);
115
    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(lookup_widget(startwin,"inputjoycheck")), settings.usejoy);
116
}
117
 
118
// -- EVENT CALLBACKS AND CREATION STUFF --------------------------------------
119
 
120
static void on_vmode3dcombo_changed(GtkComboBox *combobox, gpointer user_data)
121
{
122
    GtkTreeModel *data;
123
    GtkTreeIter iter;
124
    int val;
125
    if (!gtk_combo_box_get_active_iter(combobox, &iter)) return;
126
    if (!(data = gtk_combo_box_get_model(combobox))) return;
127
    gtk_tree_model_get(data, &iter, 1, &val, -1);
128
    settings.xdim3d = validmode[val].xdim;
129
    settings.ydim3d = validmode[val].ydim;
130
}
131
 
132
static void on_fullscreencheck_toggled(GtkToggleButton *togglebutton, gpointer user_data)
133
{
134
    settings.fullscreen = (gtk_toggle_button_get_active(togglebutton) == TRUE);
135
    PopulateForm();
136
}
137
 
138
static void on_alwaysshowcheck_toggled(GtkToggleButton *togglebutton, gpointer user_data)
139
{
140
    settings.forcesetup = (gtk_toggle_button_get_active(togglebutton) == TRUE);
141
}
142
 
143
static void on_cancelbutton_clicked(GtkButton *button, gpointer user_data)
144
{
145
    retval = 0;
146
    gtk_main_quit();
147
}
148
 
149
static void on_startbutton_clicked(GtkButton *button, gpointer user_data)
150
{
151
    retval = 1;
152
    gtk_main_quit();
153
}
154
 
155
static void on_sounddrvcombo_changed(GtkComboBox *combobox, gpointer user_data)
156
{
157
}
158
 
159
static void on_cddrvcombo_changed(GtkComboBox *combobox, gpointer user_data)
160
{
161
}
162
 
163
static void on_inputmousecheck_toggled(GtkToggleButton *togglebutton, gpointer user_data)
164
{
165
    settings.usemouse = (gtk_toggle_button_get_active(togglebutton) == TRUE);
166
}
167
 
168
static void on_inputjoycheck_toggled(GtkToggleButton *togglebutton, gpointer user_data)
169
{
170
    settings.usejoy = (gtk_toggle_button_get_active(togglebutton) == TRUE);
171
}
172
 
173
static gboolean on_startwin_delete_event(GtkWidget *widget, GdkEvent *event, gpointer user_data)
174
{
175
    //quitevent++;
176
    return TRUE;        // FALSE would let the event go through. we want the game to decide when to close
177
}
178
 
179
 
180
static GtkWidget *create_window(void)
181
{
182
    GtkWidget *startwin;
183
    GtkWidget *hlayout;
184
    GtkWidget *banner;
185
    GtkWidget *vlayout;
186
    GtkWidget *tabs;
187
    GtkWidget *configvlayout;
188
    GtkWidget *configlayout;
189
    GtkWidget *fullscreencheck;
190
    GtkWidget *vmode3dlabel;
191
    GtkWidget *inputdevlabel;
192
    GtkWidget *sounddrvlabel;
193
    GtkWidget *cddrvlabel;
194
    GtkWidget *sounddrvcombo;
195
    GtkWidget *cddrvcombo;
196
    GtkWidget *inputmousecheck;
197
    GtkWidget *inputjoycheck;
198
    GtkWidget *vmode3dcombo;
199
    GtkWidget *alwaysshowcheck;
200
    GtkWidget *configtab;
201
    GtkWidget *messagesscroll;
202
    GtkWidget *messagestext;
203
    GtkWidget *messagestab;
204
    GtkWidget *buttons;
205
    GtkWidget *cancelbutton;
206
    GtkWidget *cancelbuttonalign;
207
    GtkWidget *cancelbuttonlayout;
208
    GtkWidget *cancelbuttonicon;
209
    GtkWidget *cancelbuttonlabel;
210
    GtkWidget *startbutton;
211
    GtkWidget *startbuttonalign;
212
    GtkWidget *startbuttonlayout;
213
    GtkWidget *startbuttonicon;
214
    GtkWidget *startbuttonlabel;
215
    GtkAccelGroup *accel_group;
216
 
217
    accel_group = gtk_accel_group_new ();
218
 
219
    // Basic window
220
    startwin = gtk_window_new (GTK_WINDOW_TOPLEVEL);
221
    gtk_window_set_title (GTK_WINDOW (startwin), apptitle);     // NOTE: use global app title
222
    gtk_window_set_position (GTK_WINDOW (startwin), GTK_WIN_POS_CENTER);
223
    gtk_window_set_resizable (GTK_WINDOW (startwin), FALSE);
224
    gtk_window_set_type_hint (GTK_WINDOW (startwin), GDK_WINDOW_TYPE_HINT_DIALOG);
225
 
226
    // Horizontal layout of banner and controls
227
    hlayout = gtk_hbox_new (FALSE, 0);
228
    gtk_widget_show (hlayout);
229
    gtk_container_add (GTK_CONTAINER (startwin), hlayout);
230
 
231
    // Banner
232
    {
233
        GdkPixbuf *pixbuf = load_banner();
234
        banner = gtk_image_new_from_pixbuf(pixbuf);
235
        g_object_unref((gpointer)pixbuf);
236
    }
237
    gtk_widget_show (banner);
238
    gtk_box_pack_start (GTK_BOX (hlayout), banner, FALSE, FALSE, 0);
239
    gtk_misc_set_alignment (GTK_MISC (banner), 0.5, 0);
240
 
241
    // Vertical layout of tab control and start+cancel buttons
242
    vlayout = gtk_vbox_new (FALSE, 0);
243
    gtk_widget_show (vlayout);
244
    gtk_box_pack_start (GTK_BOX (hlayout), vlayout, TRUE, TRUE, 0);
245
 
246
    // Tab control
247
    tabs = gtk_notebook_new ();
248
    gtk_widget_show (tabs);
249
    gtk_box_pack_start (GTK_BOX (vlayout), tabs, TRUE, TRUE, 0);
250
    gtk_container_set_border_width (GTK_CONTAINER (tabs), 4);
251
 
252
    // Vertical layout of config page main body
253
    configvlayout = gtk_vbox_new (FALSE, 0);
254
    gtk_widget_show (configvlayout);
255
    gtk_container_add (GTK_CONTAINER (tabs), configvlayout);
256
 
257
    // Fixed-position layout of config page controls
258
    configlayout = gtk_fixed_new ();
259
    gtk_widget_show (configlayout);
260
    gtk_box_pack_start (GTK_BOX (configvlayout), configlayout, TRUE, TRUE, 0);
261
    gtk_container_set_border_width (GTK_CONTAINER (configlayout), 6);
262
 
263
    // Fullscreen checkbox
264
    fullscreencheck = gtk_check_button_new_with_mnemonic ("_Fullscreen");
265
    gtk_widget_show (fullscreencheck);
266
    gtk_fixed_put (GTK_FIXED (configlayout), fullscreencheck, 248, 0);
267
    gtk_widget_set_size_request (fullscreencheck, 85, 29);
268
    gtk_widget_add_accelerator (fullscreencheck, "grab_focus", accel_group,
269
                                GDK_F, GDK_MOD1_MASK,
270
                                GTK_ACCEL_VISIBLE);
271
 
272
    // 3D video mode label
273
    vmode3dlabel = gtk_label_new_with_mnemonic ("_Video mode:");
274
    gtk_widget_show (vmode3dlabel);
275
    gtk_fixed_put (GTK_FIXED (configlayout), vmode3dlabel, 0, 0);
276
    gtk_widget_set_size_request (vmode3dlabel, 88, 29);
277
    gtk_misc_set_alignment (GTK_MISC (vmode3dlabel), 0, 0.5);
278
 
279
    inputdevlabel = gtk_label_new ("Input devices:");
280
    gtk_widget_show (inputdevlabel);
281
    gtk_fixed_put (GTK_FIXED (configlayout), inputdevlabel, 0, 120);
282
    gtk_widget_set_size_request (inputdevlabel, 88, 20);
283
    gtk_misc_set_alignment (GTK_MISC (inputdevlabel), 0, 0.5);
284
 
285
    sounddrvlabel = gtk_label_new_with_mnemonic ("S_ound driver:");
286
    gtk_widget_show (sounddrvlabel);
287
    gtk_fixed_put (GTK_FIXED (configlayout), sounddrvlabel, 0, 40);
288
    gtk_widget_set_size_request (sounddrvlabel, 88, 29);
289
    gtk_misc_set_alignment (GTK_MISC (sounddrvlabel), 0, 0.5);
290
 
291
    cddrvlabel = gtk_label_new_with_mnemonic ("C_D drive:");
292
    gtk_widget_show (cddrvlabel);
293
    gtk_fixed_put (GTK_FIXED (configlayout), cddrvlabel, 0, 72);
294
    gtk_widget_set_size_request (cddrvlabel, 88, 29);
295
    gtk_misc_set_alignment (GTK_MISC (cddrvlabel), 0, 0.5);
296
 
297
    sounddrvcombo = gtk_combo_box_new_text ();
298
    gtk_widget_show (sounddrvcombo);
299
    gtk_fixed_put (GTK_FIXED (configlayout), sounddrvcombo, 88, 40);
300
    gtk_widget_set_size_request (sounddrvcombo, 31, 30);
301
    gtk_widget_add_accelerator (sounddrvcombo, "grab_focus", accel_group,
302
                                GDK_O, GDK_MOD1_MASK,
303
                                GTK_ACCEL_VISIBLE);
304
 
305
    cddrvcombo = gtk_combo_box_new_text ();
306
    gtk_widget_show (cddrvcombo);
307
    gtk_fixed_put (GTK_FIXED (configlayout), cddrvcombo, 88, 72);
308
    gtk_widget_set_size_request (cddrvcombo, 31, 30);
309
 
310
    inputmousecheck = gtk_check_button_new_with_mnemonic ("Mo_use");
311
    gtk_widget_show (inputmousecheck);
312
    gtk_fixed_put (GTK_FIXED (configlayout), inputmousecheck, 88, 120);
313
    gtk_widget_set_size_request (inputmousecheck, 80, 20);
314
    gtk_widget_add_accelerator (inputmousecheck, "grab_focus", accel_group,
315
                                GDK_U, GDK_MOD1_MASK,
316
                                GTK_ACCEL_VISIBLE);
317
 
318
    inputjoycheck = gtk_check_button_new_with_mnemonic ("_Joystick");
319
    gtk_widget_show (inputjoycheck);
320
    gtk_fixed_put (GTK_FIXED (configlayout), inputjoycheck, 168, 120);
321
    gtk_widget_set_size_request (inputjoycheck, 80, 20);
322
    gtk_widget_add_accelerator (inputjoycheck, "grab_focus", accel_group,
323
                                GDK_J, GDK_MOD1_MASK,
324
                                GTK_ACCEL_VISIBLE);
325
 
326
    // 3D video mode combo
327
    {
328
        GtkListStore *list = gtk_list_store_new(2, G_TYPE_STRING, G_TYPE_INT);
329
        GtkCellRenderer *cell;
330
 
331
        vmode3dcombo = gtk_combo_box_new_with_model (GTK_TREE_MODEL(list));
332
        g_object_unref(G_OBJECT(list));
333
 
334
        cell = gtk_cell_renderer_text_new();
335
        gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(vmode3dcombo), cell, FALSE);
336
        gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(vmode3dcombo), cell, "text", 0, NULL);
337
    }
338
    gtk_widget_show (vmode3dcombo);
339
    gtk_fixed_put (GTK_FIXED (configlayout), vmode3dcombo, 88, 0);
340
    gtk_widget_set_size_request (vmode3dcombo, 150, 29);
341
    gtk_widget_add_accelerator (vmode3dcombo, "grab_focus", accel_group,
342
                                GDK_V, GDK_MOD1_MASK,
343
                                GTK_ACCEL_VISIBLE);
344
 
345
    // Always show config checkbox
346
    alwaysshowcheck = gtk_check_button_new_with_mnemonic ("_Always show configuration on start");
347
    gtk_widget_show (alwaysshowcheck);
348
    gtk_box_pack_start (GTK_BOX (configvlayout), alwaysshowcheck, FALSE, FALSE, 0);
349
    gtk_widget_add_accelerator (alwaysshowcheck, "grab_focus", accel_group,
350
                                GDK_A, GDK_MOD1_MASK,
351
                                GTK_ACCEL_VISIBLE);
352
 
353
    // Configuration tab
354
    configtab = gtk_label_new ("Configuration");
355
    gtk_widget_show (configtab);
356
    gtk_notebook_set_tab_label (GTK_NOTEBOOK (tabs), gtk_notebook_get_nth_page (GTK_NOTEBOOK (tabs), 0), configtab);
357
 
358
    // Messages scrollable area
359
    messagesscroll = gtk_scrolled_window_new (NULL, NULL);
360
    gtk_widget_show (messagesscroll);
361
    gtk_container_add (GTK_CONTAINER (tabs), messagesscroll);
362
    gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (messagesscroll), GTK_POLICY_NEVER, GTK_POLICY_ALWAYS);
363
 
364
    // Messages text area
365
    messagestext = gtk_text_view_new ();
366
    gtk_widget_show (messagestext);
367
    gtk_container_add (GTK_CONTAINER (messagesscroll), messagestext);
368
    gtk_text_view_set_editable (GTK_TEXT_VIEW (messagestext), FALSE);
369
    gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (messagestext), GTK_WRAP_WORD);
370
    gtk_text_view_set_cursor_visible (GTK_TEXT_VIEW (messagestext), FALSE);
371
    gtk_text_view_set_left_margin (GTK_TEXT_VIEW (messagestext), 2);
372
    gtk_text_view_set_right_margin (GTK_TEXT_VIEW (messagestext), 2);
373
 
374
    // Messages tab
375
    messagestab = gtk_label_new ("Messages");
376
    gtk_widget_show (messagestab);
377
    gtk_notebook_set_tab_label (GTK_NOTEBOOK (tabs), gtk_notebook_get_nth_page (GTK_NOTEBOOK (tabs), 1), messagestab);
378
 
379
    // Dialogue box buttons layout
380
    buttons = gtk_hbutton_box_new ();
381
    gtk_widget_show (buttons);
382
    gtk_box_pack_start (GTK_BOX (vlayout), buttons, FALSE, TRUE, 0);
383
    gtk_container_set_border_width (GTK_CONTAINER (buttons), 3);
384
    gtk_button_box_set_layout (GTK_BUTTON_BOX (buttons), GTK_BUTTONBOX_END);
385
 
386
    // Cancel button
387
    cancelbutton = gtk_button_new ();
388
    gtk_widget_show (cancelbutton);
389
    gtk_container_add (GTK_CONTAINER (buttons), cancelbutton);
390
    GTK_WIDGET_SET_FLAGS (cancelbutton, GTK_CAN_DEFAULT);
391
    gtk_widget_add_accelerator (cancelbutton, "grab_focus", accel_group,
392
                                GDK_C, GDK_MOD1_MASK,
393
                                GTK_ACCEL_VISIBLE);
394
 
395
    cancelbuttonalign = gtk_alignment_new (0.5, 0.5, 0, 0);
396
    gtk_widget_show (cancelbuttonalign);
397
    gtk_container_add (GTK_CONTAINER (cancelbutton), cancelbuttonalign);
398
 
399
    cancelbuttonlayout = gtk_hbox_new (FALSE, 2);
400
    gtk_widget_show (cancelbuttonlayout);
401
    gtk_container_add (GTK_CONTAINER (cancelbuttonalign), cancelbuttonlayout);
402
 
403
    cancelbuttonicon = gtk_image_new_from_stock ("gtk-cancel", GTK_ICON_SIZE_BUTTON);
404
    gtk_widget_show (cancelbuttonicon);
405
    gtk_box_pack_start (GTK_BOX (cancelbuttonlayout), cancelbuttonicon, FALSE, FALSE, 0);
406
 
407
    cancelbuttonlabel = gtk_label_new_with_mnemonic ("_Cancel");
408
    gtk_widget_show (cancelbuttonlabel);
409
    gtk_box_pack_start (GTK_BOX (cancelbuttonlayout), cancelbuttonlabel, FALSE, FALSE, 0);
410
 
411
    // Start button
412
    startbutton = gtk_button_new ();
413
    gtk_widget_show (startbutton);
414
    gtk_container_add (GTK_CONTAINER (buttons), startbutton);
415
    GTK_WIDGET_SET_FLAGS (startbutton, GTK_CAN_DEFAULT);
416
    gtk_widget_add_accelerator (startbutton, "grab_focus", accel_group,
417
                                GDK_S, GDK_MOD1_MASK,
418
                                GTK_ACCEL_VISIBLE);
419
 
420
    startbuttonalign = gtk_alignment_new (0.5, 0.5, 0, 0);
421
    gtk_widget_show (startbuttonalign);
422
    gtk_container_add (GTK_CONTAINER (startbutton), startbuttonalign);
423
 
424
    startbuttonlayout = gtk_hbox_new (FALSE, 2);
425
    gtk_widget_show (startbuttonlayout);
426
    gtk_container_add (GTK_CONTAINER (startbuttonalign), startbuttonlayout);
427
 
428
    startbuttonicon = gtk_image_new_from_stock ("gtk-execute", GTK_ICON_SIZE_BUTTON);
429
    gtk_widget_show (startbuttonicon);
430
    gtk_box_pack_start (GTK_BOX (startbuttonlayout), startbuttonicon, FALSE, FALSE, 0);
431
 
432
    startbuttonlabel = gtk_label_new_with_mnemonic ("_Start");
433
    gtk_widget_show (startbuttonlabel);
434
    gtk_box_pack_start (GTK_BOX (startbuttonlayout), startbuttonlabel, FALSE, FALSE, 0);
435
 
436
    // Wire up the signals
437
    g_signal_connect ((gpointer) startwin, "delete_event",
438
                      G_CALLBACK (on_startwin_delete_event),
439
                      NULL);
440
    g_signal_connect ((gpointer) fullscreencheck, "toggled",
441
                      G_CALLBACK (on_fullscreencheck_toggled),
442
                      NULL);
443
    g_signal_connect ((gpointer) sounddrvcombo, "changed",
444
                      G_CALLBACK (on_sounddrvcombo_changed),
445
                      NULL);
446
    g_signal_connect ((gpointer) cddrvcombo, "changed",
447
                      G_CALLBACK (on_cddrvcombo_changed),
448
                      NULL);
449
    g_signal_connect ((gpointer) inputmousecheck, "toggled",
450
                      G_CALLBACK (on_inputmousecheck_toggled),
451
                      NULL);
452
    g_signal_connect ((gpointer) inputjoycheck, "toggled",
453
                      G_CALLBACK (on_inputjoycheck_toggled),
454
                      NULL);
455
    g_signal_connect ((gpointer) vmode3dcombo, "changed",
456
                      G_CALLBACK (on_vmode3dcombo_changed),
457
                      NULL);
458
    g_signal_connect ((gpointer) alwaysshowcheck, "toggled",
459
                      G_CALLBACK (on_alwaysshowcheck_toggled),
460
                      NULL);
461
    g_signal_connect ((gpointer) cancelbutton, "clicked",
462
                      G_CALLBACK (on_cancelbutton_clicked),
463
                      NULL);
464
    g_signal_connect ((gpointer) startbutton, "clicked",
465
                      G_CALLBACK (on_startbutton_clicked),
466
                      NULL);
467
 
468
    // Associate labels with their controls
469
    gtk_label_set_mnemonic_widget (GTK_LABEL (vmode3dlabel), vmode3dcombo);
470
    gtk_label_set_mnemonic_widget (GTK_LABEL (sounddrvlabel), sounddrvcombo);
471
    gtk_label_set_mnemonic_widget (GTK_LABEL (cddrvlabel), cddrvcombo);
472
 
473
    /* Store pointers to all widgets, for use by lookup_widget(). */
474
    GLADE_HOOKUP_OBJECT_NO_REF (startwin, startwin, "startwin");
475
    GLADE_HOOKUP_OBJECT (startwin, hlayout, "hlayout");
476
    GLADE_HOOKUP_OBJECT (startwin, banner, "banner");
477
    GLADE_HOOKUP_OBJECT (startwin, vlayout, "vlayout");
478
    GLADE_HOOKUP_OBJECT (startwin, tabs, "tabs");
479
    GLADE_HOOKUP_OBJECT (startwin, configvlayout, "configvlayout");
480
    GLADE_HOOKUP_OBJECT (startwin, configlayout, "configlayout");
481
    GLADE_HOOKUP_OBJECT (startwin, fullscreencheck, "fullscreencheck");
482
    GLADE_HOOKUP_OBJECT (startwin, vmode3dlabel, "vmode3dlabel");
483
    GLADE_HOOKUP_OBJECT (startwin, inputdevlabel, "inputdevlabel");
484
    GLADE_HOOKUP_OBJECT (startwin, sounddrvlabel, "sounddrvlabel");
485
    GLADE_HOOKUP_OBJECT (startwin, cddrvlabel, "cddrvlabel");
486
    GLADE_HOOKUP_OBJECT (startwin, sounddrvcombo, "sounddrvcombo");
487
    GLADE_HOOKUP_OBJECT (startwin, cddrvcombo, "cddrvcombo");
488
    GLADE_HOOKUP_OBJECT (startwin, inputmousecheck, "inputmousecheck");
489
    GLADE_HOOKUP_OBJECT (startwin, inputjoycheck, "inputjoycheck");
490
    GLADE_HOOKUP_OBJECT (startwin, vmode3dcombo, "vmode3dcombo");
491
    GLADE_HOOKUP_OBJECT (startwin, alwaysshowcheck, "alwaysshowcheck");
492
    GLADE_HOOKUP_OBJECT (startwin, configtab, "configtab");
493
    GLADE_HOOKUP_OBJECT (startwin, messagesscroll, "messagesscroll");
494
    GLADE_HOOKUP_OBJECT (startwin, messagestext, "messagestext");
495
    GLADE_HOOKUP_OBJECT (startwin, messagestab, "messagestab");
496
    GLADE_HOOKUP_OBJECT (startwin, buttons, "buttons");
497
    GLADE_HOOKUP_OBJECT (startwin, cancelbutton, "cancelbutton");
498
    GLADE_HOOKUP_OBJECT (startwin, cancelbuttonalign, "cancelbuttonalign");
499
    GLADE_HOOKUP_OBJECT (startwin, cancelbuttonlayout, "cancelbuttonlayout");
500
    GLADE_HOOKUP_OBJECT (startwin, cancelbuttonicon, "cancelbuttonicon");
501
    GLADE_HOOKUP_OBJECT (startwin, cancelbuttonlabel, "cancelbuttonlabel");
502
    GLADE_HOOKUP_OBJECT (startwin, startbutton, "startbutton");
503
    GLADE_HOOKUP_OBJECT (startwin, startbuttonalign, "startbuttonalign");
504
    GLADE_HOOKUP_OBJECT (startwin, startbuttonlayout, "startbuttonlayout");
505
    GLADE_HOOKUP_OBJECT (startwin, startbuttonicon, "startbuttonicon");
506
    GLADE_HOOKUP_OBJECT (startwin, startbuttonlabel, "startbuttonlabel");
507
 
508
    gtk_window_add_accel_group (GTK_WINDOW (startwin), accel_group);
509
 
510
    return startwin;
511
}
512
 
513
// -- BUILD ENTRY POINTS ------------------------------------------------------
514
 
515
int startwin_open(void)
516
{
517
    if (!gtkenabled) return 0;
518
    if (startwin) return 1;
519
 
520
    startwin = create_window();
521
    if (startwin) {
522
        SetPage(TAB_MESSAGES);
523
        EnableConfig(FALSE);
524
        gtk_widget_show(startwin);
525
        gtk_main_iteration_do(FALSE);
526
        return 0;
527
    }
528
    return -1;
529
}
530
 
531
int startwin_close(void)
532
{
533
    if (!gtkenabled) return 0;
534
    if (!startwin) return 1;
535
    gtk_widget_destroy (startwin);
536
    startwin = NULL;
537
    return 0;
538
}
539
 
540
int startwin_puts(const char *str)
541
{
542
    GtkWidget *textview;
543
    GtkTextBuffer *textbuffer;
544
    GtkTextIter enditer;
545
    GtkTextMark *mark;
546
    const char *aptr, *bptr;
547
 
548
    if (!gtkenabled || !str) return 0;
549
    if (!startwin) return 1;
550
    if (!(textview = lookup_widget(startwin, "messagestext"))) return -1;
551
    textbuffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(textview));
552
 
553
    gtk_text_buffer_get_end_iter(textbuffer, &enditer);
554
    for (aptr = bptr = str; *aptr != 0; ) {
555
        switch (*bptr) {
556
        case '\b':
557
            if (bptr > aptr)
558
                gtk_text_buffer_insert(textbuffer, &enditer, (const gchar *)aptr, (gint)(bptr-aptr)-1);
559
#if GTK_CHECK_VERSION(2,6,0)
560
            gtk_text_buffer_backspace(textbuffer, &enditer, FALSE, TRUE);
561
#else
562
            {
563
                GtkTextIter iter2 = enditer;
564
                gtk_text_iter_backward_cursor_position(&iter2);
565
                //FIXME: this seems be deleting one too many chars somewhere!
566
                if (!gtk_text_iter_equal(&iter2, &enditer))
567
                    gtk_text_buffer_delete_interactive(textbuffer, &iter2, &enditer, TRUE);
568
            }
569
#endif
570
            aptr = ++bptr;
571
            break;
572
        case 0:
573
            if (bptr > aptr)
574
                gtk_text_buffer_insert(textbuffer, &enditer, (const gchar *)aptr, (gint)(bptr-aptr));
575
            aptr = bptr;
576
            break;
577
        case '\r':      // FIXME
578
        default:
579
            bptr++;
580
            break;
581
        }
582
    }
583
 
584
    mark = gtk_text_buffer_create_mark(textbuffer, NULL, &enditer, 1);
585
    gtk_text_view_scroll_to_mark(GTK_TEXT_VIEW(textview), mark, 0.0, FALSE, 0.0, 1.0);
586
    gtk_text_buffer_delete_mark(textbuffer, mark);
587
 
588
    return 0;
589
}
590
 
591
int startwin_settitle(const char *title)
592
{
593
    if (!gtkenabled) return 0;
594
    if (!startwin) return 1;
595
    gtk_window_set_title (GTK_WINDOW (startwin), title);
596
    return 0;
597
}
598
 
599
int startwin_idle(void *s)
600
{
601
    if (!gtkenabled) return 0;
602
    //if (!startwin) return 1;
603
    gtk_main_iteration_do (FALSE);
604
    return 0;
605
}
606
 
607
extern int xdimgame, ydimgame, bppgame, forcesetup;
608
 
609
int startwin_run(void)
610
{
611
    if (!gtkenabled) return 0;
612
    if (!startwin) return 1;
613
 
614
    SetPage(TAB_CONFIG);
615
    EnableConfig(TRUE);
616
 
617
    settings.fullscreen = ScreenMode;
618
    settings.xdim3d = ScreenWidth;
619
    settings.ydim3d = ScreenHeight;
620
    settings.bpp3d = ScreenBPP;
621
    settings.forcesetup = ForceSetup;
622
    settings.usemouse = UseMouse;
623
    settings.usejoy = UseJoystick;
624
    PopulateForm();
625
 
626
    gtk_main();
627
 
628
    SetPage(TAB_MESSAGES);
629
    EnableConfig(FALSE);
630
    if (retval) {
631
        ScreenMode = settings.fullscreen;
632
        ScreenWidth = settings.xdim3d;
633
        ScreenHeight = settings.ydim3d;
634
        ScreenBPP = settings.bpp3d;
635
        ForceSetup = settings.forcesetup;
636
        UseMouse = settings.usemouse;
637
        UseJoystick = settings.usejoy;
638
    }
639
 
640
    return retval;
641
}
642