Subversion Repositories eduke32

Rev

Rev 1425 | Rev 1457 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
194 terminx 1
#ifndef RENDERTYPEWIN
2
#error Only for Windows
3
#endif
4
 
5
#include "duke3d.h"
219 terminx 6
#include "sounds.h"
194 terminx 7
 
8
#include "build.h"
9
#include "winlayer.h"
10
#include "compat.h"
11
 
241 terminx 12
#include "grpscan.h"
214 terminx 13
 
194 terminx 14
#define WIN32_LEAN_AND_MEAN
15
#include <windows.h>
16
#include <windowsx.h>
1121 terminx 17
#ifndef _WIN32_IE
194 terminx 18
#define _WIN32_IE 0x0300
1121 terminx 19
#endif
194 terminx 20
#include <commctrl.h>
21
#include <stdio.h>
22
 
23
#include "startwin.game.h"
24
 
25
#define TAB_CONFIG 0
991 terminx 26
// #define TAB_GAME 1
27
#define TAB_MESSAGES 1
194 terminx 28
 
219 terminx 29
static struct audioenumdrv *wavedevs = NULL;
30
 
335 terminx 31
static struct
32
{
1325 terminx 33
    int32_t flags; // bitfield
1205 terminx 34
    int32_t xdim, ydim, bpp;
35
    int32_t forcesetup;
36
    int32_t usemouse, usejoy;
222 terminx 37
    char selectedgrp[BMAX_PATH+1];
1205 terminx 38
    int32_t game;
39
    int32_t crcval; // for finding the grp in the list again
984 terminx 40
    char *gamedir;
335 terminx 41
}
42
settings;
194 terminx 43
 
44
static HWND startupdlg = NULL;
335 terminx 45
static HWND pages[3] =
559 terminx 46
{
47
    NULL, NULL, NULL
48
};
1205 terminx 49
static int32_t done = -1, mode = TAB_CONFIG;
194 terminx 50
 
984 terminx 51
static CACHE1D_FIND_REC *finddirs=NULL;
1205 terminx 52
static int32_t numdirs=0;
984 terminx 53
 
987 terminx 54
static void clearfilenames(void)
984 terminx 55
{
56
    klistfree(finddirs);
57
    finddirs = NULL;
58
    numdirs = 0;
59
}
60
 
1205 terminx 61
static int32_t getfilenames(char *path)
984 terminx 62
{
63
    CACHE1D_FIND_REC *r;
64
 
65
    clearfilenames();
66
    finddirs = klistpath(path,"*",CACHE1D_FIND_DIR);
67
    for (r = finddirs; r; r=r->next) numdirs++;
68
    return(0);
69
}
70
 
219 terminx 71
#define POPULATE_VIDEO 1
72
#define POPULATE_CONFIG 2
73
#define POPULATE_GAME 4
985 terminx 74
#define POPULATE_GAMEDIRS 8
219 terminx 75
 
1064 terminx 76
#if defined(POLYMOST)
1166 terminx 77
extern char TEXCACHEFILE[];
1064 terminx 78
#endif
988 terminx 79
 
1205 terminx 80
extern int32_t g_noSetup;
1097 terminx 81
 
1399 terminx 82
#ifdef INPUT_MOUSE
83
#undef INPUT_MOUSE
84
#endif
85
 
1327 terminx 86
#define INPUT_KB 0
87
#define INPUT_MOUSE 1
88
#define INPUT_JOYSTICK 2
89
#define INPUT_ALL 3
90
 
