Leaked source code of windows server 2003
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.

923 lines
27 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. WORD idCtrl = GET_WM_COMMAND_ID(wParam, lParam);
  259. WORD wEvent = GET_WM_COMMAND_CMD(wParam, lParam);
  260. switch (idCtrl)
  261. {
  262. case IDOK:
  263. if (_IsDialogDataValid())
  264. {
  265. _GetStateFromUI();
  266. EndDialog(hDlg, IDOK);
  267. }
  268. break;
  269. case IDCANCEL:
  270. EndDialog(hDlg, IDCANCEL);
  271. break;
  272. case IDC_CHECK_OTHERPICTS:
  273. if ((BN_CLICKED == wEvent) && (IDC_CHECK_OTHERPICTS == idCtrl))
  274. {
  275. m_fFolders[3] = GetCheckBox(m_hDlg, IDC_CHECK_OTHERPICTS);
  276. EnableWindow(GetDlgItem(m_hDlg, IDC_EDIT_OTHERPICTS), m_fFolders[3]);
  277. EnableWindow(GetDlgItem(m_hDlg, IDC_BUTTON_BROWSEPICTS), m_fFolders[3]);
  278. }
  279. break;
  280. case IDC_BUTTON_ADVANCEDQUALITY:
  281. DisplayAdvancedDialog(m_hDlg);
  282. break;
  283. case IDC_BUTTON_BROWSEPICTS:
  284. _OnBrowseForFolder();
  285. break;
  286. case IDC_BUTTON_MONITORSETTINGS:
  287. if (m_pMain)
  288. {
  289. m_pMain->DisplayMonitorSettings(hDlg);
  290. }
  291. break;
  292. default:
  293. break;
  294. }
  295. return S_OK;
  296. }
  297. INT_PTR CALLBACK CConfig::ConfigDlgProc(HWND hDlg, UINT wMsg, WPARAM wParam, LPARAM lParam)
  298. {
  299. CConfig * pThis = (CConfig *)GetWindowLongPtr(hDlg, DWLP_USER);
  300. if (WM_INITDIALOG == wMsg)
  301. {
  302. pThis = (CConfig *) lParam;
  303. if (pThis)
  304. {
  305. SetWindowLongPtr(hDlg, DWLP_USER, lParam);
  306. }
  307. }
  308. if (pThis)
  309. {
  310. return pThis->_ConfigDlgProc(hDlg, wMsg, wParam, lParam);
  311. }
  312. return DefWindowProc(hDlg, wMsg, wParam, lParam);
  313. }
  314. INT_PTR CConfig::_ConfigDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
  315. {
  316. switch(message)
  317. {
  318. case WM_NOTIFY:
  319. break;
  320. case WM_INITDIALOG:
  321. _OnInitDlg(hDlg);
  322. break;
  323. case WM_DESTROY:
  324. _OnDestroy(hDlg);
  325. break;
  326. case WM_HELP:
  327. // TODO: Get help strings
  328. // WinHelp((HWND) ((LPHELPINFO) lParam)->hItemHandle, SZ_HELPFILE_ADVAPPEARANCE, HELP_WM_HELP, (DWORD_PTR) aAdvAppearanceHelpIds);
  329. break;
  330. case WM_CONTEXTMENU: // right mouse click
  331. // WinHelp((HWND) wParam, SZ_HELPFILE_ADVAPPEARANCE, HELP_CONTEXTMENU, (DWORD_PTR) aAdvAppearanceHelpIds);
  332. break;
  333. case WM_COMMAND:
  334. _OnCommand(hDlg, message, wParam, lParam);
  335. break;
  336. case WM_HSCROLL:
  337. case WM_VSCROLL:
  338. if (GetDlgItem(m_hDlg, IDC_SLIDER_VIEWTIME) == (HWND) lParam)
  339. {
  340. _UpdateViewTimeSelection();
  341. }
  342. else if (GetDlgItem(m_hDlg, IDC_SLIDER_QUALITY) == (HWND) lParam)
  343. {
  344. _LoadQualitySliderValues();
  345. }
  346. break;
  347. }
  348. return FALSE;
  349. }
  350. HRESULT CConfig::_LoadState(void)
  351. {
  352. HRESULT hr = S_OK;
  353. if (!m_fLoaded)
  354. {
  355. if (!m_hkeyCurrentUser)
  356. {
  357. hr = HrRegCreateKeyEx(HKEY_CURRENT_USER, SZ_REGKEY_THISSS_CONFIG, 0, NULL, REG_OPTION_NON_VOLATILE, (KEY_WRITE | KEY_READ), NULL, &m_hkeyCurrentUser, NULL);
  358. }
  359. if (m_hkeyCurrentUser)
  360. {
  361. int nIndex;
  362. for (nIndex = 0; nIndex < ARRAYSIZE(m_fSettings); nIndex++)
  363. {
  364. HrRegGetDWORD(m_hkeyCurrentUser, NULL, s_QualitySettings[nIndex].pszRegValue, (DWORD *)&m_fSettings[nIndex], s_fQualityValues[DEFAULT_QUALITYSLIDER][nIndex]);
  365. }
  366. for (nIndex = 0; nIndex < ARRAYSIZE(m_dwSettings); nIndex++)
  367. {
  368. HrRegGetDWORD(m_hkeyCurrentUser, NULL, s_pszDWORDSettingsArray[nIndex], &m_dwSettings[nIndex], s_dwSettingsDefaults[nIndex]);
  369. }
  370. // For the view time, we persist the number of seconds, not the slot number.
  371. // Let's find the slot number from the view time in seconds..
  372. for (nIndex = 0; nIndex < ARRAYSIZE(s_nViewTimeSettings); nIndex++)
  373. {
  374. if ((DWORD)s_nViewTimeSettings[nIndex] == m_dwSettings[CONFIG_DWORD_VIEWPAINTINGTIME])
  375. {
  376. m_dwSettings[CONFIG_DWORD_VIEWPAINTINGTIME] = nIndex;
  377. break;
  378. }
  379. }
  380. for (nIndex = 0; nIndex < ARRAYSIZE(m_fFolders); nIndex++)
  381. {
  382. HrRegGetDWORD(m_hkeyCurrentUser, NULL, s_FolderSettings[nIndex].pszRegValue, (DWORD *)&m_fFolders[nIndex], s_FolderSettings[nIndex].fDefaultToOn); // Only default to on for IDC_CHECK_WINPICTS
  383. }
  384. if (FAILED(HrRegGetValueString(m_hkeyCurrentUser, NULL, SZ_REGVALUE_OTHERPICTURES, m_szOther, ARRAYSIZE(m_szOther))))
  385. {
  386. StrCpyN(m_szOther, TEXT("C:\\"), ARRAYSIZE(m_szOther));
  387. }
  388. // Load any customized textures
  389. for (nIndex = 0; nIndex < ARRAYSIZE(m_pszCustomPaths); nIndex++)
  390. {
  391. TCHAR szRegValue[MAX_PATH];
  392. TCHAR szRegString[MAX_PATH];
  393. wnsprintf(szRegValue, ARRAYSIZE(szRegValue), TEXT("Texture #%d"), nIndex);
  394. szRegString[0] = 0; // in case the regkey doesn't exist yet.
  395. HrRegGetValueString(m_hkeyCurrentUser, NULL, szRegValue, szRegString, ARRAYSIZE(szRegString));
  396. if (szRegString[0])
  397. {
  398. Str_SetPtr(&(m_pszCustomPaths[nIndex]), szRegString);
  399. }
  400. else
  401. {
  402. Str_SetPtr(&(m_pszCustomPaths[nIndex]), NULL);
  403. }
  404. wnsprintf(szRegValue, ARRAYSIZE(szRegValue), TEXT("Texture #%d Scale"), nIndex);
  405. HrRegGetDWORD(m_hkeyCurrentUser, NULL, szRegValue, (DWORD *)&m_dwCustomScale[nIndex], 100);
  406. }
  407. m_pMain->ReadScreenSettingsPublic( m_hkeyCurrentUser );
  408. }
  409. m_fLoaded = TRUE;
  410. }
  411. return hr;
  412. }
  413. HRESULT CConfig::_SaveState(void)
  414. {
  415. HRESULT hr = E_FAIL;
  416. if (m_hkeyCurrentUser)
  417. {
  418. int nIndex;
  419. for (nIndex = 0; nIndex < ARRAYSIZE(m_fSettings); nIndex++)
  420. {
  421. HrRegSetDWORD(m_hkeyCurrentUser, NULL, s_QualitySettings[nIndex].pszRegValue, m_fSettings[nIndex]);
  422. }
  423. for (nIndex = 0; nIndex < ARRAYSIZE(m_dwSettings); nIndex++)
  424. {
  425. HrRegSetDWORD(m_hkeyCurrentUser, NULL, s_pszDWORDSettingsArray[nIndex], m_dwSettings[nIndex]);
  426. }
  427. for (nIndex = 0; nIndex < ARRAYSIZE(m_fFolders); nIndex++)
  428. {
  429. HrRegSetDWORD(m_hkeyCurrentUser, NULL, s_FolderSettings[nIndex].pszRegValue, m_fFolders[nIndex]); // Only default to on for IDC_CHECK_WINPICTS
  430. }
  431. hr = HrRegSetValueString(m_hkeyCurrentUser, NULL, SZ_REGVALUE_OTHERPICTURES, m_szOther);
  432. // Load any customized textures
  433. for (nIndex = 0; nIndex < ARRAYSIZE(m_pszCustomPaths); nIndex++)
  434. {
  435. TCHAR szRegValue[MAX_PATH];
  436. wnsprintf(szRegValue, ARRAYSIZE(szRegValue), TEXT("Texture #%d"), nIndex);
  437. HrRegSetValueString(m_hkeyCurrentUser, NULL, szRegValue, (m_pszCustomPaths[nIndex] ? m_pszCustomPaths[nIndex] : TEXT("")));
  438. wnsprintf(szRegValue, ARRAYSIZE(szRegValue), TEXT("Texture #%d Scale"), nIndex);
  439. HrRegSetDWORD(m_hkeyCurrentUser, NULL, szRegValue, m_dwCustomScale[nIndex]);
  440. }
  441. m_pMain->WriteScreenSettingsPublic( m_hkeyCurrentUser );
  442. }
  443. return hr;
  444. }
  445. HRESULT CConfig::GetOtherDir(LPTSTR pszPath, DWORD cchSize)
  446. {
  447. HRESULT hr = _LoadState();
  448. if (SUCCEEDED(hr))
  449. {
  450. StrCpyN(pszPath, m_szOther, cchSize);
  451. }
  452. return hr;
  453. }
  454. HRESULT CConfig::GetTexturePath(int nTextureIndex, DWORD * pdwScale, LPTSTR pszPath, DWORD cchSize)
  455. {
  456. HRESULT hr = _LoadState();
  457. if (SUCCEEDED(hr))
  458. {
  459. hr = E_FAIL;
  460. if ((nTextureIndex >= 0) && (nTextureIndex < ARRAYSIZE(m_pszCustomPaths)) &&
  461. m_pszCustomPaths[nTextureIndex] && m_pszCustomPaths[nTextureIndex][0])
  462. {
  463. // We have a custom texture to use.
  464. StrCpyN(pszPath, m_pszCustomPaths[nTextureIndex], cchSize);
  465. *pdwScale = m_dwCustomScale[nTextureIndex];
  466. hr = S_OK;
  467. }
  468. }
  469. return hr;
  470. }
  471. BOOL CConfig::GetFolderOn(UINT nSetting)
  472. {
  473. HRESULT hr = _LoadState();
  474. BOOL fReturn = FALSE;
  475. if (SUCCEEDED(hr) && (nSetting < ARRAYSIZE(m_fFolders)))
  476. {
  477. fReturn = m_fFolders[nSetting];
  478. }
  479. return fReturn;
  480. }
  481. BOOL CConfig::GetBoolSetting(UINT nSetting)
  482. {
  483. HRESULT hr = _LoadState();
  484. BOOL fReturn = FALSE;
  485. if (SUCCEEDED(hr) && (IDC_CHECK_SHOWSTATS <= nSetting))
  486. {
  487. nSetting -= IDC_CHECK_SHOWSTATS;
  488. if (nSetting < ARRAYSIZE(m_fSettings))
  489. {
  490. fReturn = m_fSettings[nSetting];
  491. }
  492. }
  493. return fReturn;
  494. }
  495. DWORD CConfig::GetDWORDSetting(UINT nSetting)
  496. {
  497. HRESULT hr = _LoadState();
  498. DWORD dwReturn = 0;
  499. if (SUCCEEDED(hr) && (nSetting < ARRAYSIZE(m_dwSettings)))
  500. {
  501. dwReturn = m_dwSettings[nSetting];
  502. }
  503. return dwReturn;
  504. }
  505. HRESULT CConfig::DisplayConfigDialog(HWND hwndParent)
  506. {
  507. HRESULT hr = _LoadState();
  508. if (SUCCEEDED(hr))
  509. {
  510. // Display Advanced Dialog
  511. if (IDOK == DialogBoxParam(HINST_THISDLL, MAKEINTRESOURCE(IDD_DIALOG_CONFIG), hwndParent, CConfig::ConfigDlgProc, (LPARAM)this))
  512. {
  513. hr = _SaveState();
  514. }
  515. else
  516. {
  517. hr = HRESULT_FROM_WIN32(ERROR_CANCELLED);
  518. }
  519. }
  520. return hr;
  521. }
  522. HRESULT CConfig::DisplayAdvancedDialog(HWND hwndParent)
  523. {
  524. HRESULT hr = S_OK;
  525. int nIndex;
  526. for (nIndex = 0; nIndex < ARRAYSIZE(m_fSettings); nIndex++)
  527. {
  528. m_fAdvSettings[nIndex] = m_fSettings[nIndex];
  529. }
  530. for (nIndex = 0; nIndex < ARRAYSIZE(m_dwSettings); nIndex++)
  531. {
  532. m_dwAdvSettings[nIndex] = m_dwSettings[nIndex];
  533. }
  534. // Display Advanced Dialog
  535. if (IDOK == DialogBoxParam(HINST_THISDLL, MAKEINTRESOURCE(IDD_DIALOG_ADVANCED), hwndParent, CConfig::AdvDlgProc, (LPARAM)this))
  536. {
  537. for (nIndex = 0; nIndex < ARRAYSIZE(m_fSettings); nIndex++)
  538. {
  539. m_fSettings[nIndex] = m_fAdvSettings[nIndex];
  540. }
  541. for (nIndex = 0; nIndex < ARRAYSIZE(m_dwSettings); nIndex++)
  542. {
  543. m_dwSettings[nIndex] = m_dwAdvSettings[nIndex];
  544. }
  545. hr = S_OK;
  546. }
  547. else
  548. {
  549. hr = HRESULT_FROM_WIN32(ERROR_CANCELLED);
  550. }
  551. return hr;
  552. }
  553. HRESULT CConfig::_OnEnableCustomTexture(int nIndex, BOOL fEnable)
  554. {
  555. EnableWindow(GetDlgItem(m_hDlgAdvanced, (IDC_EDIT_TEXTR_FLOOR + nIndex)), fEnable);
  556. EnableWindow(GetDlgItem(m_hDlgAdvanced, (IDC_EDIT_TEXTR_FLOORSIZE + nIndex)), fEnable);
  557. EnableWindow(GetDlgItem(m_hDlgAdvanced, (IDC_STATIC1_TEXTR_FLOOR + nIndex)), fEnable);
  558. EnableWindow(GetDlgItem(m_hDlgAdvanced, (IDC_STATIC2_TEXTR_FLOOR + nIndex)), fEnable);
  559. EnableWindow(GetDlgItem(m_hDlgAdvanced, (IDC_STATIC3_TEXTR_FLOOR + nIndex)), fEnable);
  560. return S_OK;
  561. }
  562. HRESULT CConfig::_OnAdvInitDlg(HWND hDlg)
  563. {
  564. m_hDlgAdvanced = hDlg;
  565. int nIndex;
  566. // Set Directory Checkboxes
  567. for (nIndex = 0; nIndex < ARRAYSIZE(m_fAdvSettings); nIndex++)
  568. {
  569. SetCheckBox(m_hDlgAdvanced, IDC_CHECK_SHOWSTATS+nIndex, m_fAdvSettings[nIndex]);
  570. }
  571. // Copy the customized textures.
  572. for (nIndex = 0; nIndex < ARRAYSIZE(m_pszCustomPaths); nIndex++)
  573. {
  574. TCHAR szPath[MAX_PATH];
  575. SHAutoComplete(GetDlgItem(m_hDlgAdvanced, (IDC_EDIT_TEXTR_FLOOR + nIndex)), SHACF_FILESYSTEM);
  576. wnsprintf(szPath, ARRAYSIZE(szPath), TEXT("%d"), m_dwCustomScale[nIndex]);
  577. SetWindowText(GetDlgItem(m_hDlgAdvanced, (IDC_EDIT_TEXTR_FLOORSIZE + nIndex)), szPath);
  578. if (m_pszCustomPaths[nIndex] && m_pszCustomPaths[nIndex][0])
  579. {
  580. CheckDlgButton(m_hDlgAdvanced, (IDC_CHECK_TEXTR_FLOOR + nIndex), BST_CHECKED);
  581. SetWindowText(GetDlgItem(m_hDlgAdvanced, (IDC_EDIT_TEXTR_FLOOR + nIndex)), m_pszCustomPaths[nIndex]);
  582. }
  583. else
  584. {
  585. _OnEnableCustomTexture(nIndex, FALSE);
  586. }
  587. }
  588. CheckDlgButton(m_hDlgAdvanced, IDC_RENDERQUALITY1+m_dwAdvSettings[CONFIG_DWORD_RENDERQUALITY], BST_CHECKED);
  589. return S_OK;
  590. }
  591. HRESULT CConfig::_GetAdvState(void)
  592. {
  593. int nIndex;
  594. // Set Directory Checkboxes
  595. for (nIndex = 0; nIndex < ARRAYSIZE(m_fAdvSettings); nIndex++)
  596. {
  597. m_fAdvSettings[nIndex] = GetCheckBox(m_hDlgAdvanced, IDC_CHECK_SHOWSTATS+nIndex);
  598. }
  599. // Copy the customized textures.
  600. for (nIndex = 0; nIndex < ARRAYSIZE(m_pszCustomPaths); nIndex++)
  601. {
  602. if (IsDlgButtonChecked(m_hDlgAdvanced, (IDC_CHECK_TEXTR_FLOOR + nIndex)))
  603. {
  604. TCHAR szPath[MAX_PATH];
  605. GetWindowText(GetDlgItem(m_hDlgAdvanced, (IDC_EDIT_TEXTR_FLOOR + nIndex)), szPath, ARRAYSIZE(szPath));
  606. Str_SetPtr(&(m_pszCustomPaths[nIndex]), szPath);
  607. GetWindowText(GetDlgItem(m_hDlgAdvanced, (IDC_EDIT_TEXTR_FLOORSIZE + nIndex)), szPath, ARRAYSIZE(szPath));
  608. m_dwCustomScale[nIndex] = (DWORD) StrToInt(szPath);
  609. }
  610. else
  611. {
  612. Str_SetPtr(&(m_pszCustomPaths[nIndex]), NULL);
  613. }
  614. }
  615. if (BST_CHECKED == IsDlgButtonChecked(m_hDlgAdvanced, IDC_RENDERQUALITY1))
  616. {
  617. m_dwAdvSettings[CONFIG_DWORD_RENDERQUALITY] = 0;
  618. }
  619. else if (BST_CHECKED == IsDlgButtonChecked(m_hDlgAdvanced, IDC_RENDERQUALITY2))
  620. {
  621. m_dwAdvSettings[CONFIG_DWORD_RENDERQUALITY] = 1;
  622. }
  623. else if (BST_CHECKED == IsDlgButtonChecked(m_hDlgAdvanced, IDC_RENDERQUALITY3))
  624. {
  625. m_dwAdvSettings[CONFIG_DWORD_RENDERQUALITY] = 2;
  626. }
  627. return S_OK;
  628. }
  629. HRESULT CConfig::_OnAdvDestroy(HWND hDlg)
  630. {
  631. return S_OK;
  632. }
  633. HRESULT CConfig::_OnAdvCommand(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
  634. {
  635. WORD idCtrl = GET_WM_COMMAND_ID(wParam, lParam);
  636. WORD wEvent = GET_WM_COMMAND_CMD(wParam, lParam);
  637. switch (idCtrl)
  638. {
  639. case IDOK:
  640. _GetAdvState();
  641. EndDialog(hDlg, IDOK);
  642. break;
  643. case IDCANCEL:
  644. EndDialog(hDlg, IDCANCEL);
  645. break;
  646. case IDC_CHECK_TEXTR_FLOOR:
  647. _OnEnableCustomTexture(0, IsDlgButtonChecked(m_hDlgAdvanced, IDC_CHECK_TEXTR_FLOOR));
  648. break;
  649. case IDC_CHECK_TEXTR_WALLPAPER:
  650. _OnEnableCustomTexture(1, IsDlgButtonChecked(m_hDlgAdvanced, IDC_CHECK_TEXTR_WALLPAPER));
  651. break;
  652. case IDC_CHECK_TEXTR_CEILING:
  653. _OnEnableCustomTexture(2, IsDlgButtonChecked(m_hDlgAdvanced, IDC_CHECK_TEXTR_CEILING));
  654. break;
  655. case IDC_CHECK_TEXTR_TOEGUARD:
  656. _OnEnableCustomTexture(3, IsDlgButtonChecked(m_hDlgAdvanced, IDC_CHECK_TEXTR_TOEGUARD));
  657. break;
  658. case IDC_CHECK_TEXTR_RUG:
  659. _OnEnableCustomTexture(4, IsDlgButtonChecked(m_hDlgAdvanced, IDC_CHECK_TEXTR_RUG));
  660. break;
  661. case IDC_CHECK_TEXTR_FRAME:
  662. _OnEnableCustomTexture(5, IsDlgButtonChecked(m_hDlgAdvanced, IDC_CHECK_TEXTR_FRAME));
  663. break;
  664. default:
  665. break;
  666. }
  667. return S_OK;
  668. }
  669. INT_PTR CALLBACK CConfig::AdvDlgProc(HWND hDlg, UINT wMsg, WPARAM wParam, LPARAM lParam)
  670. {
  671. CConfig * pThis = (CConfig *)GetWindowLongPtr(hDlg, DWLP_USER);
  672. if (WM_INITDIALOG == wMsg)
  673. {
  674. pThis = (CConfig *) lParam;
  675. if (pThis)
  676. {
  677. SetWindowLongPtr(hDlg, DWLP_USER, lParam);
  678. }
  679. }
  680. if (pThis)
  681. {
  682. return pThis->_AdvDlgProc(hDlg, wMsg, wParam, lParam);
  683. }
  684. return DefWindowProc(hDlg, wMsg, wParam, lParam);
  685. }
  686. INT_PTR CConfig::_AdvDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
  687. {
  688. switch(message)
  689. {
  690. case WM_NOTIFY:
  691. break;
  692. case WM_INITDIALOG:
  693. _OnAdvInitDlg(hDlg);
  694. break;
  695. case WM_DESTROY:
  696. _OnAdvDestroy(hDlg);
  697. break;
  698. case WM_HELP:
  699. // TODO: Get help strings
  700. // WinHelp((HWND) ((LPHELPINFO) lParam)->hItemHandle, SZ_HELPFILE_ADVAPPEARANCE, HELP_WM_HELP, (DWORD_PTR) aAdvAppearanceHelpIds);
  701. break;
  702. case WM_CONTEXTMENU: // right mouse click
  703. // WinHelp((HWND) wParam, SZ_HELPFILE_ADVAPPEARANCE, HELP_CONTEXTMENU, (DWORD_PTR) aAdvAppearanceHelpIds);
  704. break;
  705. case WM_COMMAND:
  706. _OnAdvCommand(hDlg, message, wParam, lParam);
  707. break;
  708. }
  709. return FALSE;
  710. }