Subversion Repositories eduke32

Rev

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