1205 terminx 91
static void PopulateForm(int32_t pgs)
194 terminx 92
{
222 terminx 93
    HWND hwnd;
94
    char buf[256];
1205 terminx 95
    int32_t i,j;
219 terminx 96
 
335 terminx 97
    if (pgs & POPULATE_VIDEO)
98
    {
1205 terminx 99
        int32_t mode;
194 terminx 100
 
222 terminx 101
        hwnd = GetDlgItem(pages[TAB_CONFIG], IDCVMODE);
194 terminx 102
 
1325 terminx 103
        mode = checkvideomode(&settings.xdim, &settings.ydim, settings.bpp, settings.flags&1, 1);
104
        if (mode < 0 || (settings.bpp < 15 && (settings.flags & 2)))
335 terminx 105
        {
1205 terminx 106
            int32_t cd[] = { 32, 24, 16, 15, 8, 0 };
335 terminx 107
            for (i=0; cd[i];)
108
            {
109
                if (cd[i] >= settings.bpp) i++;
110
                else break;
111
            }
112
            for (; cd[i]; i++)
113
            {
1325 terminx 114
                mode = checkvideomode(&settings.xdim, &settings.ydim, cd[i], settings.flags&1, 1);
222 terminx 115
                if (mode < 0) continue;
116
                settings.bpp = cd[i];
117
                break;
118
            }
119
        }
214 terminx 120
 
1325 terminx 121
        Button_SetCheck(GetDlgItem(pages[TAB_CONFIG], IDCFULLSCREEN), ((settings.flags&1) ? BST_CHECKED : BST_UNCHECKED));
122
        Button_SetCheck(GetDlgItem(pages[TAB_CONFIG], IDCPOLYMER), ((settings.flags&2) ? BST_CHECKED : BST_UNCHECKED));
649 terminx 123
        (void)ComboBox_ResetContent(hwnd);
335 terminx 124
        for (i=0; i<validmodecnt; i++)
125
        {
1325 terminx 126
            if (validmode[i].fs != (settings.flags & 1)) continue;
127
            if ((validmode[i].bpp < 15) && (settings.flags & 2)) continue;
214 terminx 128
 
222 terminx 129
            // all modes get added to the 3D mode list
584 terminx 130
            Bsprintf(buf, "%d x %d %dbpp", validmode[i].xdim, validmode[i].ydim, validmode[i].bpp);
222 terminx 131
            j = ComboBox_AddString(hwnd, buf);
649 terminx 132
            (void)ComboBox_SetItemData(hwnd, j, i);
723 terminx 133
            if (i == mode)(void)ComboBox_SetCurSel(hwnd, j);
222 terminx 134
        }
135
    }
214 terminx 136
 
335 terminx 137
    if (pgs & POPULATE_CONFIG)
138
    {
1454 terminx 139
/*
222 terminx 140
        struct audioenumdev *d;
141
        char *n;
219 terminx 142
 
222 terminx 143
        hwnd = GetDlgItem(pages[TAB_CONFIG], IDCSOUNDDRV);
649 terminx 144
        (void)ComboBox_ResetContent(hwnd);
335 terminx 145
        if (wavedevs)
146
        {
222 terminx 147
            d = wavedevs->devs;
335 terminx 148
            for (i=0; wavedevs->drvs[i]; i++)
149
            {
222 terminx 150
                strcpy(buf, wavedevs->drvs[i]);
335 terminx 151
                if (d->devs)
152
                {
222 terminx 153
                    strcat(buf, ":");
154
                    n = buf + strlen(buf);
335 terminx 155
                    for (j=0; d->devs[j]; j++)
156
                    {
222 terminx 157
                        strcpy(n, d->devs[j]);
649 terminx 158
                        (void)ComboBox_AddString(hwnd, buf);
222 terminx 159
                    }
335 terminx 160
                }
161
                else
162
                {
649 terminx 163
                    (void)ComboBox_AddString(hwnd, buf);
222 terminx 164
                }
165
                d = d->next;
166
            }
167
        }
1454 terminx 168
*/
219 terminx 169
 
222 terminx 170
        Button_SetCheck(GetDlgItem(pages[TAB_CONFIG], IDCALWAYSSHOW), (settings.forcesetup ? BST_CHECKED : BST_UNCHECKED));
1325 terminx 171
        Button_SetCheck(GetDlgItem(pages[TAB_CONFIG], IDCAUTOLOAD), (!(settings.flags & 4) ? BST_CHECKED : BST_UNCHECKED));
1327 terminx 172
 
173
        {
1454 terminx 174
            static const char *s[] = { "Keyboard only", "Keyboard and mouse", "Keyboard and joystick", "All supported devices" };
1327 terminx 175
 
176
            hwnd = GetDlgItem(pages[TAB_CONFIG], IDCINPUT);
177
 
178
            (void)ComboBox_ResetContent(hwnd);
179
            j = ComboBox_AddString(hwnd, s[INPUT_KB]);
180
            (void)ComboBox_SetItemData(hwnd, j, INPUT_KB);
181
            (void)ComboBox_SetCurSel(hwnd, j);
1329 terminx 182
            for (i=1; i<4; i++)
1327 terminx 183
            {
184
                j = ComboBox_AddString(hwnd, s[i]);
185
                (void)ComboBox_SetItemData(hwnd, j, i);
186
                if ((settings.usemouse && !settings.usejoy && i == INPUT_MOUSE) ||
1329 terminx 187
                        (!settings.usemouse && settings.usejoy && i == INPUT_JOYSTICK) ||
188
                        (settings.usemouse && settings.usejoy && i == INPUT_ALL))
1327 terminx 189
                    (void)ComboBox_SetCurSel(hwnd, j);
190
            }
191
        }
192
 
222 terminx 193
    }
194 terminx 194
 
335 terminx 195
    if (pgs & POPULATE_GAME)
196
    {
222 terminx 197
        struct grpfile *fg;
1205 terminx 198
        int32_t i, j;
1454 terminx 199
        char buf[1024];
194 terminx 200
 
991 terminx 201
        hwnd = GetDlgItem(pages[TAB_CONFIG], IDCDATA);
194 terminx 202
 
335 terminx 203
        for (fg = foundgrps; fg; fg=fg->next)
204
        {
241 terminx 205
            for (i = 0; i<numgrpfiles; i++) if (fg->crcval == grpfiles[i].crcval) break;
222 terminx 206
            if (i == numgrpfiles) continue;     // unrecognised grp file
207
            Bsprintf(buf, "%s\t%s", grpfiles[i].name, fg->name);
208
            j = ListBox_AddString(hwnd, buf);
649 terminx 209
            (void)ListBox_SetItemData(hwnd, j, (LPARAM)fg);
723 terminx 210
            if (!Bstrcasecmp(fg->name, settings.selectedgrp))(void)ListBox_SetCurSel(hwnd, j);
222 terminx 211
        }
212
    }
984 terminx 213
 
985 terminx 214
    if (pgs & POPULATE_GAMEDIRS)
984 terminx 215
    {
216
        CACHE1D_FIND_REC *dirs = NULL;
217
 
991 terminx 218
        hwnd = GetDlgItem(pages[TAB_CONFIG], IDCGAMEDIR);
984 terminx 219
 
220
        getfilenames("/");
221
        (void)ComboBox_ResetContent(hwnd);
222
        j = ComboBox_AddString(hwnd, "None");
223
        (void)ComboBox_SetItemData(hwnd, j, 0);
985 terminx 224
        (void)ComboBox_SetCurSel(hwnd, j);
984 terminx 225
        for (dirs=finddirs,i=1; dirs != NULL; dirs=dirs->next,i++)
226
        {
1064 terminx 227
#if defined(POLYMOST) && defined(USE_OPENGL)
1166 terminx 228
            if (Bstrcasecmp(TEXCACHEFILE,dirs->name) == 0) continue;
1064 terminx 229
#endif
989 terminx 230
            j = ComboBox_AddString(hwnd, dirs->name);
984 terminx 231
            (void)ComboBox_SetItemData(hwnd, j, i);
990 terminx 232
            if (Bstrcasecmp(dirs->name,settings.gamedir) == 0)
985 terminx 233
                (void)ComboBox_SetCurSel(hwnd, j);
984 terminx 234
        }
235
    }
194 terminx 236
}
237
 
