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