Subversion Repositories eduke32

Rev

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