238
static INT_PTR CALLBACK ConfigPageProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
239
{
335 terminx 240
    switch (uMsg)
241
    {
337 terminx 242
    case WM_COMMAND:
243
        switch (LOWORD(wParam))
244
        {
245
        case IDCFULLSCREEN:
1325 terminx 246
            if (settings.flags & 1) settings.flags &= ~1;
247
            else settings.flags |= 1;
337 terminx 248
            PopulateForm(POPULATE_VIDEO);
249
            return TRUE;
1325 terminx 250
        case IDCPOLYMER:
251
            if (settings.flags & 2) settings.flags &= ~2;
252
            else settings.flags |= 2;
253
            if (settings.bpp == 8) settings.bpp = 32;
254
            PopulateForm(POPULATE_VIDEO);
255
            return TRUE;
337 terminx 256
        case IDCVMODE:
257
            if (HIWORD(wParam) == CBN_SELCHANGE)
335 terminx 258
            {
1205 terminx 259
                int32_t i;
337 terminx 260
                i = ComboBox_GetCurSel((HWND)lParam);
261
                if (i != CB_ERR) i = ComboBox_GetItemData((HWND)lParam, i);
262
                if (i != CB_ERR)
263
                {
264
                    settings.xdim = validmode[i].xdim;
265
                    settings.ydim = validmode[i].ydim;
266
                    settings.bpp  = validmode[i].bpp;
267
                }
222 terminx 268
            }
337 terminx 269
            return TRUE;
270
        case IDCALWAYSSHOW:
271
            settings.forcesetup = IsDlgButtonChecked(hwndDlg, IDCALWAYSSHOW) == BST_CHECKED;
272
            return TRUE;
1325 terminx 273
        case IDCAUTOLOAD:
1326 terminx 274
            if (IsDlgButtonChecked(hwndDlg, IDCAUTOLOAD) == BST_CHECKED)
1325 terminx 275
                settings.flags &= ~4;
276
            else settings.flags |= 4;
277
            return TRUE;
1329 terminx 278
            /*
279
                    case IDCINPUTMOUSE:
280
                        settings.usemouse = IsDlgButtonChecked(hwndDlg, IDCINPUTMOUSE) == BST_CHECKED;
281
                        return TRUE;
282
                    case IDCINPUTJOY:
283
                        settings.usejoy = IsDlgButtonChecked(hwndDlg, IDCINPUTJOY) == BST_CHECKED;
284
                        return TRUE;
285
            */
1327 terminx 286
        case IDCINPUT:
287
            if (HIWORD(wParam) == CBN_SELCHANGE)
288
            {
289
                int32_t i;
290
                i = ComboBox_GetCurSel((HWND)lParam);
291
                if (i != CB_ERR) i = ComboBox_GetItemData((HWND)lParam, i);
292
                if (i != CB_ERR)
293
                {
294
                    switch (i)
295
                    {
296
                    case 0:
297
                        settings.usemouse = settings.usejoy = 0;
298
                        break;
299
                    case 1:
300
                        settings.usemouse = 1;
301
                        settings.usejoy = 0;
302
                        break;
303
                    case 2:
304
                        settings.usemouse = 0;
305
                        settings.usejoy = 1;
306
                        break;
307
                    case 3:
308
                        settings.usemouse = settings.usejoy = 1;
309
                        break;
310
                    }
311
                }
312
            }
313
            return TRUE;
314
 
991 terminx 315
        case IDCGAMEDIR:
984 terminx 316
            if (HIWORD(wParam) == CBN_SELCHANGE)
317
            {
1205 terminx 318
                int32_t i,j;
984 terminx 319
                CACHE1D_FIND_REC *dir = NULL;
320
                i = ComboBox_GetCurSel((HWND)lParam);
321
                if (i != CB_ERR) i = ComboBox_GetItemData((HWND)lParam, i);
322
                if (i != CB_ERR)
323
                {
1062 terminx 324
                    if (i==0)
325
                        settings.gamedir = NULL;
326
                    else
327
                    {
1229 terminx 328
                        for (j=1,dir=finddirs; dir != NULL; dir=dir->next,j++)
1062 terminx 329
                            if (j == i)
330
                            {
331
                                settings.gamedir = dir->name;
332
                                break;
333
                            }
334
                    }
984 terminx 335
                }
336
            }
337
            return TRUE;
991 terminx 338
        case IDCDATA:
339
        {
1205 terminx 340
            int32_t i;
991 terminx 341
            if (HIWORD(wParam) != LBN_SELCHANGE) break;
342
            i = ListBox_GetCurSel((HWND)lParam);
343
            if (i != CB_ERR) i = ListBox_GetItemData((HWND)lParam, i);
344
            if (i != CB_ERR)
345
            {
346
                strcpy(settings.selectedgrp, ((struct grpfile*)i)->name);
347
                settings.game = ((struct grpfile*)i)->game;
348
                settings.crcval = ((struct grpfile*)i)->crcval;
349
            }
350
            return TRUE;
351
        }
331 terminx 352
        default:
353
            break;
337 terminx 354
        }
355
        break;
356
    default:
357
        break;
222 terminx 358
    }
359
    return FALSE;
214 terminx 360
}
194 terminx 361
 
