Subversion Repositories eduke32

Rev

Rev 5062 | Details | Compare with Previous | Last modification | View Log | RSS feed

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