Subversion Repositories eduke32

Rev

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