362
 
1205 terminx 363
static void SetPage(int32_t n)
194 terminx 364
{
222 terminx 365
    HWND tab;
1205 terminx 366
    int32_t cur;
222 terminx 367
    tab = GetDlgItem(startupdlg, WIN_STARTWIN_TABCTL);
1205 terminx 368
    cur = (int32_t)SendMessage(tab, TCM_GETCURSEL,0,0);
222 terminx 369
    ShowWindow(pages[cur],SW_HIDE);
370
    SendMessage(tab, TCM_SETCURSEL, n, 0);
371
    ShowWindow(pages[n],SW_SHOW);
372
    mode = n;
196 terminx 373
 
222 terminx 374
    SetFocus(GetDlgItem(startupdlg, WIN_STARTWIN_TABCTL));
194 terminx 375
}
376
 
1205 terminx 377
static void EnableConfig(int32_t n)
194 terminx 378
{
222 terminx 379
    //EnableWindow(GetDlgItem(startupdlg, WIN_STARTWIN_CANCEL), n);
380
    EnableWindow(GetDlgItem(startupdlg, WIN_STARTWIN_START), n);
381
    EnableWindow(GetDlgItem(pages[TAB_CONFIG], IDCFULLSCREEN), n);
1325 terminx 382
    EnableWindow(GetDlgItem(pages[TAB_CONFIG], IDCPOLYMER), n);
222 terminx 383
    EnableWindow(GetDlgItem(pages[TAB_CONFIG], IDCVMODE), n);
1329 terminx 384
    /*
385
        EnableWindow(GetDlgItem(pages[TAB_CONFIG], IDCINPUTMOUSE), n);
386
        EnableWindow(GetDlgItem(pages[TAB_CONFIG], IDCINPUTJOY), n);
387
    */
1327 terminx 388
    EnableWindow(GetDlgItem(pages[TAB_CONFIG], IDCINPUT), n);
214 terminx 389
 
991 terminx 390
    EnableWindow(GetDlgItem(pages[TAB_CONFIG], IDCDATA), n);
391
    EnableWindow(GetDlgItem(pages[TAB_CONFIG], IDCGAMEDIR), n);
194 terminx 392
}
393
 
