Main Page | Class Hierarchy | Compound List | File List | Compound Members | File Members | Related Pages

Prefs_WIN32.i

Go to the documentation of this file.
00001 /*
00002  *  Prefs_WIN32.i - Global preferences, WIN32 specific stuff
00003  *
00004  *  Frodo (C) 1994-1997 Christian Bauer
00005  *  WIN32 code by J. Richard Sladkey <jrs@world.std.com>
00006  */
00007 
00008 #include <commctrl.h>
00009 #include "resource.h"
00010 
00011 Prefs *Prefs::edit_prefs;
00012 char *Prefs::edit_prefs_name;
00013 HWND Prefs::hDlg;
00014 
00015 #define STANDARD_PAGE   0
00016 #define WIN32_PAGE      1
00017 
00018 bool Prefs::ShowEditor(bool /* startup */, char *prefs_name)
00019 {
00020         edit_prefs = this;
00021         edit_prefs_name = prefs_name;
00022 
00023         PROPSHEETPAGE psp[2];
00024 
00025         // Set up standard preferences property page.
00026         psp[0].dwSize = sizeof(PROPSHEETPAGE);
00027         psp[0].dwFlags = PSP_HASHELP;
00028         psp[0].hInstance = hInstance;
00029         psp[0].pszTemplate = MAKEINTRESOURCE(IDD_PREFERENCES_STANDARD);
00030         psp[0].pszIcon = NULL;
00031         psp[0].pfnDlgProc = StandardDialogProc;
00032         psp[0].pszTitle = NULL;
00033         psp[0].lParam = 0;
00034         psp[0].pfnCallback = NULL;
00035 
00036         // Set up WIN32 preferences property page.
00037         psp[1].dwSize = sizeof(PROPSHEETPAGE);
00038         psp[1].dwFlags = PSP_HASHELP;
00039         psp[1].hInstance = hInstance;
00040         psp[1].pszTemplate = MAKEINTRESOURCE(IDD_PREFERENCES_WIN32);
00041         psp[1].pszIcon = NULL;
00042         psp[1].pfnDlgProc = WIN32DialogProc;
00043         psp[1].pszTitle = NULL;
00044         psp[1].lParam = 0;
00045         psp[1].pfnCallback = NULL;
00046 
00047         // Setup property sheet.
00048         PROPSHEETHEADER psh;
00049         psh.dwSize = sizeof(PROPSHEETHEADER);
00050         psh.dwFlags = PSH_PROPSHEETPAGE | PSH_NOAPPLYNOW;
00051         psh.hwndParent = hwnd;
00052         psh.hInstance = hInstance;
00053         psh.pszIcon = NULL;
00054         psh.pszCaption = "Preferences";
00055         psh.nPages = sizeof(psp) / sizeof(PROPSHEETPAGE);
00056         psh.nStartPage = 0;
00057         psh.ppsp = psp;
00058         psh.pfnCallback = NULL;
00059 
00060         int result = PropertySheet(&psh);
00061 
00062         if (result == -1)
00063                 return FALSE;
00064         return result;
00065 }
00066 
00067 BOOL CALLBACK Prefs::StandardDialogProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
00068 {
00069         return edit_prefs->DialogProc(STANDARD_PAGE, hDlg, message, wParam, lParam);
00070 }
00071 
00072 BOOL CALLBACK Prefs::WIN32DialogProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
00073 {
00074         return edit_prefs->DialogProc(WIN32_PAGE, hDlg, message, wParam, lParam);
00075 }
00076 
00077 BOOL Prefs::DialogProc(int page, HWND hDlg_arg, UINT message, WPARAM wParam, LPARAM lParam)
00078 {
00079         hDlg = hDlg_arg;
00080 
00081         switch (message) {
00082 
00083         case WM_INITDIALOG:
00084                 SetupControls(page);
00085                 SetValues(page);
00086                 return TRUE;
00087 
00088         case WM_COMMAND:
00089                 switch (LOWORD(wParam)) {
00090 
00091                 case IDC_BROWSE8:
00092                         BrowseForDevice(IDC_DEVICE8);
00093                         break;
00094 
00095                 case IDC_BROWSE9:
00096                         BrowseForDevice(IDC_DEVICE9);
00097                         break;
00098 
00099                 case IDC_BROWSE10:
00100                         BrowseForDevice(IDC_DEVICE10);
00101                         break;
00102 
00103                 case IDC_BROWSE11:
00104                         BrowseForDevice(IDC_DEVICE11);
00105                         break;
00106 
00107                 }
00108                 return TRUE;
00109 
00110         case WM_NOTIFY:
00111                 {
00112                         NMHDR *pnmhdr = (NMHDR *) lParam;
00113                         switch (pnmhdr->code) {
00114 
00115                         case PSN_KILLACTIVE:
00116                                 SetWindowLong(hDlg, DWL_MSGRESULT, FALSE);
00117                                 break;
00118 
00119                         case PSN_APPLY:
00120                                 GetValues(page);
00121                                 break;
00122 
00123                         case PSN_HELP:
00124                                 PostMessage(hwnd, WM_COMMAND, ID_HELP_SETTINGS, 0);
00125                                 break;
00126                         }
00127                 }
00128                 return TRUE;
00129         }
00130 
00131         return FALSE;
00132 }
00133 
00134 #define SetupSpin(id, upper, lower) SendMessage(GetDlgItem(hDlg, id), UDM_SETRANGE, 0, MAKELONG(upper, lower))
00135 #define SetupSpinIncrement(id, increment) (udaccel.nSec = 0, udaccel.nInc = increment, SendMessage(GetDlgItem(hDlg, id), UDM_SETACCEL, 1, (LPARAM) &udaccel))
00136 #define SetupComboClear(id) SendMessage(GetDlgItem(hDlg, id), CB_RESETCONTENT, 0, 0)
00137 #define SetupComboAdd(id, string) SendMessage(GetDlgItem(hDlg, id), CB_ADDSTRING, 0, (LPARAM) string)
00138 
00139 void Prefs::SetupControls(int page)
00140 {
00141         UDACCEL udaccel;
00142         switch (page) {
00143 
00144         case STANDARD_PAGE:
00145                 SetupSpin(IDC_NORMAL_SPIN, 200, 1);
00146                 SetupSpin(IDC_BADLINES_SPIN, 200, 1);
00147                 SetupSpin(IDC_CIA_SPIN, 200, 1);
00148                 SetupSpin(IDC_FLOPPY_SPIN, 200, 1);
00149                 SetupSpin(IDC_DRAWEVERY_SPIN, 10, 1);
00150                 SetupComboClear(IDC_REUSIZE);
00151                 SetupComboAdd(IDC_REUSIZE, "None");
00152                 SetupComboAdd(IDC_REUSIZE, "128k");
00153                 SetupComboAdd(IDC_REUSIZE, "256k");
00154                 SetupComboAdd(IDC_REUSIZE, "512k");
00155                 break;
00156 
00157         case WIN32_PAGE:
00158                 SetupComboClear(IDC_VIEWPORT);
00159                 SetupComboAdd(IDC_VIEWPORT, "Default");
00160                 SetupComboAdd(IDC_VIEWPORT, "320x200");
00161                 SetupComboAdd(IDC_VIEWPORT, "336x216");
00162                 SetupComboAdd(IDC_VIEWPORT, "384x272");
00163                 SetupComboClear(IDC_DISPLAYMODE);
00164                 SetupComboAdd(IDC_DISPLAYMODE, "Default");
00165                 {
00166                         C64Display *TheDisplay = TheApp->TheC64->TheDisplay;
00167                         int n = TheDisplay->GetNumDisplayModes();
00168                         const C64Display::DisplayMode *modes =
00169                                 TheDisplay->GetDisplayModes();
00170                         for (int i = 0; i < n; i++) {
00171                                 char mode[64];
00172                                 sprintf(mode, "%dx%dx%d%s",
00173                                         modes[i].x, modes[i].y, modes[i].depth,
00174                                         modes[i].modex ? " (ModeX)" : "");
00175                                 SetupComboAdd(IDC_DISPLAYMODE, mode);
00176                         }
00177                 }
00178                 SetupSpin(IDC_SCALINGNUMERATOR_SPIN, 16, 1);
00179                 SetupSpin(IDC_SCALINGDENOMINATOR_SPIN, 4, 1);
00180                 SetupSpin(IDC_LATENCYMIN_SPIN, 1000, 20);
00181                 SetupSpinIncrement(IDC_LATENCYMIN_SPIN, 20);
00182                 SetupSpin(IDC_LATENCYMAX_SPIN, 1000, 20);
00183                 SetupSpinIncrement(IDC_LATENCYMAX_SPIN, 20);
00184                 SetupSpin(IDC_LATENCYAVG_SPIN, 1000, 20);
00185                 SetupSpinIncrement(IDC_LATENCYAVG_SPIN, 20);
00186                 break;
00187         }
00188 }
00189 
00190 #define SetText(id, val) SetDlgItemText(hDlg, id, val)
00191 #define SetInteger(id, val) SetDlgItemInt(hDlg, id, val, FALSE)
00192 #define SetCheckBox(id, val) CheckDlgButton(hDlg, id, (val) ? BST_CHECKED : BST_UNCHECKED)
00193 #define SetCombo(id, val) SendMessage(GetDlgItem(hDlg, id), CB_SELECTSTRING, 0, (LPARAM) val)
00194 
00195 void Prefs::SetValues(int page)
00196 {
00197         const char *str;
00198         switch (page) {
00199 
00200         case STANDARD_PAGE:
00201                 SetText(IDC_DEVICE8, DrivePath[0]);
00202                 SetText(IDC_DEVICE9, DrivePath[1]);
00203                 SetText(IDC_DEVICE10, DrivePath[2]);
00204                 SetText(IDC_DEVICE11, DrivePath[3]);
00205 
00206                 SetInteger(IDC_NORMAL, NormalCycles);
00207                 SetInteger(IDC_BADLINES, BadLineCycles);
00208                 SetInteger(IDC_CIA, CIACycles);
00209                 SetInteger(IDC_FLOPPY, FloppyCycles);
00210                 SetInteger(IDC_DRAWEVERY, SkipFrames);
00211                 switch (REUSize) {
00212                 case REU_NONE: str = "None"; break;
00213                 case REU_128K: str = "128k"; break;
00214                 case REU_256K: str = "256k"; break;
00215                 case REU_512K: str = "512k"; break;
00216                 }
00217                 SetCombo(IDC_REUSIZE, str);
00218 
00219                 SetCheckBox(IDC_LIMITSPEED, LimitSpeed);
00220                 SetCheckBox(IDC_SPRITES, SpritesOn);
00221                 SetCheckBox(IDC_SPRITECOLLISIONS, SpriteCollisions);
00222                 SetCheckBox(IDC_JOYSTICK1, Joystick1On);
00223                 SetCheckBox(IDC_JOYSTICK2, Joystick2On);
00224                 SetCheckBox(IDC_SWAPJOYSTICKS, JoystickSwap);
00225                 SetCheckBox(IDC_FASTRESET, FastReset);
00226                 SetCheckBox(IDC_CIAIRQHACK, CIAIRQHack);
00227                 SetCheckBox(IDC_MAPSLASH, MapSlash);
00228                 SetCheckBox(IDC_SIDEMULATION, SIDType == SIDTYPE_DIGITAL);
00229                 SetCheckBox(IDC_SIDFILTERS, SIDFilters);
00230                 SetCheckBox(IDC_1541EMULATION, Emul1541Proc);
00231                 break;
00232 
00233         case WIN32_PAGE:
00234                 SetCheckBox(IDC_FULLSCREEN, DisplayType == DISPTYPE_SCREEN);
00235                 SetCheckBox(IDC_SYSTEMMEMORY, SystemMemory);
00236                 SetCheckBox(IDC_ALWAYSCOPY, AlwaysCopy);
00237                 SetText(IDC_VIEWPORT, ViewPort);
00238                 SetText(IDC_DISPLAYMODE, DisplayMode);
00239 
00240                 SetCheckBox(IDC_HIDECURSOR, HideCursor);
00241                 SetCheckBox(IDC_SYSTEMKEYS, SystemKeys);
00242                 SetInteger(IDC_SCALINGNUMERATOR, ScalingNumerator);
00243                 SetInteger(IDC_SCALINGDENOMINATOR, ScalingDenominator);
00244 
00245                 SetCheckBox(IDC_DIRECTSOUND, DirectSound);
00246                 SetCheckBox(IDC_EXCLUSIVESOUND, ExclusiveSound);
00247                 SetInteger(IDC_LATENCYMIN, LatencyMin);
00248                 SetInteger(IDC_LATENCYMAX, LatencyMax);
00249                 SetInteger(IDC_LATENCYAVG, LatencyAvg);
00250 
00251                 SetCheckBox(IDC_AUTOPAUSE, AutoPause);
00252                 SetCheckBox(IDC_PREFSATSTARTUP, PrefsAtStartup);
00253                 SetCheckBox(IDC_SHOWLEDS, ShowLEDs);
00254                 break;
00255         }
00256 }
00257 
00258 #define GetCheckBox(id, val) (val = IsDlgButtonChecked(hDlg, id) == BST_CHECKED)
00259 #define GetInteger(id, val) (val = GetDlgItemInt(hDlg, id, NULL, FALSE))
00260 #define GetText(id, val) GetDlgItemText(hDlg, id, val, sizeof(val))
00261 
00262 void Prefs::GetValues(int page)
00263 {
00264         BOOL temp;
00265         char str[256];
00266         switch (page) {
00267 
00268         case STANDARD_PAGE:
00269                 GetText(IDC_DEVICE8, DrivePath[0]);
00270                 GetText(IDC_DEVICE9, DrivePath[1]);
00271                 GetText(IDC_DEVICE10, DrivePath[2]);
00272                 GetText(IDC_DEVICE11, DrivePath[3]);
00273 
00274                 GetInteger(IDC_NORMAL, NormalCycles);
00275                 GetInteger(IDC_BADLINES, BadLineCycles);
00276                 GetInteger(IDC_CIA, CIACycles);
00277                 GetInteger(IDC_FLOPPY, FloppyCycles);
00278                 GetInteger(IDC_DRAWEVERY, SkipFrames);
00279                 GetText(IDC_REUSIZE, str);
00280                 if (strcmp(str, "None") == 0)
00281                         REUSize = REU_NONE;
00282                 else if (strcmp(str, "128k") == 0)
00283                         REUSize = REU_128K;
00284                 else if (strcmp(str, "256k") == 0)
00285                         REUSize = REU_256K;
00286                 else if (strcmp(str, "512k") == 0)
00287                         REUSize = REU_512K;
00288 
00289                 GetCheckBox(IDC_LIMITSPEED, LimitSpeed);
00290                 GetCheckBox(IDC_SPRITES, SpritesOn);
00291                 GetCheckBox(IDC_SPRITECOLLISIONS, SpriteCollisions);
00292                 GetCheckBox(IDC_JOYSTICK1, Joystick1On);
00293                 GetCheckBox(IDC_JOYSTICK2, Joystick2On);
00294                 GetCheckBox(IDC_SWAPJOYSTICKS, JoystickSwap);
00295                 GetCheckBox(IDC_FASTRESET, FastReset);
00296                 GetCheckBox(IDC_CIAIRQHACK, CIAIRQHack);
00297                 GetCheckBox(IDC_MAPSLASH, MapSlash);
00298                 GetCheckBox(IDC_SIDEMULATION, temp);
00299                 SIDType = temp ? SIDTYPE_DIGITAL : SIDTYPE_NONE;
00300                 GetCheckBox(IDC_SIDFILTERS, SIDFilters);
00301                 GetCheckBox(IDC_1541EMULATION, Emul1541Proc);
00302                 break;
00303 
00304         case WIN32_PAGE:
00305                 GetCheckBox(IDC_FULLSCREEN, temp);
00306                 DisplayType = temp ? DISPTYPE_SCREEN : DISPTYPE_WINDOW;
00307                 GetCheckBox(IDC_SYSTEMMEMORY, SystemMemory);
00308                 GetCheckBox(IDC_ALWAYSCOPY, AlwaysCopy);
00309                 GetText(IDC_VIEWPORT, ViewPort);
00310                 GetText(IDC_DISPLAYMODE, DisplayMode);
00311 
00312                 GetCheckBox(IDC_HIDECURSOR, HideCursor);
00313                 GetCheckBox(IDC_SYSTEMKEYS, SystemKeys);
00314                 GetInteger(IDC_SCALINGNUMERATOR, ScalingNumerator);
00315                 GetInteger(IDC_SCALINGDENOMINATOR, ScalingDenominator);
00316 
00317                 GetCheckBox(IDC_DIRECTSOUND, DirectSound);
00318                 GetCheckBox(IDC_EXCLUSIVESOUND, ExclusiveSound);
00319                 GetInteger(IDC_LATENCYMIN, LatencyMin);
00320                 GetInteger(IDC_LATENCYMAX, LatencyMax);
00321                 GetInteger(IDC_LATENCYAVG, LatencyAvg);
00322 
00323                 GetCheckBox(IDC_AUTOPAUSE, AutoPause);
00324                 GetCheckBox(IDC_PREFSATSTARTUP, PrefsAtStartup);
00325                 GetCheckBox(IDC_SHOWLEDS, ShowLEDs);
00326                 break;
00327         }
00328 
00329         for (int i = 0; i < 4; i++) {
00330                 DriveType[i] = DRVTYPE_DIR;
00331                 int length = strlen(DrivePath[i]);
00332                 if (length >= 4) {
00333                         char *suffix = DrivePath[i] + length - 4;
00334                         if (stricmp(suffix, ".t64") == 0)
00335                                 DriveType[i] = DRVTYPE_T64;
00336                         else if (stricmp(suffix, ".d64") == 0)
00337                                 DriveType[i] = DRVTYPE_D64;
00338                 }
00339         }
00340 }
00341 
00342 void Prefs::BrowseForDevice(int id)
00343 {
00344         char filename[256];
00345         GetDlgItemText(hDlg, id, filename, sizeof(filename));
00346         OPENFILENAME ofn;
00347         memset(&ofn, 0, sizeof(ofn));
00348         ofn.lStructSize = sizeof(ofn);
00349         ofn.hwndOwner = hDlg;
00350         ofn.hInstance = hInstance;
00351         ofn.lpstrFilter =
00352                 "All Files (*.*)\0*.*\0"
00353                 "All C64 Files (*.d64;*.t64)\0*.d64;*.t64\0"
00354                 "D64 Files (*.d64)\0*.d64\0"
00355                 "T64 Files (*.t64)\0*.t64\0"
00356                 ;
00357         ofn.lpstrCustomFilter = NULL;
00358         ofn.nMaxCustFilter = 0;
00359         ofn.nFilterIndex = 1;
00360         ofn.lpstrFile = filename;
00361         ofn.nMaxFile = sizeof(filename);
00362         ofn.lpstrFileTitle = NULL;
00363         ofn.nMaxFileTitle = 0;
00364         ofn.lpstrInitialDir = NULL;
00365         ofn.lpstrTitle = "Set Device";
00366         ofn.Flags = OFN_EXPLORER | OFN_HIDEREADONLY | OFN_NOTESTFILECREATE |
00367                 OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR | OFN_SHAREAWARE;
00368         ofn.nFileOffset = 0;
00369         ofn.nFileExtension = 0;
00370         ofn.lpstrDefExt = NULL;
00371         ofn.lpfnHook = NULL;
00372         ofn.lpTemplateName = NULL;
00373         BOOL result = GetOpenFileName(&ofn);
00374         if (result) {
00375                 const char *ext = filename + ofn.nFileExtension;
00376                 if (stricmp(ext, "d64") != 0 && stricmp(ext, "t64") != 0)
00377                         filename[ofn.nFileOffset - 1] = '\0';
00378                 char cwd[256];
00379                 GetCurrentDirectory(sizeof(cwd), cwd);
00380                 int cwd_len = strlen(cwd);
00381                 if (cwd_len > 0 && cwd[cwd_len - 1] != '\\') {
00382                         strcat(cwd, "\\");
00383                         cwd_len++;
00384                 }
00385                 if (strnicmp(filename, cwd, cwd_len) == 0)
00386                         SetDlgItemText(hDlg, id, filename + cwd_len);
00387                 else
00388                         SetDlgItemText(hDlg, id, filename);
00389         }
00390 }

Generated on Tue Feb 8 04:08:05 2005 for E32frodo by doxygen 1.3.3