Subversion Repositories eduke32

Rev

Rev 886 | Rev 985 | 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
 
52
void clearfilenames(void)
53
{
54
    klistfree(finddirs);
55
    finddirs = NULL;
56
    numdirs = 0;
57
}
58
 
59
int getfilenames(char *path)
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
984 terminx 72
#define POPULATE_MODS 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
 
174
    if (pgs & POPULATE_MODS)
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);
184
        for (dirs=finddirs,i=1; dirs != NULL; dirs=dirs->next,i++)
185
        {
186
            Bsprintf(buf, "%s", dirs->name);
187
            j = ComboBox_AddString(hwnd, buf);
188
            (void)ComboBox_SetItemData(hwnd, j, i);
189
            if (Bstrcmp(dirs->name,settings.gamedir) == 0)(void)ComboBox_SetCurSel(hwnd, j);
190
        }
191
    }
194 terminx 192
}
193
 
194
static INT_PTR CALLBACK ConfigPageProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
195
{
335 terminx 196
    switch (uMsg)
197
    {
337 terminx 198
    case WM_COMMAND:
199
        switch (LOWORD(wParam))
200
        {
201
        case IDCFULLSCREEN:
202
            settings.fullscreen = !settings.fullscreen;
203
            PopulateForm(POPULATE_VIDEO);
204
            return TRUE;
205
        case IDCVMODE:
206
            if (HIWORD(wParam) == CBN_SELCHANGE)
335 terminx 207
            {
337 terminx 208
                int i;
209
                i = ComboBox_GetCurSel((HWND)lParam);
210
                if (i != CB_ERR) i = ComboBox_GetItemData((HWND)lParam, i);
211
                if (i != CB_ERR)
212
                {
213
                    settings.xdim = validmode[i].xdim;
214
                    settings.ydim = validmode[i].ydim;
215
                    settings.bpp  = validmode[i].bpp;
216
                }
222 terminx 217
            }
337 terminx 218
            return TRUE;
219
        case IDCALWAYSSHOW:
220
            settings.forcesetup = IsDlgButtonChecked(hwndDlg, IDCALWAYSSHOW) == BST_CHECKED;
221
            return TRUE;
222
        case IDCINPUTMOUSE:
223
            settings.usemouse = IsDlgButtonChecked(hwndDlg, IDCINPUTMOUSE) == BST_CHECKED;
224
            return TRUE;
225
        case IDCINPUTJOY:
226
            settings.usejoy = IsDlgButtonChecked(hwndDlg, IDCINPUTJOY) == BST_CHECKED;
227
            return TRUE;
331 terminx 228
        default:
229
            break;
337 terminx 230
        }
231
        break;
232
    default:
233
        break;
222 terminx 234
    }
235
    return FALSE;
194 terminx 236
}
237
 
214 terminx 238
static INT_PTR CALLBACK GamePageProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
239
{
654 terminx 240
    UNREFERENCED_PARAMETER(hwndDlg);
335 terminx 241
    switch (uMsg)
242
    {
337 terminx 243
    case WM_COMMAND:
244
        switch (LOWORD(wParam))
245
        {
246
        case IDGDATA:
247
        {
248
            int i;
249
            if (HIWORD(wParam) != LBN_SELCHANGE) break;
250
            i = ListBox_GetCurSel((HWND)lParam);
251
            if (i != CB_ERR) i = ListBox_GetItemData((HWND)lParam, i);
252
            if (i != CB_ERR)
335 terminx 253
            {
337 terminx 254
                strcpy(settings.selectedgrp, ((struct grpfile*)i)->name);
255
                settings.game = ((struct grpfile*)i)->game;
886 terminx 256
                settings.crcval = ((struct grpfile*)i)->crcval;
222 terminx 257
            }
337 terminx 258
            return TRUE;
259
        }
984 terminx 260
        case IDGGAMEDIR:
261
            if (HIWORD(wParam) == CBN_SELCHANGE)
262
            {
263
                int i,j;
264
                CACHE1D_FIND_REC *dir = NULL;
265
                i = ComboBox_GetCurSel((HWND)lParam);
266
                if (i != CB_ERR) i = ComboBox_GetItemData((HWND)lParam, i);
267
                if (i != CB_ERR)
268
                {
269
                    for (j=0,dir=finddirs;dir != NULL;dir=dir->next,j++)
270
                        if (j == i)
271
                        {
272
                            if (i==0) settings.gamedir = NULL;
273
                            else settings.gamedir = dir->prev->name;
274
                            break;
275
                        }
276
                }
277
            }
278
            return TRUE;
331 terminx 279
        default:
280
            break;
337 terminx 281
        }
282
        break;
283
    default:
284
        break;
222 terminx 285
    }
286
    return FALSE;
214 terminx 287
}
194 terminx 288
 