394
static INT_PTR CALLBACK startup_dlgproc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
395
{
222 terminx 396
    static HBITMAP hbmp = NULL;
397
    HDC hdc;
194 terminx 398
 
335 terminx 399
    switch (uMsg)
400
    {
337 terminx 401
    case WM_INITDIALOG:
402
    {
403
        HWND hwnd;
404
        RECT r, rdlg, chrome, rtab, rcancel, rstart;
1205 terminx 405
        int32_t xoffset = 0, yoffset = 0;
194 terminx 406
 
337 terminx 407
        // Fetch the positions (in screen coordinates) of all the windows we need to tweak
408
        ZeroMemory(&chrome, sizeof(chrome));
409
        AdjustWindowRect(&chrome, GetWindowLong(hwndDlg, GWL_STYLE), FALSE);
410
        GetWindowRect(hwndDlg, &rdlg);
411
        GetWindowRect(GetDlgItem(hwndDlg, WIN_STARTWIN_TABCTL), &rtab);
412
        GetWindowRect(GetDlgItem(hwndDlg, WIN_STARTWIN_CANCEL), &rcancel);
413
        GetWindowRect(GetDlgItem(hwndDlg, WIN_STARTWIN_START), &rstart);
194 terminx 414
 
337 terminx 415
        // Knock off the non-client area of the main dialogue to give just the client area
416
        rdlg.left -= chrome.left;
417
        rdlg.top -= chrome.top;
418
        rdlg.right -= chrome.right;
419
        rdlg.bottom -= chrome.bottom;
194 terminx 420
 
337 terminx 421
        // Translate them to client-relative coordinates wrt the main dialogue window
422
        rtab.right -= rtab.left - 1;
423
        rtab.bottom -= rtab.top - 1;
424
        rtab.left  -= rdlg.left;
425
        rtab.top -= rdlg.top;
194 terminx 426
 
337 terminx 427
        rcancel.right -= rcancel.left - 1;
428
        rcancel.bottom -= rcancel.top - 1;
429
        rcancel.left -= rdlg.left;
430
        rcancel.top -= rdlg.top;
194 terminx 431
 
337 terminx 432
        rstart.right -= rstart.left - 1;
433
        rstart.bottom -= rstart.top - 1;
434
        rstart.left -= rdlg.left;
435
        rstart.top -= rdlg.top;
194 terminx 436
 
337 terminx 437
        // And then convert the main dialogue coordinates to just width/length
438
        rdlg.right -= rdlg.left - 1;
439
        rdlg.bottom -= rdlg.top - 1;
440
        rdlg.left = 0;
441
        rdlg.top = 0;
194 terminx 442
 
337 terminx 443
        // Load the bitmap into the bitmap control and fetch its dimensions
444
        hbmp = LoadBitmap((HINSTANCE)win_gethinstance(), MAKEINTRESOURCE(RSRC_BMP));
445
        hwnd = GetDlgItem(hwndDlg,WIN_STARTWIN_BITMAP);
446
        SendMessage(hwnd, STM_SETIMAGE, IMAGE_BITMAP, (LPARAM)hbmp);
447
        GetClientRect(hwnd, &r);
448
        xoffset = r.right;
449
        yoffset = r.bottom - rdlg.bottom;
194 terminx 450
 
337 terminx 451
        // Shift and resize the controls that require it
452
        rtab.left += xoffset;
453
        rtab.bottom += yoffset;
454
        rcancel.left += xoffset;
455
        rcancel.top += yoffset;
456
        rstart.left += xoffset;
457
        rstart.top += yoffset;
458
        rdlg.right += xoffset;
459
        rdlg.bottom += yoffset;
194 terminx 460
 
337 terminx 461
        // Move the controls to their new positions
462
        MoveWindow(GetDlgItem(hwndDlg, WIN_STARTWIN_TABCTL), rtab.left, rtab.top, rtab.right, rtab.bottom, FALSE);
463
        MoveWindow(GetDlgItem(hwndDlg, WIN_STARTWIN_CANCEL), rcancel.left, rcancel.top, rcancel.right, rcancel.bottom, FALSE);
464
        MoveWindow(GetDlgItem(hwndDlg, WIN_STARTWIN_START), rstart.left, rstart.top, rstart.right, rstart.bottom, FALSE);
194 terminx 465
 
337 terminx 466
        // Move the main dialogue to the centre of the screen
467
        hdc = GetDC(NULL);
468
        rdlg.left = (GetDeviceCaps(hdc, HORZRES) - rdlg.right) / 2;
469
        rdlg.top = (GetDeviceCaps(hdc, VERTRES) - rdlg.bottom) / 2;
470
        ReleaseDC(NULL, hdc);
471
        MoveWindow(hwndDlg, rdlg.left + chrome.left, rdlg.top + chrome.left,
472
                   rdlg.right + (-chrome.left+chrome.right), rdlg.bottom + (-chrome.top+chrome.bottom), TRUE);
194 terminx 473
 
337 terminx 474
        // Add tabs to the tab control
475
        {
476
            TCITEM tab;
194 terminx 477
 
337 terminx 478
            hwnd = GetDlgItem(hwndDlg, WIN_STARTWIN_TABCTL);
194 terminx 479
 
337 terminx 480
            ZeroMemory(&tab, sizeof(tab));
481
            tab.mask = TCIF_TEXT;
1188 terminx 482
            tab.pszText = TEXT("Setup");
337 terminx 483
            SendMessage(hwnd, TCM_INSERTITEM, (WPARAM)TAB_CONFIG, (LPARAM)&tab);
484
            tab.mask = TCIF_TEXT;
1188 terminx 485
            tab.pszText = TEXT("Message Log");
337 terminx 486
            SendMessage(hwnd, TCM_INSERTITEM, (WPARAM)TAB_MESSAGES, (LPARAM)&tab);
194 terminx 487
 
337 terminx 488
            // Work out the position and size of the area inside the tab control for the pages
489
            ZeroMemory(&r, sizeof(r));
490
            GetClientRect(hwnd, &r);
491
            SendMessage(hwnd, TCM_ADJUSTRECT, FALSE, (LPARAM)&r);
492
            r.right -= r.left-1;
493
            r.bottom -= r.top-1;
494
            r.top += rtab.top;
495
            r.left += rtab.left;
194 terminx 496
 
337 terminx 497
            // Create the pages and position them in the tab control, but hide them
498
            pages[TAB_CONFIG] = CreateDialog((HINSTANCE)win_gethinstance(),
499
                                             MAKEINTRESOURCE(WIN_STARTWINPAGE_CONFIG), hwndDlg, ConfigPageProc);
500
            pages[TAB_MESSAGES] = GetDlgItem(hwndDlg, WIN_STARTWIN_MESSAGES);
501
            SetWindowPos(pages[TAB_CONFIG], hwnd,r.left,r.top,r.right,r.bottom,SWP_HIDEWINDOW);
502
            SetWindowPos(pages[TAB_MESSAGES], hwnd,r.left,r.top,r.right,r.bottom,SWP_HIDEWINDOW);
194 terminx 503
 
337 terminx 504
            // Tell the editfield acting as the console to exclude the width of the scrollbar
505
            GetClientRect(pages[TAB_MESSAGES],&r);
506
            r.right -= GetSystemMetrics(SM_CXVSCROLL)+4;
507
            r.left = r.top = 0;
508
            SendMessage(pages[TAB_MESSAGES], EM_SETRECTNP,0,(LPARAM)&r);
194 terminx 509
 
337 terminx 510
            // Set a tab stop in the game data listbox
511
            {
512
                DWORD tabs[1] = { 150 };
991 terminx 513
                (void)ListBox_SetTabStops(GetDlgItem(pages[TAB_CONFIG], IDCDATA), 1, tabs);
337 terminx 514
            }
335 terminx 515
 
337 terminx 516
            SetFocus(GetDlgItem(hwndDlg, WIN_STARTWIN_START));
517
            SetWindowText(hwndDlg, apptitle);
335 terminx 518
        }
337 terminx 519
        return FALSE;
520
    }
335 terminx 521
 
337 terminx 522
    case WM_NOTIFY:
523
    {
524
        LPNMHDR nmhdr = (LPNMHDR)lParam;
1205 terminx 525
        int32_t cur;
337 terminx 526
        if (nmhdr->idFrom != WIN_STARTWIN_TABCTL) break;
1205 terminx 527
        cur = (int32_t)SendMessage(nmhdr->hwndFrom, TCM_GETCURSEL,0,0);
337 terminx 528
        switch (nmhdr->code)
335 terminx 529
        {
337 terminx 530
        case TCN_SELCHANGING:
531
        {
532
            if (cur < 0 || !pages[cur]) break;
533
            ShowWindow(pages[cur],SW_HIDE);
534
            return TRUE;
222 terminx 535
        }
337 terminx 536
        case TCN_SELCHANGE:
537
        {
538
            if (cur < 0 || !pages[cur]) break;
539
            ShowWindow(pages[cur],SW_SHOW);
331 terminx 540
            return TRUE;
337 terminx 541
        }
542
        }
543
        break;
544
    }
194 terminx 545
 
337 terminx 546
    case WM_CLOSE:
547
        if (mode == TAB_CONFIG) done = 0;
548
        else quitevent++;
549
        return TRUE;
194 terminx 550
 
337 terminx 551
    case WM_DESTROY:
552
        if (hbmp)
553
        {
554
            DeleteObject(hbmp);
555
            hbmp = NULL;
556
        }
194 terminx 557
 
337 terminx 558
        if (pages[TAB_CONFIG])
559
        {
560
            DestroyWindow(pages[TAB_CONFIG]);
561
            pages[TAB_CONFIG] = NULL;
562
        }
563
 
564
        startupdlg = NULL;
565
        return TRUE;
566
 
567
    case WM_COMMAND:
568
        switch (LOWORD(wParam))
569
        {
570
        case WIN_STARTWIN_CANCEL:
571
            if (mode == TAB_CONFIG) done = 0;
572
            else quitevent++;
335 terminx 573
            return TRUE;
337 terminx 574
        case WIN_STARTWIN_START:
575
            done = 1;
576
            return TRUE;
577
        }
578
        return FALSE;
194 terminx 579
 
337 terminx 580
    case WM_CTLCOLORSTATIC:
581
        if ((HWND)lParam == pages[TAB_MESSAGES])
582
            return (BOOL)GetSysColorBrush(COLOR_WINDOW);
583
        break;
194 terminx 584
 
337 terminx 585
    default:
586
        break;
222 terminx 587
    }
588
 
589
    return FALSE;
194 terminx 590
}
591
 
