Subversion Repositories eduke32

Rev

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