Subversion Repositories eduke32

Rev

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