Subversion Repositories eduke32

Rev

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