Subversion Repositories eduke32

Rev

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