Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

925 lines
26 KiB

  1. /*****************************************************************************\
  2. FILE: config.cpp
  3. DESCRIPTION:
  4. The class will handle the user's configuration state. It will also
  5. display the Screen Saver's configuration dialog to allow the user to change
  6. these settings.
  7. BryanSt 12/18/2000
  8. Copyright (C) Microsoft Corp 2000-2001. All rights reserved.
  9. \*****************************************************************************/
  10. #include "stdafx.h"
  11. #include <shlobj.h>
  12. #include "config.h"
  13. #include "resource.h"
  14. #define SZ_REGKEY_THISSCREENSAVER TEXT("Software\\Microsoft\\Screensavers\\Museum")
  15. #define SZ_REGKEY_THISSS_CONFIG SZ_REGKEY_THISSCREENSAVER TEXT("\\Config")
  16. #define SZ_REGVALUE_QUALITYSLIDER TEXT("Quality Slider")
  17. #define SZ_REGVALUE_SPEEDSLIDER TEXT("Speed Slider")
  18. #define SZ_REGVALUE_TEMPMB TEXT("Temp Disk Space")
  19. #define SZ_REGVALUE_WALKSPEED TEXT("Walk Speed")
  20. #define SZ_REGVALUE_OTHERPICTURES TEXT("Other Pictures Directory")
  21. #define SZ_REGVALUE_VIEWTIME TEXT("View Painting Time")
  22. SPEED_SETTING s_SpeedSettings[MAX_SPEED] =
  23. {
  24. {15.0f, 15.0f, 60.0f, 15, 15, 50, 50},
  25. {11.0f, 11.0f, 25.0f, 12, 12, 35, 35},
  26. {10.0f, 10.0f, 15.0f, 10, 10, 35, 35},
  27. {7.0f, 7.0f, 12.0f, 9, 9, 25, 25},
  28. {4.0f, 4.0f, 10.0f, 8, 8, 25, 25},
  29. {4.0f, 4.0f, 7.0f, 7, 7, 25, 25},
  30. {2.5f, 2.5f, 5.0f, 6, 6, 21, 21},
  31. {2.0f, 2.0f, 2.50f, 5, 5, 17, 17},
  32. {2.00f, 2.0f, 1.5f, 10, 10, 15, 15},
  33. {0.50f, 0.5f, 0.5f, 7, 7, 15, 15},
  34. {0.50f, 0.5f, 0.5f, 5, 5, 15, 15},
  35. // {5.00f, 10.0f, 0.50f, 5, 5, 15, 15},
  36. };
  37. static QUALITY_SETTING s_QualitySettings[NUM_BOOL_SETTINGS] =
  38. {
  39. {TEXT("Show Stats")}, // IDC_CHECK_SHOWSTATS
  40. };
  41. // Values we can add: Lighing, Vectors on floor, etc.
  42. static BOOL s_fQualityValues[MAX_QUALITY][NUM_BOOL_SETTINGS] =
  43. { // ORDER: AntiAlias, Texture Perspective, Texture Dithering, Depth Buffering (Z), Specular Highlights, Anti-Alias Edges, Render Quality (Flat, Gouraud, Phong)
  44. {0},
  45. {0},
  46. {0},
  47. {0},
  48. {0},
  49. {0},
  50. {0},
  51. {0}
  52. };
  53. #define MINUTE 60
  54. static int s_nViewTimeSettings[MAX_VIEWTIME] =
  55. { 1, 2, 3, 4, 5, 7, 10, 12, 15, 17,
  56. 20, 25, 30, 35, 40, 45, 50, 55, MINUTE, MINUTE + 15,
  57. MINUTE + 30, MINUTE + 45, 2 * MINUTE, 2 * MINUTE + 30, 3 * MINUTE, 4 * MINUTE, 5 * MINUTE, 7 * MINUTE, 10 * MINUTE, 20 * MINUTE};
  58. static DWORD s_RenderQualitySliderValues[MAX_QUALITY] =
  59. {
  60. 0, 1, 1, 1, 2, 2, 2, 2
  61. };
  62. static LPCTSTR s_pszDWORDSettingsArray[NUM_DWORD_SETTINGS] =
  63. {
  64. TEXT("RenderQuality"), // IDC_RENDERQUALITY1
  65. TEXT("RealTimeMode"), // Walking Speed
  66. TEXT("Quality Slider"),
  67. TEXT("Speed Slider"),
  68. TEXT("View Time Slider"),
  69. };
  70. static FOLDER_SETTING s_FolderSettings[NUM_BOOL_FOLDERS] =
  71. {
  72. {TEXT("My Pictures"), TRUE}, // IDC_CHECK_MYPICTS
  73. {TEXT("Common Pictures"), FALSE}, // IDC_CHECK_COMMONPICTS
  74. {TEXT("Windows Pictures"), TRUE}, // IDC_CHECK_WINPICTS
  75. {TEXT("Other Pictures"), FALSE}, // IDC_CHECK_OTHERPICTS
  76. };
  77. static DWORD s_dwSettingsDefaults[NUM_DWORD_SETTINGS] =
  78. {
  79. DEFAULT_RENDERQUALITY, // CONFIG_DWORD_RENDERQUALITY
  80. 2, // CONFIG_DWORD_REALTIMEMODE
  81. DEFAULT_QUALITYSLIDER, // CONFIG_DWORD_QUALITY_SLIDER
  82. DEFAULT_SPEEDSLIDER, // CONFIG_DWORD_SPEED_SLIDER
  83. DEFAULT_VIEWTIMESLIDER, // CONFIG_DWORD_VIEWPAINTINGTIME
  84. };
  85. CConfig * g_pConfig = NULL; // The configuration settings the user wants to use.
  86. CConfig::CConfig(CMSLogoDXScreenSaver * pMain)
  87. {
  88. m_hkeyCurrentUser = NULL;
  89. m_fLoaded = FALSE;
  90. m_hDlg = NULL;
  91. m_szOther[0] = 0;
  92. m_pMain = pMain;
  93. for (int nIndex = 0; nIndex < ARRAYSIZE(m_pszCustomPaths); nIndex++)
  94. {
  95. m_pszCustomPaths[nIndex] = NULL;
  96. m_dwCustomScale[nIndex] = 100; // Default to 100%
  97. }
  98. }
  99. CConfig::~CConfig()
  100. {
  101. if (m_hkeyCurrentUser)
  102. {
  103. RegCloseKey(m_hkeyCurrentUser);
  104. m_hkeyCurrentUser = NULL;
  105. }
  106. for (int nIndex = 0; nIndex < ARRAYSIZE(m_pszCustomPaths); nIndex++)
  107. {
  108. Str_SetPtr(&(m_pszCustomPaths[nIndex]), NULL);
  109. }
  110. }
  111. HRESULT CConfig::_GetStateFromUI(void)
  112. {
  113. int nIndex;
  114. // Get Directory Checkboxes
  115. for (nIndex = 0; nIndex < ARRAYSIZE(m_fFolders); nIndex++)
  116. {
  117. m_fFolders[nIndex] = GetCheckBox(m_hDlg, IDC_CHECK_MYPICTS + nIndex);
  118. }
  119. // Set Other Path
  120. GetWindowText(GetDlgItem(m_hDlg, IDC_EDIT_OTHERPICTS), m_szOther, ARRAYSIZE(m_szOther));
  121. // Get Sliders
  122. m_dwSettings[CONFIG_DWORD_SPEED_SLIDER] = (DWORD) TaskBar_GetPos(GetDlgItem(m_hDlg, IDC_SLIDER_SPEED));
  123. m_dwSettings[CONFIG_DWORD_QUALITY_SLIDER] = (DWORD) TaskBar_GetPos(GetDlgItem(m_hDlg, IDC_SLIDER_QUALITY));
  124. m_dwSettings[CONFIG_DWORD_VIEWPAINTINGTIME] = s_nViewTimeSettings[(DWORD) TaskBar_GetPos(GetDlgItem(m_hDlg, IDC_SLIDER_VIEWTIME))];
  125. // Get Walk Speed ComboBox
  126. m_dwSettings[CONFIG_DWORD_REALTIMEMODE] = 0;
  127. return S_OK;
  128. }
  129. HRESULT CConfig::_LoadQualitySliderValues(void)
  130. {
  131. int nNewPos = TaskBar_GetPos(GetDlgItem(m_hDlg, IDC_SLIDER_QUALITY));
  132. if ((nNewPos < 0) || (nNewPos >= MAX_QUALITY))
  133. {
  134. nNewPos = DEFAULT_QUALITYSLIDER; // The value was invalid so revert to a valid value.
  135. }
  136. for (int nIndex = 0; nIndex < ARRAYSIZE(m_fSettings); nIndex++)
  137. {
  138. m_fSettings[nIndex] = s_fQualityValues[nNewPos][nIndex];
  139. }
  140. m_dwSettings[CONFIG_DWORD_RENDERQUALITY] = s_RenderQualitySliderValues[nNewPos];
  141. return S_OK;
  142. }
  143. HRESULT CConfig::_UpdateViewTimeSelection(void)
  144. {
  145. int nNewPos = TaskBar_GetPos(GetDlgItem(m_hDlg, IDC_SLIDER_VIEWTIME));
  146. TCHAR szDesc[MAX_PATH];
  147. if ((nNewPos < 0) || (nNewPos >= MAX_VIEWTIME))
  148. {
  149. nNewPos = DEFAULT_VIEWTIMESLIDER; // The value was invalid so revert to a valid value.
  150. }
  151. LoadString(HINST_THISDLL, IDS_VIEW_TIME_DESC + nNewPos, szDesc, ARRAYSIZE(szDesc));
  152. SetWindowText(GetDlgItem(m_hDlg, IDC_STATIC_VIEWTIME), szDesc);
  153. return S_OK;
  154. }
  155. int CALLBACK BrowseCallback(HWND hwnd, UINT msg, LPARAM lParam, LPARAM lpData)
  156. {
  157. int nResult = 0;
  158. switch (msg)
  159. {
  160. case BFFM_INITIALIZED:
  161. if (lpData) // Documentation says it will be NULL but other code does this.
  162. {
  163. // we passed ppidl as lpData so pass on just pidl
  164. // Notice I pass BFFM_SETSELECTIONA which would normally indicate ANSI.
  165. // I do this because Win95 requires it, but it doesn't matter because I'm
  166. // only passing a pidl
  167. SendMessage(hwnd, BFFM_SETSELECTIONA, FALSE, (LPARAM)((LPITEMIDLIST)lpData));
  168. }
  169. break;
  170. }
  171. return nResult;
  172. }
  173. HRESULT CConfig::_OnBrowseForFolder(void)
  174. {
  175. HRESULT hr = S_OK;
  176. LPITEMIDLIST pidlCurrent = NULL;
  177. BROWSEINFO bi = {0};
  178. TCHAR szTitle[MAX_PATH];
  179. GetWindowText(GetDlgItem(m_hDlg, IDC_EDIT_OTHERPICTS), m_szOther, ARRAYSIZE(m_szOther));
  180. LoadString(HINST_THISDLL, IDS_OTHERBROWSE_TITLE, szTitle, ARRAYSIZE(szTitle));
  181. hr = ShellFolderParsePath(m_szOther, &pidlCurrent);
  182. bi.hwndOwner = m_hDlg;
  183. bi.lpszTitle = szTitle;
  184. bi.lpfn = BrowseCallback;
  185. bi.lParam = (LPARAM) pidlCurrent;
  186. bi.ulFlags = (BIF_RETURNONLYFSDIRS | BIF_RETURNFSANCESTORS | BIF_EDITBOX | BIF_USENEWUI | BIF_VALIDATE);
  187. LPITEMIDLIST pidlNew = SHBrowseForFolder(&bi);
  188. if (pidlNew)
  189. {
  190. hr = ShellFolderGetPath(pidlNew, m_szOther, ARRAYSIZE(m_szOther));
  191. if (SUCCEEDED(hr))
  192. {
  193. SetWindowText(GetDlgItem(m_hDlg, IDC_EDIT_OTHERPICTS), m_szOther);
  194. }
  195. ILFree(pidlNew);
  196. }
  197. ILFree(pidlCurrent);
  198. return hr;
  199. }
  200. HRESULT CConfig::_OnInitDlg(HWND hDlg)
  201. {
  202. m_hDlg = hDlg;
  203. int nIndex;
  204. // Set Directory Checkboxes
  205. for (nIndex = 0; nIndex < ARRAYSIZE(m_fFolders); nIndex++)
  206. {
  207. SetCheckBox(m_hDlg, IDC_CHECK_MYPICTS + nIndex, m_fFolders[nIndex]);
  208. }
  209. // Set Other Path
  210. SetWindowText(GetDlgItem(m_hDlg, IDC_EDIT_OTHERPICTS), m_szOther);
  211. EnableWindow(GetDlgItem(m_hDlg, IDC_EDIT_OTHERPICTS), m_fFolders[3]);
  212. EnableWindow(GetDlgItem(m_hDlg, IDC_BUTTON_BROWSEPICTS), m_fFolders[3]);
  213. // If we want to run on IE4, we need to delay load this.
  214. SHAutoComplete(GetDlgItem(m_hDlg, IDC_EDIT_OTHERPICTS), SHACF_FILESYSTEM);
  215. // Set Sliders
  216. TaskBar_SetRange(GetDlgItem(m_hDlg, IDC_SLIDER_SPEED), TRUE, 0, MAX_SPEED-1);
  217. TaskBar_SetPos(GetDlgItem(m_hDlg, IDC_SLIDER_SPEED), TRUE, m_dwSettings[CONFIG_DWORD_SPEED_SLIDER]);
  218. TaskBar_SetRange(GetDlgItem(m_hDlg, IDC_SLIDER_QUALITY), TRUE, 0, MAX_QUALITY-1);
  219. TaskBar_SetPos(GetDlgItem(m_hDlg, IDC_SLIDER_QUALITY), TRUE, m_dwSettings[CONFIG_DWORD_QUALITY_SLIDER]);
  220. TaskBar_SetRange(GetDlgItem(m_hDlg, IDC_SLIDER_VIEWTIME), TRUE, 0, MAX_VIEWTIME-1);
  221. TaskBar_SetPos(GetDlgItem(m_hDlg, IDC_SLIDER_VIEWTIME), TRUE, m_dwSettings[CONFIG_DWORD_VIEWPAINTINGTIME]);
  222. _UpdateViewTimeSelection();
  223. return S_OK;
  224. }
  225. HRESULT CConfig::_OnDestroy(HWND hDlg)
  226. {
  227. return S_OK;
  228. }
  229. BOOL CConfig::_IsDialogDataValid(void)
  230. {
  231. BOOL fValid = TRUE;
  232. GetWindowText(GetDlgItem(m_hDlg, IDC_EDIT_OTHERPICTS), m_szOther, ARRAYSIZE(m_szOther));
  233. if (m_fFolders[CONFIG_FOLDER_OTHER])
  234. {
  235. if (!PathFileExists(m_szOther))
  236. {
  237. TCHAR szMessage[MAX_PATH];
  238. TCHAR szTitle[MAX_PATH];
  239. LoadString(HINST_THISDLL, IDS_ERROR_INVALIDOTHERPATH, szMessage, ARRAYSIZE(szMessage));
  240. LoadString(HINST_THISDLL, IDS_ERROR_TITLE_OTHERPATH, szTitle, ARRAYSIZE(szTitle));
  241. MessageBox(m_hDlg, szMessage, szTitle, MB_OK);
  242. fValid = FALSE;
  243. }
  244. else if (!PathIsDirectory(m_szOther))
  245. {
  246. TCHAR szMessage[MAX_PATH];
  247. TCHAR szTitle[MAX_PATH];
  248. LoadString(HINST_THISDLL, IDS_ERROR_OTHERPATH_NOTDIR, szMessage, ARRAYSIZE(szMessage));
  249. LoadString(HINST_THISDLL, IDS_ERROR_TITLE_OTHERPATH, szTitle, ARRAYSIZE(szTitle));
  250. MessageBox(m_hDlg, szMessage, szTitle, MB_OK);
  251. fValid = FALSE;
  252. }
  253. }
  254. return fValid;
  255. }
  256. HRESULT CConfig::_OnCommand(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
  257. {
  258. BOOL fHandled = 1; // Not handled (WM_COMMAND seems to be different)
  259. WORD idCtrl = GET_WM_COMMAND_ID(wParam, lParam);
  260. WORD wEvent = GET_WM_COMMAND_CMD(wParam, lParam);
  261. switch (idCtrl)
  262. {
  263. case IDOK:
  264. if (_IsDialogDataValid())
  265. {
  266. _GetStateFromUI();
  267. EndDialog(hDlg, IDOK);
  268. }
  269. break;
  270. case IDCANCEL:
  271. EndDialog(hDlg, IDCANCEL);
  272. break;
  273. case IDC_CHECK_OTHERPICTS:
  274. if ((BN_CLICKED == wEvent) && (IDC_CHECK_OTHERPICTS == idCtrl))
  275. {
  276. m_fFolders[3] = GetCheckBox(m_hDlg, IDC_CHECK_OTHERPICTS);
  277. EnableWindow(GetDlgItem(m_hDlg, IDC_EDIT_OTHERPICTS), m_fFolders[3]);
  278. EnableWindow(GetDlgItem(m_hDlg, IDC_BUTTON_BROWSEPICTS), m_fFolders[3]);
  279. }
  280. break;
  281. case IDC_BUTTON_ADVANCEDQUALITY:
  282. DisplayAdvancedDialog(m_hDlg);
  283. break;
  284. case IDC_BUTTON_BROWSEPICTS:
  285. _OnBrowseForFolder();
  286. break;
  287. case IDC_BUTTON_MONITORSETTINGS:
  288. if (m_pMain)
  289. {
  290. m_pMain->DisplayMonitorSettings(hDlg);
  291. }
  292. break;
  293. default:
  294. break;
  295. }
  296. return fHandled;
  297. }
  298. INT_PTR CALLBACK CConfig::ConfigDlgProc(HWND hDlg, UINT wMsg, WPARAM wParam, LPARAM lParam)
  299. {
  300. CConfig * pThis = (CConfig *)GetWindowLongPtr(hDlg, DWLP_USER);
  301. if (WM_INITDIALOG == wMsg)
  302. {
  303. pThis = (CConfig *) lParam;
  304. if (pThis)
  305. {
  306. SetWindowLongPtr(hDlg, DWLP_USER, lParam);
  307. }
  308. }
  309. if (pThis)
  310. {
  311. return pThis->_ConfigDlgProc(hDlg, wMsg, wParam, lParam);
  312. }
  313. return DefWindowProc(hDlg, wMsg, wParam, lParam);
  314. }
  315. INT_PTR CConfig::_ConfigDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
  316. {
  317. switch(message)
  318. {
  319. case WM_NOTIFY:
  320. break;
  321. case WM_INITDIALOG:
  322. _OnInitDlg(hDlg);
  323. break;
  324. case WM_DESTROY:
  325. _OnDestroy(hDlg);
  326. break;
  327. case WM_HELP:
  328. // TODO: Get help strings
  329. // WinHelp((HWND) ((LPHELPINFO) lParam)->hItemHandle, SZ_HELPFILE_ADVAPPEARANCE, HELP_WM_HELP, (DWORD_PTR) aAdvAppearanceHelpIds);
  330. break;
  331. case WM_CONTEXTMENU: // right mouse click
  332. // WinHelp((HWND) wParam, SZ_HELPFILE_ADVAPPEARANCE, HELP_CONTEXTMENU, (DWORD_PTR) aAdvAppearanceHelpIds);
  333. break;
  334. case WM_COMMAND:
  335. _OnCommand(hDlg, message, wParam, lParam);
  336. break;
  337. case WM_HSCROLL:
  338. case WM_VSCROLL:
  339. if (GetDlgItem(m_hDlg, IDC_SLIDER_VIEWTIME) == (HWND) lParam)
  340. {
  341. _UpdateViewTimeSelection();
  342. }
  343. else if (GetDlgItem(m_hDlg, IDC_SLIDER_QUALITY) == (HWND) lParam)
  344. {
  345. _LoadQualitySliderValues();
  346. }
  347. break;
  348. }
  349. return FALSE;
  350. }
  351. HRESULT CConfig::_LoadState(void)
  352. {
  353. HRESULT hr = S_OK;
  354. if (!m_fLoaded)
  355. {
  356. if (!m_hkeyCurrentUser)
  357. {
  358. hr = HrRegCreateKeyEx(HKEY_CURRENT_USER, SZ_REGKEY_THISSS_CONFIG, 0, NULL, REG_OPTION_NON_VOLATILE, (KEY_WRITE | KEY_READ), NULL, &m_hkeyCurrentUser, NULL);
  359. }
  360. if (m_hkeyCurrentUser)
  361. {
  362. int nIndex;
  363. for (nIndex = 0; nIndex < ARRAYSIZE(m_fSettings); nIndex++)
  364. {
  365. HrRegGetDWORD(m_hkeyCurrentUser, NULL, s_QualitySettings[nIndex].pszRegValue, (DWORD *)&m_fSettings[nIndex], s_fQualityValues[DEFAULT_QUALITYSLIDER][nIndex]);
  366. }
  367. for (nIndex = 0; nIndex < ARRAYSIZE(m_dwSettings); nIndex++)
  368. {
  369. HrRegGetDWORD(m_hkeyCurrentUser, NULL, s_pszDWORDSettingsArray[nIndex], &m_dwSettings[nIndex], s_dwSettingsDefaults[nIndex]);
  370. }
  371. // For the view time, we persist the number of seconds, not the slot number.
  372. // Let's find the slot number from the view time in seconds..
  373. for (nIndex = 0; nIndex < ARRAYSIZE(s_nViewTimeSettings); nIndex++)
  374. {
  375. if ((DWORD)s_nViewTimeSettings[nIndex] == m_dwSettings[CONFIG_DWORD_VIEWPAINTINGTIME])
  376. {
  377. m_dwSettings[CONFIG_DWORD_VIEWPAINTINGTIME] = nIndex;
  378. break;
  379. }
  380. }
  381. for (nIndex = 0; nIndex < ARRAYSIZE(m_fFolders); nIndex++)
  382. {
  383. HrRegGetDWORD(m_hkeyCurrentUser, NULL, s_FolderSettings[nIndex].pszRegValue, (DWORD *)&m_fFolders[nIndex], s_FolderSettings[nIndex].fDefaultToOn); // Only default to on for IDC_CHECK_WINPICTS
  384. }
  385. if (FAILED(HrRegGetValueString(m_hkeyCurrentUser, NULL, SZ_REGVALUE_OTHERPICTURES, m_szOther, ARRAYSIZE(m_szOther))))
  386. {
  387. StrCpyN(m_szOther, TEXT("C:\\"), ARRAYSIZE(m_szOther));
  388. }
  389. // Load any customized textures
  390. for (nIndex = 0; nIndex < ARRAYSIZE(m_pszCustomPaths); nIndex++)
  391. {
  392. TCHAR szRegValue[MAX_PATH];
  393. TCHAR szRegString[MAX_PATH];
  394. wnsprintf(szRegValue, ARRAYSIZE(szRegValue), TEXT("Texture #%d"), nIndex);
  395. szRegString[0] = 0; // in case the regkey doesn't exist yet.
  396. HrRegGetValueString(m_hkeyCurrentUser, NULL, szRegValue, szRegString, ARRAYSIZE(szRegString));
  397. if (szRegString[0])
  398. {
  399. Str_SetPtr(&(m_pszCustomPaths[nIndex]), szRegString);
  400. }
  401. else
  402. {
  403. Str_SetPtr(&(m_pszCustomPaths[nIndex]), NULL);
  404. }
  405. wnsprintf(szRegValue, ARRAYSIZE(szRegValue), TEXT("Texture #%d Scale"), nIndex);
  406. HrRegGetDWORD(m_hkeyCurrentUser, NULL, szRegValue, (DWORD *)&m_dwCustomScale[nIndex], 100);
  407. }
  408. m_pMain->ReadScreenSettingsPublic( m_hkeyCurrentUser );
  409. }
  410. m_fLoaded = TRUE;
  411. }
  412. return hr;
  413. }
  414. HRESULT CConfig::_SaveState(void)
  415. {
  416. HRESULT hr = E_FAIL;
  417. if (m_hkeyCurrentUser)
  418. {
  419. int nIndex;
  420. for (nIndex = 0; nIndex < ARRAYSIZE(m_fSettings); nIndex++)
  421. {
  422. HrRegSetDWORD(m_hkeyCurrentUser, NULL, s_QualitySettings[nIndex].pszRegValue, m_fSettings[nIndex]);
  423. }
  424. for (nIndex = 0; nIndex < ARRAYSIZE(m_dwSettings); nIndex++)
  425. {
  426. HrRegSetDWORD(m_hkeyCurrentUser, NULL, s_pszDWORDSettingsArray[nIndex], m_dwSettings[nIndex]);
  427. }
  428. for (nIndex = 0; nIndex < ARRAYSIZE(m_fFolders); nIndex++)
  429. {
  430. HrRegSetDWORD(m_hkeyCurrentUser, NULL, s_FolderSettings[nIndex].pszRegValue, m_fFolders[nIndex]); // Only default to on for IDC_CHECK_WINPICTS
  431. }
  432. hr = HrRegSetValueString(m_hkeyCurrentUser, NULL, SZ_REGVALUE_OTHERPICTURES, m_szOther);
  433. // Load any customized textures
  434. for (nIndex = 0; nIndex < ARRAYSIZE(m_pszCustomPaths); nIndex++)
  435. {
  436. TCHAR szRegValue[MAX_PATH];
  437. wnsprintf(szRegValue, ARRAYSIZE(szRegValue), TEXT("Texture #%d"), nIndex);
  438. HrRegSetValueString(m_hkeyCurrentUser, NULL, szRegValue, (m_pszCustomPaths[nIndex] ? m_pszCustomPaths[nIndex] : TEXT("")));
  439. wnsprintf(szRegValue, ARRAYSIZE(szRegValue), TEXT("Texture #%d Scale"), nIndex);
  440. HrRegSetDWORD(m_hkeyCurrentUser, NULL, szRegValue, m_dwCustomScale[nIndex]);
  441. }
  442. m_pMain->WriteScreenSettingsPublic( m_hkeyCurrentUser );
  443. }
  444. return hr;
  445. }
  446. HRESULT CConfig::GetOtherDir(LPTSTR pszPath, DWORD cchSize)
  447. {
  448. HRESULT hr = _LoadState();
  449. if (SUCCEEDED(hr))
  450. {
  451. StrCpyN(pszPath, m_szOther, cchSize);
  452. }
  453. return hr;
  454. }
  455. HRESULT CConfig::GetTexturePath(int nTextureIndex, DWORD * pdwScale, LPTSTR pszPath, DWORD cchSize)
  456. {
  457. HRESULT hr = _LoadState();
  458. if (SUCCEEDED(hr))
  459. {
  460. hr = E_FAIL;
  461. if ((nTextureIndex >= 0) && (nTextureIndex < ARRAYSIZE(m_pszCustomPaths)) &&
  462. m_pszCustomPaths[nTextureIndex] && m_pszCustomPaths[nTextureIndex][0])
  463. {
  464. // We have a custom texture to use.
  465. StrCpyN(pszPath, m_pszCustomPaths[nTextureIndex], cchSize);
  466. *pdwScale = m_dwCustomScale[nTextureIndex];
  467. hr = S_OK;
  468. }
  469. }
  470. return hr;
  471. }
  472. BOOL CConfig::GetFolderOn(UINT nSetting)
  473. {
  474. HRESULT hr = _LoadState();
  475. BOOL fReturn = FALSE;
  476. if (SUCCEEDED(hr) && (nSetting < ARRAYSIZE(m_fFolders)))
  477. {
  478. fReturn = m_fFolders[nSetting];
  479. }
  480. return fReturn;
  481. }
  482. BOOL CConfig::GetBoolSetting(UINT nSetting)
  483. {
  484. HRESULT hr = _LoadState();
  485. BOOL fReturn = FALSE;
  486. if (SUCCEEDED(hr) && (IDC_CHECK_SHOWSTATS <= nSetting))
  487. {
  488. nSetting -= IDC_CHECK_SHOWSTATS;
  489. if (nSetting < ARRAYSIZE(m_fSettings))
  490. {
  491. fReturn = m_fSettings[nSetting];
  492. }
  493. }
  494. return fReturn;
  495. }
  496. DWORD CConfig::GetDWORDSetting(UINT nSetting)
  497. {
  498. HRESULT hr = _LoadState();
  499. DWORD dwReturn = 0;
  500. if (SUCCEEDED(hr) && (nSetting < ARRAYSIZE(m_dwSettings)))
  501. {
  502. dwReturn = m_dwSettings[nSetting];
  503. }
  504. return dwReturn;
  505. }
  506. HRESULT CConfig::DisplayConfigDialog(HWND hwndParent)
  507. {
  508. HRESULT hr = _LoadState();
  509. if (SUCCEEDED(hr))
  510. {
  511. // Display Advanced Dialog
  512. if (IDOK == DialogBoxParam(HINST_THISDLL, MAKEINTRESOURCE(IDD_DIALOG_CONFIG), hwndParent, CConfig::ConfigDlgProc, (LPARAM)this))
  513. {
  514. hr = _SaveState();
  515. }
  516. else
  517. {
  518. hr = HRESULT_FROM_WIN32(ERROR_CANCELLED);
  519. }
  520. }
  521. return hr;
  522. }
  523. HRESULT CConfig::DisplayAdvancedDialog(HWND hwndParent)
  524. {
  525. HRESULT hr = S_OK;
  526. int nIndex;
  527. for (nIndex = 0; nIndex < ARRAYSIZE(m_fSettings); nIndex++)
  528. {
  529. m_fAdvSettings[nIndex] = m_fSettings[nIndex];
  530. }
  531. for (nIndex = 0; nIndex < ARRAYSIZE(m_dwSettings); nIndex++)
  532. {
  533. m_dwAdvSettings[nIndex] = m_dwSettings[nIndex];
  534. }
  535. // Display Advanced Dialog
  536. if (IDOK == DialogBoxParam(HINST_THISDLL, MAKEINTRESOURCE(IDD_DIALOG_ADVANCED), hwndParent, CConfig::AdvDlgProc, (LPARAM)this))
  537. {
  538. for (nIndex = 0; nIndex < ARRAYSIZE(m_fSettings); nIndex++)
  539. {
  540. m_fSettings[nIndex] = m_fAdvSettings[nIndex];
  541. }
  542. for (nIndex = 0; nIndex < ARRAYSIZE(m_dwSettings); nIndex++)
  543. {
  544. m_dwSettings[nIndex] = m_dwAdvSettings[nIndex];
  545. }
  546. hr = S_OK;
  547. }
  548. else
  549. {
  550. hr = HRESULT_FROM_WIN32(ERROR_CANCELLED);
  551. }
  552. return hr;
  553. }
  554. HRESULT CConfig::_OnEnableCustomTexture(int nIndex, BOOL fEnable)
  555. {
  556. EnableWindow(GetDlgItem(m_hDlgAdvanced, (IDC_EDIT_TEXTR_FLOOR + nIndex)), fEnable);
  557. EnableWindow(GetDlgItem(m_hDlgAdvanced, (IDC_EDIT_TEXTR_FLOORSIZE + nIndex)), fEnable);
  558. EnableWindow(GetDlgItem(m_hDlgAdvanced, (IDC_STATIC1_TEXTR_FLOOR + nIndex)), fEnable);
  559. EnableWindow(GetDlgItem(m_hDlgAdvanced, (IDC_STATIC2_TEXTR_FLOOR + nIndex)), fEnable);
  560. EnableWindow(GetDlgItem(m_hDlgAdvanced, (IDC_STATIC3_TEXTR_FLOOR + nIndex)), fEnable);
  561. return S_OK;
  562. }
  563. HRESULT CConfig::_OnAdvInitDlg(HWND hDlg)
  564. {
  565. m_hDlgAdvanced = hDlg;
  566. int nIndex;
  567. // Set Directory Checkboxes
  568. for (nIndex = 0; nIndex < ARRAYSIZE(m_fAdvSettings); nIndex++)
  569. {
  570. SetCheckBox(m_hDlgAdvanced, IDC_CHECK_SHOWSTATS+nIndex, m_fAdvSettings[nIndex]);
  571. }
  572. // Copy the customized textures.
  573. for (nIndex = 0; nIndex < ARRAYSIZE(m_pszCustomPaths); nIndex++)
  574. {
  575. TCHAR szPath[MAX_PATH];
  576. SHAutoComplete(GetDlgItem(m_hDlgAdvanced, (IDC_EDIT_TEXTR_FLOOR + nIndex)), SHACF_FILESYSTEM);
  577. wnsprintf(szPath, ARRAYSIZE(szPath), TEXT("%d"), m_dwCustomScale[nIndex]);
  578. SetWindowText(GetDlgItem(m_hDlgAdvanced, (IDC_EDIT_TEXTR_FLOORSIZE + nIndex)), szPath);
  579. if (m_pszCustomPaths[nIndex] && m_pszCustomPaths[nIndex][0])
  580. {
  581. CheckDlgButton(m_hDlgAdvanced, (IDC_CHECK_TEXTR_FLOOR + nIndex), BST_CHECKED);
  582. SetWindowText(GetDlgItem(m_hDlgAdvanced, (IDC_EDIT_TEXTR_FLOOR + nIndex)), m_pszCustomPaths[nIndex]);
  583. }
  584. else
  585. {
  586. _OnEnableCustomTexture(nIndex, FALSE);
  587. }
  588. }
  589. CheckDlgButton(m_hDlgAdvanced, IDC_RENDERQUALITY1+m_dwAdvSettings[CONFIG_DWORD_RENDERQUALITY], BST_CHECKED);
  590. return S_OK;
  591. }
  592. HRESULT CConfig::_GetAdvState(void)
  593. {
  594. int nIndex;
  595. // Set Directory Checkboxes
  596. for (nIndex = 0; nIndex < ARRAYSIZE(m_fAdvSettings); nIndex++)
  597. {
  598. m_fAdvSettings[nIndex] = GetCheckBox(m_hDlgAdvanced, IDC_CHECK_SHOWSTATS+nIndex);
  599. }
  600. // Copy the customized textures.
  601. for (nIndex = 0; nIndex < ARRAYSIZE(m_pszCustomPaths); nIndex++)
  602. {
  603. if (IsDlgButtonChecked(m_hDlgAdvanced, (IDC_CHECK_TEXTR_FLOOR + nIndex)))
  604. {
  605. TCHAR szPath[MAX_PATH];
  606. GetWindowText(GetDlgItem(m_hDlgAdvanced, (IDC_EDIT_TEXTR_FLOOR + nIndex)), szPath, ARRAYSIZE(szPath));
  607. Str_SetPtr(&(m_pszCustomPaths[nIndex]), szPath);
  608. GetWindowText(GetDlgItem(m_hDlgAdvanced, (IDC_EDIT_TEXTR_FLOORSIZE + nIndex)), szPath, ARRAYSIZE(szPath));
  609. m_dwCustomScale[nIndex] = (DWORD) StrToInt(szPath);
  610. }
  611. else
  612. {
  613. Str_SetPtr(&(m_pszCustomPaths[nIndex]), NULL);
  614. }
  615. }
  616. if (BST_CHECKED == IsDlgButtonChecked(m_hDlgAdvanced, IDC_RENDERQUALITY1))
  617. {
  618. m_dwAdvSettings[CONFIG_DWORD_RENDERQUALITY] = 0;
  619. }
  620. else if (BST_CHECKED == IsDlgButtonChecked(m_hDlgAdvanced, IDC_RENDERQUALITY2))
  621. {
  622. m_dwAdvSettings[CONFIG_DWORD_RENDERQUALITY] = 1;
  623. }
  624. else if (BST_CHECKED == IsDlgButtonChecked(m_hDlgAdvanced, IDC_RENDERQUALITY3))
  625. {
  626. m_dwAdvSettings[CONFIG_DWORD_RENDERQUALITY] = 2;
  627. }
  628. return S_OK;
  629. }
  630. HRESULT CConfig::_OnAdvDestroy(HWND hDlg)
  631. {
  632. return S_OK;
  633. }
  634. HRESULT CConfig::_OnAdvCommand(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
  635. {
  636. BOOL fHandled = 1; // Not handled (WM_COMMAND seems to be different)
  637. WORD idCtrl = GET_WM_COMMAND_ID(wParam, lParam);
  638. WORD wEvent = GET_WM_COMMAND_CMD(wParam, lParam);
  639. switch (idCtrl)
  640. {
  641. case IDOK:
  642. _GetAdvState();
  643. EndDialog(hDlg, IDOK);
  644. break;
  645. case IDCANCEL:
  646. EndDialog(hDlg, IDCANCEL);
  647. break;
  648. case IDC_CHECK_TEXTR_FLOOR:
  649. _OnEnableCustomTexture(0, IsDlgButtonChecked(m_hDlgAdvanced, IDC_CHECK_TEXTR_FLOOR));
  650. break;
  651. case IDC_CHECK_TEXTR_WALLPAPER:
  652. _OnEnableCustomTexture(1, IsDlgButtonChecked(m_hDlgAdvanced, IDC_CHECK_TEXTR_WALLPAPER));
  653. break;
  654. case IDC_CHECK_TEXTR_CEILING:
  655. _OnEnableCustomTexture(2, IsDlgButtonChecked(m_hDlgAdvanced, IDC_CHECK_TEXTR_CEILING));
  656. break;
  657. case IDC_CHECK_TEXTR_TOEGUARD:
  658. _OnEnableCustomTexture(3, IsDlgButtonChecked(m_hDlgAdvanced, IDC_CHECK_TEXTR_TOEGUARD));
  659. break;
  660. case IDC_CHECK_TEXTR_RUG:
  661. _OnEnableCustomTexture(4, IsDlgButtonChecked(m_hDlgAdvanced, IDC_CHECK_TEXTR_RUG));
  662. break;
  663. case IDC_CHECK_TEXTR_FRAME:
  664. _OnEnableCustomTexture(5, IsDlgButtonChecked(m_hDlgAdvanced, IDC_CHECK_TEXTR_FRAME));
  665. break;
  666. default:
  667. break;
  668. }
  669. return fHandled;
  670. }
  671. INT_PTR CALLBACK CConfig::AdvDlgProc(HWND hDlg, UINT wMsg, WPARAM wParam, LPARAM lParam)
  672. {
  673. CConfig * pThis = (CConfig *)GetWindowLongPtr(hDlg, DWLP_USER);
  674. if (WM_INITDIALOG == wMsg)
  675. {
  676. pThis = (CConfig *) lParam;
  677. if (pThis)
  678. {
  679. SetWindowLongPtr(hDlg, DWLP_USER, lParam);
  680. }
  681. }
  682. if (pThis)
  683. {
  684. return pThis->_AdvDlgProc(hDlg, wMsg, wParam, lParam);
  685. }
  686. return DefWindowProc(hDlg, wMsg, wParam, lParam);
  687. }
  688. INT_PTR CConfig::_AdvDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
  689. {
  690. switch(message)
  691. {
  692. case WM_NOTIFY:
  693. break;
  694. case WM_INITDIALOG:
  695. _OnAdvInitDlg(hDlg);
  696. break;
  697. case WM_DESTROY:
  698. _OnAdvDestroy(hDlg);
  699. break;
  700. case WM_HELP:
  701. // TODO: Get help strings
  702. // WinHelp((HWND) ((LPHELPINFO) lParam)->hItemHandle, SZ_HELPFILE_ADVAPPEARANCE, HELP_WM_HELP, (DWORD_PTR) aAdvAppearanceHelpIds);
  703. break;
  704. case WM_CONTEXTMENU: // right mouse click
  705. // WinHelp((HWND) wParam, SZ_HELPFILE_ADVAPPEARANCE, HELP_CONTEXTMENU, (DWORD_PTR) aAdvAppearanceHelpIds);
  706. break;
  707. case WM_COMMAND:
  708. _OnAdvCommand(hDlg, message, wParam, lParam);
  709. break;
  710. }
  711. return FALSE;
  712. }