Subversion Repositories eduke32

Rev

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