289
 
214 terminx 290
 
194 terminx 291
static void SetPage(int n)
292
{
222 terminx 293
    HWND tab;
294
    int cur;
295
    tab = GetDlgItem(startupdlg, WIN_STARTWIN_TABCTL);
296
    cur = (int)SendMessage(tab, TCM_GETCURSEL,0,0);
297
    ShowWindow(pages[cur],SW_HIDE);
298
    SendMessage(tab, TCM_SETCURSEL, n, 0);
299
    ShowWindow(pages[n],SW_SHOW);
300
    mode = n;
196 terminx 301
 
222 terminx 302
    SetFocus(GetDlgItem(startupdlg, WIN_STARTWIN_TABCTL));
194 terminx 303
}
304
 
305
static void EnableConfig(int n)
306
{
222 terminx 307
    //EnableWindow(GetDlgItem(startupdlg, WIN_STARTWIN_CANCEL), n);
308
    EnableWindow(GetDlgItem(startupdlg, WIN_STARTWIN_START), n);
309
    EnableWindow(GetDlgItem(pages[TAB_CONFIG], IDCFULLSCREEN), n);
310
    EnableWindow(GetDlgItem(pages[TAB_CONFIG], IDCVMODE), n);
311
    EnableWindow(GetDlgItem(pages[TAB_CONFIG], IDCINPUTMOUSE), n);
312
    EnableWindow(GetDlgItem(pages[TAB_CONFIG], IDCINPUTJOY), n);
214 terminx 313
 
222 terminx 314
    EnableWindow(GetDlgItem(pages[TAB_GAME], IDGDATA), n);
984 terminx 315
    EnableWindow(GetDlgItem(pages[TAB_GAME], IDGGAMEDIR), n);
194 terminx 316
}
317
 
