ViewVC Help
View File | Revision Log | Show Annotations | Revision Graph | Root Listing
root/cebix/Frodo4/Src/Prefs_WIN32.h
Revision: 1.1
Committed: 2003-07-01T17:36:32Z (20 years, 9 months ago) by cebix
Content type: text/plain
Branch: MAIN
Log Message:
imported files

File Contents

# Content
1 /*
2 * Prefs_WIN32.h - Global preferences, WIN32 specific stuff
3 *
4 * Frodo (C) 1994-1997,2002 Christian Bauer
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21 #include <commctrl.h>
22 #include "resource.h"
23
24 Prefs *Prefs::edit_prefs;
25 char *Prefs::edit_prefs_name;
26 HWND Prefs::hDlg;
27
28 #define STANDARD_PAGE 0
29 #define WIN32_PAGE 1
30
31 bool Prefs::ShowEditor(bool /* startup */, char *prefs_name)
32 {
33 edit_prefs = this;
34 edit_prefs_name = prefs_name;
35
36 PROPSHEETPAGE psp[2];
37
38 // Set up standard preferences property page.
39 psp[0].dwSize = sizeof(PROPSHEETPAGE);
40 psp[0].dwFlags = PSP_HASHELP;
41 psp[0].hInstance = hInstance;
42 psp[0].pszTemplate = MAKEINTRESOURCE(IDD_PREFERENCES_STANDARD);
43 psp[0].pszIcon = NULL;
44 psp[0].pfnDlgProc = StandardDialogProc;
45 psp[0].pszTitle = NULL;
46 psp[0].lParam = 0;
47 psp[0].pfnCallback = NULL;
48
49 // Set up WIN32 preferences property page.
50 psp[1].dwSize = sizeof(PROPSHEETPAGE);
51 psp[1].dwFlags = PSP_HASHELP;
52 psp[1].hInstance = hInstance;
53 psp[1].pszTemplate = MAKEINTRESOURCE(IDD_PREFERENCES_WIN32);
54 psp[1].pszIcon = NULL;
55 psp[1].pfnDlgProc = WIN32DialogProc;
56 psp[1].pszTitle = NULL;
57 psp[1].lParam = 0;
58 psp[1].pfnCallback = NULL;
59
60 // Setup property sheet.
61 PROPSHEETHEADER psh;
62 psh.dwSize = sizeof(PROPSHEETHEADER);
63 psh.dwFlags = PSH_PROPSHEETPAGE | PSH_NOAPPLYNOW;
64 psh.hwndParent = hwnd;
65 psh.hInstance = hInstance;
66 psh.pszIcon = NULL;
67 psh.pszCaption = "Preferences";
68 psh.nPages = sizeof(psp) / sizeof(PROPSHEETPAGE);
69 psh.nStartPage = 0;
70 psh.ppsp = psp;
71 psh.pfnCallback = NULL;
72
73 int result = PropertySheet(&psh);
74
75 if (result == -1)
76 return FALSE;
77 return result;
78 }
79
80 BOOL CALLBACK Prefs::StandardDialogProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
81 {
82 return edit_prefs->DialogProc(STANDARD_PAGE, hDlg, message, wParam, lParam);
83 }
84
85 BOOL CALLBACK Prefs::WIN32DialogProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
86 {
87 return edit_prefs->DialogProc(WIN32_PAGE, hDlg, message, wParam, lParam);
88 }
89
90 BOOL Prefs::DialogProc(int page, HWND hDlg_arg, UINT message, WPARAM wParam, LPARAM lParam)
91 {
92 hDlg = hDlg_arg;
93
94 switch (message) {
95
96 case WM_INITDIALOG:
97 SetupControls(page);
98 SetValues(page);
99 return TRUE;
100
101 case WM_COMMAND:
102 switch (LOWORD(wParam)) {
103
104 case IDC_BROWSE8:
105 BrowseForDevice(IDC_DEVICE8);
106 break;
107
108 case IDC_BROWSE9:
109 BrowseForDevice(IDC_DEVICE9);
110 break;
111
112 case IDC_BROWSE10:
113 BrowseForDevice(IDC_DEVICE10);
114 break;
115
116 case IDC_BROWSE11:
117 BrowseForDevice(IDC_DEVICE11);
118 break;
119
120 }
121 return TRUE;
122
123 case WM_NOTIFY:
124 {
125 NMHDR *pnmhdr = (NMHDR *) lParam;
126 switch (pnmhdr->code) {
127
128 case PSN_KILLACTIVE:
129 SetWindowLong(hDlg, DWL_MSGRESULT, FALSE);
130 break;
131
132 case PSN_APPLY:
133 GetValues(page);
134 break;
135
136 case PSN_HELP:
137 PostMessage(hwnd, WM_COMMAND, ID_HELP_SETTINGS, 0);
138 break;
139 }
140 }
141 return TRUE;
142 }
143
144 return FALSE;
145 }
146
147 #define SetupSpin(id, upper, lower) SendMessage(GetDlgItem(hDlg, id), UDM_SETRANGE, 0, MAKELONG(upper, lower))
148 #define SetupSpinIncrement(id, increment) (udaccel.nSec = 0, udaccel.nInc = increment, SendMessage(GetDlgItem(hDlg, id), UDM_SETACCEL, 1, (LPARAM) &udaccel))
149 #define SetupComboClear(id) SendMessage(GetDlgItem(hDlg, id), CB_RESETCONTENT, 0, 0)
150 #define SetupComboAdd(id, string) SendMessage(GetDlgItem(hDlg, id), CB_ADDSTRING, 0, (LPARAM) string)
151
152 void Prefs::SetupControls(int page)
153 {
154 UDACCEL udaccel;
155 switch (page) {
156
157 case STANDARD_PAGE:
158 SetupSpin(IDC_NORMAL_SPIN, 200, 1);
159 SetupSpin(IDC_BADLINES_SPIN, 200, 1);
160 SetupSpin(IDC_CIA_SPIN, 200, 1);
161 SetupSpin(IDC_FLOPPY_SPIN, 200, 1);
162 SetupSpin(IDC_DRAWEVERY_SPIN, 10, 1);
163 SetupComboClear(IDC_REUSIZE);
164 SetupComboAdd(IDC_REUSIZE, "None");
165 SetupComboAdd(IDC_REUSIZE, "128k");
166 SetupComboAdd(IDC_REUSIZE, "256k");
167 SetupComboAdd(IDC_REUSIZE, "512k");
168 break;
169
170 case WIN32_PAGE:
171 SetupComboClear(IDC_VIEWPORT);
172 SetupComboAdd(IDC_VIEWPORT, "Default");
173 SetupComboAdd(IDC_VIEWPORT, "320x200");
174 SetupComboAdd(IDC_VIEWPORT, "336x216");
175 SetupComboAdd(IDC_VIEWPORT, "384x272");
176 SetupComboClear(IDC_DISPLAYMODE);
177 SetupComboAdd(IDC_DISPLAYMODE, "Default");
178 {
179 C64Display *TheDisplay = TheApp->TheC64->TheDisplay;
180 int n = TheDisplay->GetNumDisplayModes();
181 const C64Display::DisplayMode *modes =
182 TheDisplay->GetDisplayModes();
183 for (int i = 0; i < n; i++) {
184 char mode[64];
185 sprintf(mode, "%dx%dx%d%s",
186 modes[i].x, modes[i].y, modes[i].depth,
187 modes[i].modex ? " (ModeX)" : "");
188 SetupComboAdd(IDC_DISPLAYMODE, mode);
189 }
190 }
191 SetupSpin(IDC_SCALINGNUMERATOR_SPIN, 16, 1);
192 SetupSpin(IDC_SCALINGDENOMINATOR_SPIN, 4, 1);
193 SetupSpin(IDC_LATENCYMIN_SPIN, 1000, 20);
194 SetupSpinIncrement(IDC_LATENCYMIN_SPIN, 20);
195 SetupSpin(IDC_LATENCYMAX_SPIN, 1000, 20);
196 SetupSpinIncrement(IDC_LATENCYMAX_SPIN, 20);
197 SetupSpin(IDC_LATENCYAVG_SPIN, 1000, 20);
198 SetupSpinIncrement(IDC_LATENCYAVG_SPIN, 20);
199 break;
200 }
201 }
202
203 #define SetText(id, val) SetDlgItemText(hDlg, id, val)
204 #define SetInteger(id, val) SetDlgItemInt(hDlg, id, val, FALSE)
205 #define SetCheckBox(id, val) CheckDlgButton(hDlg, id, (val) ? BST_CHECKED : BST_UNCHECKED)
206 #define SetCombo(id, val) SendMessage(GetDlgItem(hDlg, id), CB_SELECTSTRING, 0, (LPARAM) val)
207
208 void Prefs::SetValues(int page)
209 {
210 const char *str;
211 switch (page) {
212
213 case STANDARD_PAGE:
214 SetText(IDC_DEVICE8, DrivePath[0]);
215 SetText(IDC_DEVICE9, DrivePath[1]);
216 SetText(IDC_DEVICE10, DrivePath[2]);
217 SetText(IDC_DEVICE11, DrivePath[3]);
218
219 SetInteger(IDC_NORMAL, NormalCycles);
220 SetInteger(IDC_BADLINES, BadLineCycles);
221 SetInteger(IDC_CIA, CIACycles);
222 SetInteger(IDC_FLOPPY, FloppyCycles);
223 SetInteger(IDC_DRAWEVERY, SkipFrames);
224 switch (REUSize) {
225 case REU_NONE: str = "None"; break;
226 case REU_128K: str = "128k"; break;
227 case REU_256K: str = "256k"; break;
228 case REU_512K: str = "512k"; break;
229 }
230 SetCombo(IDC_REUSIZE, str);
231
232 SetCheckBox(IDC_LIMITSPEED, LimitSpeed);
233 SetCheckBox(IDC_SPRITES, SpritesOn);
234 SetCheckBox(IDC_SPRITECOLLISIONS, SpriteCollisions);
235 SetCheckBox(IDC_JOYSTICK1, Joystick1On);
236 SetCheckBox(IDC_JOYSTICK2, Joystick2On);
237 SetCheckBox(IDC_SWAPJOYSTICKS, JoystickSwap);
238 SetCheckBox(IDC_FASTRESET, FastReset);
239 SetCheckBox(IDC_CIAIRQHACK, CIAIRQHack);
240 SetCheckBox(IDC_MAPSLASH, MapSlash);
241 SetCheckBox(IDC_SIDEMULATION, SIDType == SIDTYPE_DIGITAL);
242 SetCheckBox(IDC_SIDFILTERS, SIDFilters);
243 SetCheckBox(IDC_1541EMULATION, Emul1541Proc);
244 break;
245
246 case WIN32_PAGE:
247 SetCheckBox(IDC_FULLSCREEN, DisplayType == DISPTYPE_SCREEN);
248 SetCheckBox(IDC_SYSTEMMEMORY, SystemMemory);
249 SetCheckBox(IDC_ALWAYSCOPY, AlwaysCopy);
250 SetText(IDC_VIEWPORT, ViewPort);
251 SetText(IDC_DISPLAYMODE, DisplayMode);
252
253 SetCheckBox(IDC_HIDECURSOR, HideCursor);
254 SetCheckBox(IDC_SYSTEMKEYS, SystemKeys);
255 SetInteger(IDC_SCALINGNUMERATOR, ScalingNumerator);
256 SetInteger(IDC_SCALINGDENOMINATOR, ScalingDenominator);
257
258 SetCheckBox(IDC_DIRECTSOUND, DirectSound);
259 SetCheckBox(IDC_EXCLUSIVESOUND, ExclusiveSound);
260 SetInteger(IDC_LATENCYMIN, LatencyMin);
261 SetInteger(IDC_LATENCYMAX, LatencyMax);
262 SetInteger(IDC_LATENCYAVG, LatencyAvg);
263
264 SetCheckBox(IDC_AUTOPAUSE, AutoPause);
265 SetCheckBox(IDC_PREFSATSTARTUP, PrefsAtStartup);
266 SetCheckBox(IDC_SHOWLEDS, ShowLEDs);
267 break;
268 }
269 }
270
271 #define GetCheckBox(id, val) (val = IsDlgButtonChecked(hDlg, id) == BST_CHECKED)
272 #define GetInteger(id, val) (val = GetDlgItemInt(hDlg, id, NULL, FALSE))
273 #define GetText(id, val) GetDlgItemText(hDlg, id, val, sizeof(val))
274
275 void Prefs::GetValues(int page)
276 {
277 BOOL temp;
278 char str[256];
279 switch (page) {
280
281 case STANDARD_PAGE:
282 GetText(IDC_DEVICE8, DrivePath[0]);
283 GetText(IDC_DEVICE9, DrivePath[1]);
284 GetText(IDC_DEVICE10, DrivePath[2]);
285 GetText(IDC_DEVICE11, DrivePath[3]);
286
287 GetInteger(IDC_NORMAL, NormalCycles);
288 GetInteger(IDC_BADLINES, BadLineCycles);
289 GetInteger(IDC_CIA, CIACycles);
290 GetInteger(IDC_FLOPPY, FloppyCycles);
291 GetInteger(IDC_DRAWEVERY, SkipFrames);
292 GetText(IDC_REUSIZE, str);
293 if (strcmp(str, "None") == 0)
294 REUSize = REU_NONE;
295 else if (strcmp(str, "128k") == 0)
296 REUSize = REU_128K;
297 else if (strcmp(str, "256k") == 0)
298 REUSize = REU_256K;
299 else if (strcmp(str, "512k") == 0)
300 REUSize = REU_512K;
301
302 GetCheckBox(IDC_LIMITSPEED, LimitSpeed);
303 GetCheckBox(IDC_SPRITES, SpritesOn);
304 GetCheckBox(IDC_SPRITECOLLISIONS, SpriteCollisions);
305 GetCheckBox(IDC_JOYSTICK1, Joystick1On);
306 GetCheckBox(IDC_JOYSTICK2, Joystick2On);
307 GetCheckBox(IDC_SWAPJOYSTICKS, JoystickSwap);
308 GetCheckBox(IDC_FASTRESET, FastReset);
309 GetCheckBox(IDC_CIAIRQHACK, CIAIRQHack);
310 GetCheckBox(IDC_MAPSLASH, MapSlash);
311 GetCheckBox(IDC_SIDEMULATION, temp);
312 SIDType = temp ? SIDTYPE_DIGITAL : SIDTYPE_NONE;
313 GetCheckBox(IDC_SIDFILTERS, SIDFilters);
314 GetCheckBox(IDC_1541EMULATION, Emul1541Proc);
315 break;
316
317 case WIN32_PAGE:
318 GetCheckBox(IDC_FULLSCREEN, temp);
319 DisplayType = temp ? DISPTYPE_SCREEN : DISPTYPE_WINDOW;
320 GetCheckBox(IDC_SYSTEMMEMORY, SystemMemory);
321 GetCheckBox(IDC_ALWAYSCOPY, AlwaysCopy);
322 GetText(IDC_VIEWPORT, ViewPort);
323 GetText(IDC_DISPLAYMODE, DisplayMode);
324
325 GetCheckBox(IDC_HIDECURSOR, HideCursor);
326 GetCheckBox(IDC_SYSTEMKEYS, SystemKeys);
327 GetInteger(IDC_SCALINGNUMERATOR, ScalingNumerator);
328 GetInteger(IDC_SCALINGDENOMINATOR, ScalingDenominator);
329
330 GetCheckBox(IDC_DIRECTSOUND, DirectSound);
331 GetCheckBox(IDC_EXCLUSIVESOUND, ExclusiveSound);
332 GetInteger(IDC_LATENCYMIN, LatencyMin);
333 GetInteger(IDC_LATENCYMAX, LatencyMax);
334 GetInteger(IDC_LATENCYAVG, LatencyAvg);
335
336 GetCheckBox(IDC_AUTOPAUSE, AutoPause);
337 GetCheckBox(IDC_PREFSATSTARTUP, PrefsAtStartup);
338 GetCheckBox(IDC_SHOWLEDS, ShowLEDs);
339 break;
340 }
341
342 for (int i = 0; i < 4; i++) {
343 DriveType[i] = DRVTYPE_DIR;
344 int length = strlen(DrivePath[i]);
345 if (length >= 4) {
346 char *suffix = DrivePath[i] + length - 4;
347 if (stricmp(suffix, ".t64") == 0)
348 DriveType[i] = DRVTYPE_T64;
349 else if (stricmp(suffix, ".d64") == 0)
350 DriveType[i] = DRVTYPE_D64;
351 }
352 }
353 }
354
355 void Prefs::BrowseForDevice(int id)
356 {
357 char filename[256];
358 GetDlgItemText(hDlg, id, filename, sizeof(filename));
359 OPENFILENAME ofn;
360 memset(&ofn, 0, sizeof(ofn));
361 ofn.lStructSize = sizeof(ofn);
362 ofn.hwndOwner = hDlg;
363 ofn.hInstance = hInstance;
364 ofn.lpstrFilter =
365 "All Files (*.*)\0*.*\0"
366 "All C64 Files (*.d64;*.t64)\0*.d64;*.t64\0"
367 "D64 Files (*.d64)\0*.d64\0"
368 "T64 Files (*.t64)\0*.t64\0"
369 ;
370 ofn.lpstrCustomFilter = NULL;
371 ofn.nMaxCustFilter = 0;
372 ofn.nFilterIndex = 1;
373 ofn.lpstrFile = filename;
374 ofn.nMaxFile = sizeof(filename);
375 ofn.lpstrFileTitle = NULL;
376 ofn.nMaxFileTitle = 0;
377 ofn.lpstrInitialDir = NULL;
378 ofn.lpstrTitle = "Set Device";
379 ofn.Flags = OFN_EXPLORER | OFN_HIDEREADONLY | OFN_NOTESTFILECREATE |
380 OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR | OFN_SHAREAWARE;
381 ofn.nFileOffset = 0;
382 ofn.nFileExtension = 0;
383 ofn.lpstrDefExt = NULL;
384 ofn.lpfnHook = NULL;
385 ofn.lpTemplateName = NULL;
386 BOOL result = GetOpenFileName(&ofn);
387 if (result) {
388 const char *ext = filename + ofn.nFileExtension;
389 if (stricmp(ext, "d64") != 0 && stricmp(ext, "t64") != 0)
390 filename[ofn.nFileOffset - 1] = '\0';
391 char cwd[256];
392 GetCurrentDirectory(sizeof(cwd), cwd);
393 int cwd_len = strlen(cwd);
394 if (cwd_len > 0 && cwd[cwd_len - 1] != '\\') {
395 strcat(cwd, "\\");
396 cwd_len++;
397 }
398 if (strnicmp(filename, cwd, cwd_len) == 0)
399 SetDlgItemText(hDlg, id, filename + cwd_len);
400 else
401 SetDlgItemText(hDlg, id, filename);
402 }
403 }