592
 
1205 terminx 593
int32_t startwin_open(void)
194 terminx 594
{
222 terminx 595
    INITCOMMONCONTROLSEX icc;
596
    if (startupdlg) return 1;
597
    icc.dwSize = sizeof(icc);
598
    icc.dwICC = ICC_TAB_CLASSES;
599
    InitCommonControlsEx(&icc);
600
    startupdlg = CreateDialog((HINSTANCE)win_gethinstance(), MAKEINTRESOURCE(WIN_STARTWIN), NULL, startup_dlgproc);
335 terminx 601
    if (startupdlg)
602
    {
222 terminx 603
        SetPage(TAB_MESSAGES);
604
        EnableConfig(0);
605
        return 0;
606
    }
607
    return -1;
194 terminx 608
}
609
 
1205 terminx 610
int32_t startwin_close(void)
194 terminx 611
{
222 terminx 612
    if (!startupdlg) return 1;
613
    DestroyWindow(startupdlg);
614
    startupdlg = NULL;
615
    return 0;
194 terminx 616
}
617
 
1205 terminx 618
int32_t startwin_puts(const char *buf)
194 terminx 619
{
222 terminx 620
    const char *p = NULL, *q = NULL;
851 terminx 621
    static char workbuf[1024];
1205 terminx 622
    static int32_t newline = 0;
623
    int32_t curlen, linesbefore, linesafter;
222 terminx 624
    HWND edctl;
1205 terminx 625
    int32_t vis;
851 terminx 626
    static HWND dactrl = NULL;
194 terminx 627
 
222 terminx 628
    if (!startupdlg) return 1;
194 terminx 629
 
222 terminx 630
    edctl = pages[TAB_MESSAGES];
631
    if (!edctl) return -1;
194 terminx 632
 
851 terminx 633
    if (!dactrl) dactrl = GetDlgItem(startupdlg, WIN_STARTWIN_TABCTL);
222 terminx 634
 
1205 terminx 635
    vis = ((int32_t)SendMessage(dactrl, TCM_GETCURSEL,0,0) == TAB_MESSAGES);
851 terminx 636
 
222 terminx 637
    if (vis) SendMessage(edctl, WM_SETREDRAW, FALSE,0);
638
    curlen = SendMessage(edctl, WM_GETTEXTLENGTH, 0,0);
639
    SendMessage(edctl, EM_SETSEL, (WPARAM)curlen, (LPARAM)curlen);
640
    linesbefore = SendMessage(edctl, EM_GETLINECOUNT, 0,0);
641
    p = buf;
335 terminx 642
    while (*p)
643
    {
644
        if (newline)
645
        {
222 terminx 646
            SendMessage(edctl, EM_REPLACESEL, 0, (LPARAM)"\r\n");
647
            newline = 0;
648
        }
649
        q = p;
650
        while (*q && *q != '\n') q++;
1425 terminx 651
        Bmemcpy(workbuf, p, q-p);
335 terminx 652
        if (*q == '\n')
653
        {
654
            if (!q[1])
655
            {
222 terminx 656
                newline = 1;
657
                workbuf[q-p] = 0;
335 terminx 658
            }
659
            else
660
            {
222 terminx 661
                workbuf[q-p] = '\r';
662
                workbuf[q-p+1] = '\n';
663
                workbuf[q-p+2] = 0;
664
            }
665
            p = q+1;
335 terminx 666
        }
667
        else
668
        {
222 terminx 669
            workbuf[q-p] = 0;
670
            p = q;
671
        }
672
        SendMessage(edctl, EM_REPLACESEL, 0, (LPARAM)workbuf);
673
    }
674
    linesafter = SendMessage(edctl, EM_GETLINECOUNT, 0,0);
675
    SendMessage(edctl, EM_LINESCROLL, 0, linesafter-linesbefore);
676
    if (vis) SendMessage(edctl, WM_SETREDRAW, TRUE,0);
677
    return 0;
194 terminx 678
}
679
 