318
static INT_PTR CALLBACK startup_dlgproc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
319
{
222 terminx 320
    static HBITMAP hbmp = NULL;
321
    HDC hdc;
194 terminx 322
 
335 terminx 323
    switch (uMsg)
324
    {
337 terminx 325
    case WM_INITDIALOG:
326
    {
327
        HWND hwnd;
328
        RECT r, rdlg, chrome, rtab, rcancel, rstart;
329
        int xoffset = 0, yoffset = 0;
194 terminx 330
 
337 terminx 331
        // Fetch the positions (in screen coordinates) of all the windows we need to tweak
332
        ZeroMemory(&chrome, sizeof(chrome));
333
        AdjustWindowRect(&chrome, GetWindowLong(hwndDlg, GWL_STYLE), FALSE);
334
        GetWindowRect(hwndDlg, &rdlg);
335
        GetWindowRect(GetDlgItem(hwndDlg, WIN_STARTWIN_TABCTL), &rtab);
336
        GetWindowRect(GetDlgItem(hwndDlg, WIN_STARTWIN_CANCEL), &rcancel);
337
        GetWindowRect(GetDlgItem(hwndDlg, WIN_STARTWIN_START), &rstart);
194 terminx 338
 
337 terminx 339
        // Knock off the non-client area of the main dialogue to give just the client area
340
        rdlg.left -= chrome.left;
341
        rdlg.top -= chrome.top;
342
        rdlg.right -= chrome.right;
343
        rdlg.bottom -= chrome.bottom;
194 terminx 344
 
337 terminx 345
        // Translate them to client-relative coordinates wrt the main dialogue window
346
        rtab.right -= rtab.left - 1;
347
        rtab.bottom -= rtab.top - 1;
348
        rtab.left  -= rdlg.left;
349
        rtab.top -= rdlg.top;
194 terminx 350
 
337 terminx 351
        rcancel.right -= rcancel.left - 1;
352
        rcancel.bottom -= rcancel.top - 1;
353
        rcancel.left -= rdlg.left;
354
        rcancel.top -= rdlg.top;
194 terminx 355
 
337 terminx 356
        rstart.right -= rstart.left - 1;
357
        rstart.bottom -= rstart.top - 1;
358
        rstart.left -= rdlg.left;
359
        rstart.top -= rdlg.top;
194 terminx 360
 
337 terminx 361
        // And then convert the main dialogue coordinates to just width/length
362
        rdlg.right -= rdlg.left - 1;
363
        rdlg.bottom -= rdlg.top - 1;
364
        rdlg.left = 0;
365
        rdlg.top = 0;
194 terminx 366
 
337 terminx 367
        // Load the bitmap into the bitmap control and fetch its dimensions
368
        hbmp = LoadBitmap((HINSTANCE)win_gethinstance(), MAKEINTRESOURCE(RSRC_BMP));
369
        hwnd = GetDlgItem(hwndDlg,WIN_STARTWIN_BITMAP);
370
        SendMessage(hwnd, STM_SETIMAGE, IMAGE_BITMAP, (LPARAM)hbmp);
371
        GetClientRect(hwnd, &r);
372
        xoffset = r.right;
373
        yoffset = r.bottom - rdlg.bottom;
194 terminx 374
 
337 terminx 375
        // Shift and resize the controls that require it
376
        rtab.left += xoffset;
377
        rtab.bottom += yoffset;
378
        rcancel.left += xoffset;
379
        rcancel.top += yoffset;
380
        rstart.left += xoffset;
381
        rstart.top += yoffset;
382
        rdlg.right += xoffset;
383
        rdlg.bottom += yoffset;
194 terminx 384
 
337 terminx 385
        // Move the controls to their new positions
386
        MoveWindow(GetDlgItem(hwndDlg, WIN_STARTWIN_TABCTL), rtab.left, rtab.top, rtab.right, rtab.bottom, FALSE);
387
        MoveWindow(GetDlgItem(hwndDlg, WIN_STARTWIN_CANCEL), rcancel.left, rcancel.top, rcancel.right, rcancel.bottom, FALSE);
388
        MoveWindow(GetDlgItem(hwndDlg, WIN_STARTWIN_START), rstart.left, rstart.top, rstart.right, rstart.bottom, FALSE);
194 terminx 389
 
337 terminx 390
        // Move the main dialogue to the centre of the screen
391
        hdc = GetDC(NULL);
392
        rdlg.left = (GetDeviceCaps(hdc, HORZRES) - rdlg.right) / 2;
393
        rdlg.top = (GetDeviceCaps(hdc, VERTRES) - rdlg.bottom) / 2;
394
        ReleaseDC(NULL, hdc);
395
        MoveWindow(hwndDlg, rdlg.left + chrome.left, rdlg.top + chrome.left,
396
                   rdlg.right + (-chrome.left+chrome.right), rdlg.bottom + (-chrome.top+chrome.bottom), TRUE);
194 terminx 397
 
337 terminx 398
        // Add tabs to the tab control
399
        {
400
            TCITEM tab;
194 terminx 401
 
337 terminx 402
            hwnd = GetDlgItem(hwndDlg, WIN_STARTWIN_TABCTL);
194 terminx 403
 
337 terminx 404
            ZeroMemory(&tab, sizeof(tab));
405
            tab.mask = TCIF_TEXT;
406
            tab.pszText = TEXT("Configuration");
407
            SendMessage(hwnd, TCM_INSERTITEM, (WPARAM)TAB_CONFIG, (LPARAM)&tab);
408
            tab.mask = TCIF_TEXT;
409
            tab.pszText = TEXT("Game");
410
            SendMessage(hwnd, TCM_INSERTITEM, (WPARAM)TAB_GAME, (LPARAM)&tab);
411
            tab.mask = TCIF_TEXT;
412
            tab.pszText = TEXT("Messages");
413
            SendMessage(hwnd, TCM_INSERTITEM, (WPARAM)TAB_MESSAGES, (LPARAM)&tab);
194 terminx 414
 
337 terminx 415
            // Work out the position and size of the area inside the tab control for the pages
416
            ZeroMemory(&r, sizeof(r));
417
            GetClientRect(hwnd, &r);
418
            SendMessage(hwnd, TCM_ADJUSTRECT, FALSE, (LPARAM)&r);
419
            r.right -= r.left-1;
420
            r.bottom -= r.top-1;
421
            r.top += rtab.top;
422
            r.left += rtab.left;
194 terminx 423
 
337 terminx 424
            // Create the pages and position them in the tab control, but hide them
425
            pages[TAB_CONFIG] = CreateDialog((HINSTANCE)win_gethinstance(),
426
                                             MAKEINTRESOURCE(WIN_STARTWINPAGE_CONFIG), hwndDlg, ConfigPageProc);
427
            pages[TAB_GAME] = CreateDialog((HINSTANCE)win_gethinstance(),
428
                                           MAKEINTRESOURCE(WIN_STARTWINPAGE_GAME), hwndDlg, GamePageProc);
429
            pages[TAB_MESSAGES] = GetDlgItem(hwndDlg, WIN_STARTWIN_MESSAGES);
430
            SetWindowPos(pages[TAB_CONFIG], hwnd,r.left,r.top,r.right,r.bottom,SWP_HIDEWINDOW);
431
            SetWindowPos(pages[TAB_GAME], hwnd,r.left,r.top,r.right,r.bottom,SWP_HIDEWINDOW);
432
            SetWindowPos(pages[TAB_MESSAGES], hwnd,r.left,r.top,r.right,r.bottom,SWP_HIDEWINDOW);
194 terminx 433
 
337 terminx 434
            // Tell the editfield acting as the console to exclude the width of the scrollbar
435
            GetClientRect(pages[TAB_MESSAGES],&r);
436
            r.right -= GetSystemMetrics(SM_CXVSCROLL)+4;
437
            r.left = r.top = 0;
438
            SendMessage(pages[TAB_MESSAGES], EM_SETRECTNP,0,(LPARAM)&r);
194 terminx 439
 
337 terminx 440
            // Set a tab stop in the game data listbox
441
            {
442
                DWORD tabs[1] = { 150 };
649 terminx 443
                (void)ListBox_SetTabStops(GetDlgItem(pages[TAB_GAME], IDGDATA), 1, tabs);
337 terminx 444
            }
335 terminx 445
 
337 terminx 446
            SetFocus(GetDlgItem(hwndDlg, WIN_STARTWIN_START));
447
            SetWindowText(hwndDlg, apptitle);
335 terminx 448
        }
337 terminx 449
        return FALSE;
450
    }
335 terminx 451
 
337 terminx 452
    case WM_NOTIFY:
453
    {
454
        LPNMHDR nmhdr = (LPNMHDR)lParam;
455
        int cur;
456
        if (nmhdr->idFrom != WIN_STARTWIN_TABCTL) break;
457
        cur = (int)SendMessage(nmhdr->hwndFrom, TCM_GETCURSEL,0,0);
458
        switch (nmhdr->code)
335 terminx 459
        {
337 terminx 460
        case TCN_SELCHANGING:
461
        {
462
            if (cur < 0 || !pages[cur]) break;
463
            ShowWindow(pages[cur],SW_HIDE);
464
            return TRUE;
222 terminx 465
        }
337 terminx 466
        case TCN_SELCHANGE:
467
        {
468
            if (cur < 0 || !pages[cur]) break;
469
            ShowWindow(pages[cur],SW_SHOW);
331 terminx 470
            return TRUE;
337 terminx 471
        }
472
        }
473
        break;
474
    }
194 terminx 475
 
337 terminx 476
    case WM_CLOSE:
477
        if (mode == TAB_CONFIG) done = 0;
478
        else quitevent++;
479
        return TRUE;
194 terminx 480
 
337 terminx 481
    case WM_DESTROY:
482
        if (hbmp)
483
        {
484
            DeleteObject(hbmp);
485
            hbmp = NULL;
486
        }
194 terminx 487
 
337 terminx 488
        if (pages[TAB_GAME])
489
        {
490
            DestroyWindow(pages[TAB_GAME]);
491
            pages[TAB_GAME] = NULL;
492
        }
214 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
 
529
int startwin_open(void)
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
 
546
int startwin_close(void)
547
{
222 terminx 548
    if (!startupdlg) return 1;
549
    DestroyWindow(startupdlg);
550
    startupdlg = NULL;
551
    return 0;
194 terminx 552
}
553
 
554
int startwin_puts(const char *buf)
555
{
222 terminx 556
    const char *p = NULL, *q = NULL;
851 terminx 557
    static char workbuf[1024];
222 terminx 558
    static int newline = 0;
559
    int curlen, linesbefore, linesafter;
560
    HWND edctl;
561
    int 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
 
851 terminx 571
    vis = ((int)SendMessage(dactrl, TCM_GETCURSEL,0,0) == TAB_MESSAGES);
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
 
616
int startwin_settitle(const char *str)
617
{
222 terminx 618
    if (!startupdlg) return 1;
619
    SetWindowText(startupdlg, str);
620
    return 0;
194 terminx 621
}
622
 
623
int startwin_idle(void *v)
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
 
886 terminx 630
extern char *duke3dgrp, *duke3dgrpstring;
984 terminx 631
extern char mod_dir[BMAX_PATH];
214 terminx 632
 
194 terminx 633
int startwin_run(void)
634
{
222 terminx 635
    MSG msg;
636
    if (!startupdlg) return 1;
194 terminx 637
 
222 terminx 638
    done = -1;
194 terminx 639
 
219 terminx 640
#ifdef JFAUD
222 terminx 641
    EnumAudioDevs(&wavedevs, NULL, NULL);
219 terminx 642
#endif
222 terminx 643
    SetPage(TAB_CONFIG);
644
    EnableConfig(1);
194 terminx 645
 
563 terminx 646
    settings.fullscreen = ud.config.ScreenMode;
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;
561 terminx 653
    settings.game = g_GameType;
886 terminx 654
//    settings.crcval = 0;
222 terminx 655
    strncpy(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
    {
886 terminx 680
        int i;
681
 
563 terminx 682
        ud.config.ScreenMode = settings.fullscreen;
683
        ud.config.ScreenWidth = settings.xdim;
684
        ud.config.ScreenHeight = settings.ydim;
685
        ud.config.ScreenBPP = settings.bpp;
686
        ud.config.ForceSetup = settings.forcesetup;
687
        ud.config.UseMouse = settings.usemouse;
688
        ud.config.UseJoystick = settings.usejoy;
222 terminx 689
        duke3dgrp = settings.selectedgrp;
561 terminx 690
        g_GameType = settings.game;
984 terminx 691
        if (settings.gamedir)
692
        {
693
            addsearchpath(settings.gamedir);
694
            Bstrcpy(mod_dir,settings.gamedir);
695
        }
886 terminx 696
 
697
        for (i = 0; i<numgrpfiles; i++) if (settings.crcval == grpfiles[i].crcval) break;
698
        if (i != numgrpfiles)
699
            duke3dgrpstring = (char *)grpfiles[i].name;
222 terminx 700
    }
194 terminx 701
 
335 terminx 702
    if (wavedevs)
703
    {
222 terminx 704
        struct audioenumdev *d, *e;
705
        free(wavedevs->drvs);
335 terminx 706
        for (e=wavedevs->devs; e; e=d)
707
        {
222 terminx 708
            d = e->next;
709
            if (e->devs) free(e->devs);
710
            free(e);
711
        }
712
        free(wavedevs);
713
    }
219 terminx 714
 
222 terminx 715
    return done;
194 terminx 716
}
717