Subversion Repositories eduke32

Rev

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