1205 terminx 680
int32_t startwin_settitle(const char *str)
194 terminx 681
{
222 terminx 682
    if (!startupdlg) return 1;
683
    SetWindowText(startupdlg, str);
684
    return 0;
194 terminx 685
}
686
 
1205 terminx 687
int32_t startwin_idle(void *v)
194 terminx 688
{
222 terminx 689
    if (!startupdlg || !IsWindow(startupdlg)) return 0;
690
    if (IsDialogMessage(startupdlg, (MSG*)v)) return 1;
691
    return 0;
194 terminx 692
}
693
 
1205 terminx 694
int32_t startwin_run(void)
194 terminx 695
{
222 terminx 696
    MSG msg;
697
    if (!startupdlg) return 1;
194 terminx 698
 
222 terminx 699
    done = -1;
194 terminx 700
 
219 terminx 701
#ifdef JFAUD
222 terminx 702
    EnumAudioDevs(&wavedevs, NULL, NULL);
219 terminx 703
#endif
222 terminx 704
    SetPage(TAB_CONFIG);
705
    EnableConfig(1);
194 terminx 706
 
1326 terminx 707
    settings.flags = 0;
708
    if (ud.config.ScreenMode) settings.flags |= 1;
1325 terminx 709
    if (glrendmode == 4) settings.flags |= 2;
1326 terminx 710
    if (ud.config.NoAutoLoad) settings.flags |= 4;
563 terminx 711
    settings.xdim = ud.config.ScreenWidth;
712
    settings.ydim = ud.config.ScreenHeight;
713
    settings.bpp = ud.config.ScreenBPP;
714
    settings.forcesetup = ud.config.ForceSetup;
715
    settings.usemouse = ud.config.UseMouse;
716
    settings.usejoy = ud.config.UseJoystick;
1143 terminx 717
    settings.game = g_gameType;
886 terminx 718
//    settings.crcval = 0;
1221 terminx 719
    Bstrncpy(settings.selectedgrp, duke3dgrp, BMAX_PATH);
984 terminx 720
    settings.gamedir = mod_dir;
222 terminx 721
    PopulateForm(-1);
194 terminx 722
 
335 terminx 723
    while (done < 0)
724
    {
725
        switch (GetMessage(&msg, NULL, 0,0))
726
        {
337 terminx 727
        case 0:
728
            done = 1;
729
            break;
730
        case -1:
731
            return -1;
732
        default:
733
            if (IsWindow(startupdlg) && IsDialogMessage(startupdlg, &msg)) break;
734
            TranslateMessage(&msg);
735
            DispatchMessage(&msg);
736
            break;
222 terminx 737
        }
738
    }
194 terminx 739
 
222 terminx 740
    SetPage(TAB_MESSAGES);
741
    EnableConfig(0);
335 terminx 742
    if (done)
743
    {
1205 terminx 744
        int32_t i;
886 terminx 745
 
1325 terminx 746
        ud.config.ScreenMode = (settings.flags&1);
747
        if (settings.flags & 2) glrendmode = 4;
748
        else glrendmode = 3;
1326 terminx 749
        if (settings.flags & 4) ud.config.NoAutoLoad = 1;
750
        else ud.config.NoAutoLoad = 0;
563 terminx 751
        ud.config.ScreenWidth = settings.xdim;
752
        ud.config.ScreenHeight = settings.ydim;
753
        ud.config.ScreenBPP = settings.bpp;
754
        ud.config.ForceSetup = settings.forcesetup;
755
        ud.config.UseMouse = settings.usemouse;
756
        ud.config.UseJoystick = settings.usejoy;
222 terminx 757
        duke3dgrp = settings.selectedgrp;
1143 terminx 758
        g_gameType = settings.game;
990 terminx 759
 
1143 terminx 760
        if (g_noSetup == 0 && settings.gamedir != NULL)
984 terminx 761
            Bstrcpy(mod_dir,settings.gamedir);
989 terminx 762
        else Bsprintf(mod_dir,"/");
886 terminx 763
 
764
        for (i = 0; i<numgrpfiles; i++) if (settings.crcval == grpfiles[i].crcval) break;
765
        if (i != numgrpfiles)
766
            duke3dgrpstring = (char *)grpfiles[i].name;
222 terminx 767
    }
194 terminx 768
 
335 terminx 769
    if (wavedevs)
770
    {
222 terminx 771
        struct audioenumdev *d, *e;
772
        free(wavedevs->drvs);
335 terminx 773
        for (e=wavedevs->devs; e; e=d)
774
        {
222 terminx 775
            d = e->next;
776
            if (e->devs) free(e->devs);
777
            free(e);
778
        }
779
        free(wavedevs);
780
    }
219 terminx 781
 
222 terminx 782
    return done;
194 terminx 783
}
784