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.

387 lines
11 KiB

  1. /*****************************************************************************\
  2. FILE: ThSettingsPg.cpp
  3. DESCRIPTION:
  4. This code will display a "Theme Settings" tab in the advanced
  5. "Display Properties" dialog (the advanced dialog, not the base dlg).
  6. BryanSt 3/23/2000 Updated and Converted to C++
  7. Copyright (C) Microsoft Corp 1993-2000. All rights reserved.
  8. \*****************************************************************************/
  9. #include "priv.h"
  10. #include "regutil.h"
  11. #include "ThSettingsPg.h"
  12. #include "AdvAppearPg.h"
  13. //============================================================================================================
  14. // Class
  15. //============================================================================================================
  16. class CThemeSettingsPage : public CObjectWithSite
  17. , public IAdvancedDialog
  18. {
  19. public:
  20. //////////////////////////////////////////////////////
  21. // Public Interfaces
  22. //////////////////////////////////////////////////////
  23. // *** IUnknown ***
  24. virtual STDMETHODIMP QueryInterface(REFIID riid, LPVOID * ppvObj);
  25. virtual STDMETHODIMP_(ULONG) AddRef(void);
  26. virtual STDMETHODIMP_(ULONG) Release(void);
  27. // *** IAdvancedDialog ***
  28. virtual STDMETHODIMP DisplayAdvancedDialog(IN HWND hwndParent, IN IPropertyBag * pBasePage, IN BOOL * pfEnableApply);
  29. CThemeSettingsPage();
  30. protected:
  31. private:
  32. virtual ~CThemeSettingsPage(void);
  33. // Private Member Variables
  34. long m_cRef;
  35. BOOL m_fDirty;
  36. HWND m_hDlg;
  37. IPropertyBag * m_pPropertyBag;
  38. // Private Member Functions
  39. INT_PTR _ThemeSettingsDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);
  40. HRESULT _OnInitThemesDlg(HWND hDlg);
  41. INT_PTR _OnCommand(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);
  42. HRESULT _LoadState(IN IPropertyBag * pBasePage);
  43. HRESULT _SaveState(IN IPropertyBag * pBasePage);
  44. HRESULT _IsDirty(IN BOOL * pIsDirty);
  45. static INT_PTR CALLBACK ThemeSettingsDlgProc(HWND hDlg, UINT uMessage, WPARAM wParam, LPARAM lParam);
  46. };
  47. //============================================================================================================
  48. // *** Globals ***
  49. //============================================================================================================
  50. const static DWORD FAR aThemeSettingsHelpIds[] = {
  51. IDC_TSPG_THEMELIST_LABLE, IDH_DISPLAY_THEMESETTINGS_NAMELABLE,
  52. IDC_TSPG_THEME_NAME, IDH_DISPLAY_THEMESETTINGS_NAME,
  53. IDC_TSPG_CB_GROUP_LABEL, IDH_DISPLAY_THEMESETTINGS_LABEL,
  54. IDC_TSPG_CB_LABEL, IDH_DISPLAY_THEMESETTINGS_LABEL,
  55. IDC_TSPG_CB_WALLPAPER, IDH_DISPLAY_THEMESETTINGS_WALLPAPER,
  56. IDC_TSPG_CB_SOUNDS, IDH_DISPLAY_THEMESETTINGS_SOUNDS,
  57. IDC_TSPG_CB_MOUSE, IDH_DISPLAY_THEMESETTINGS_MOUSE,
  58. IDC_TSPG_CB_SCREENSAVER, IDH_DISPLAY_THEMESETTINGS_SCREENSAVER,
  59. IDC_TSPG_CB_ICONS, IDH_DISPLAY_THEMESETTINGS_ICONS,
  60. IDC_TSPG_CB_COLORS, IDH_DISPLAY_THEMESETTINGS_COLORS,
  61. IDC_TSPG_CB_FONTS, IDH_DISPLAY_THEMESETTINGS_FONTS,
  62. IDC_TSPG_CB_BORDERS, IDH_DISPLAY_THEMESETTINGS_BORDERS,
  63. 0, 0
  64. };
  65. #define SZ_HELPFILE_THEMESETTINGS TEXT("display.hlp")
  66. const TCHAR * g_szCBNames[SIZE_THEME_FILTERS] =
  67. {
  68. SZ_PBPROP_THEME_FILTER TEXT("Screen saver"),
  69. SZ_PBPROP_THEME_FILTER TEXT("Sound events"),
  70. SZ_PBPROP_THEME_FILTER TEXT("Mouse pointers"),
  71. SZ_PBPROP_THEME_FILTER TEXT("Desktop wallpaper"),
  72. SZ_PBPROP_THEME_FILTER TEXT("Icons"),
  73. SZ_PBPROP_THEME_FILTER TEXT("Colors"),
  74. SZ_PBPROP_THEME_FILTER TEXT("Font names and styles"),
  75. SZ_PBPROP_THEME_FILTER TEXT("Font and window sizes"),
  76. SZ_PBPROP_THEME_FILTER TEXT("Rotate theme monthly")
  77. };
  78. //===========================
  79. // *** Class Internals & Helpers ***
  80. //===========================
  81. INT_PTR CALLBACK CThemeSettingsPage::ThemeSettingsDlgProc(HWND hDlg, UINT wMsg, WPARAM wParam, LPARAM lParam)
  82. {
  83. CThemeSettingsPage * pThis = (CThemeSettingsPage *)GetWindowLongPtr(hDlg, DWLP_USER);
  84. if (WM_INITDIALOG == wMsg)
  85. {
  86. pThis = (CThemeSettingsPage *) lParam;
  87. if (pThis)
  88. {
  89. SetWindowLongPtr(hDlg, DWLP_USER, lParam);
  90. }
  91. }
  92. if (pThis)
  93. return pThis->_ThemeSettingsDlgProc(hDlg, wMsg, wParam, lParam);
  94. return DefWindowProc(hDlg, wMsg, wParam, lParam);
  95. }
  96. HRESULT CThemeSettingsPage::_OnInitThemesDlg(HWND hDlg)
  97. {
  98. m_hDlg = hDlg;
  99. if (m_pPropertyBag)
  100. {
  101. VARIANT varName;
  102. VariantInit(&varName);
  103. HRESULT hr = m_pPropertyBag->Read(SZ_PBPROP_THEME_DISPLAYNAME, &varName, NULL);
  104. if (SUCCEEDED(hr))
  105. {
  106. if (VT_BSTR == varName.vt)
  107. {
  108. SetWindowTextW(GetDlgItem(hDlg, IDC_TSPG_THEME_NAME), varName.bstrVal);
  109. }
  110. VariantClear(&varName);
  111. }
  112. }
  113. return _LoadState(m_pPropertyBag);
  114. }
  115. INT_PTR CThemeSettingsPage::_OnCommand(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
  116. {
  117. BOOL fHandled = 1; // Not handled (WM_COMMAND seems to be different)
  118. WORD idCtrl = GET_WM_COMMAND_ID(wParam, lParam);
  119. switch (idCtrl)
  120. {
  121. case IDOK:
  122. _SaveState(m_pPropertyBag);
  123. EndDialog(hDlg, IDOK);
  124. break;
  125. case IDCANCEL:
  126. EndDialog(hDlg, IDCANCEL);
  127. break;
  128. case IDC_TSPG_CB_SCREENSAVER:
  129. case IDC_TSPG_CB_SOUNDS:
  130. case IDC_TSPG_CB_MOUSE:
  131. case IDC_TSPG_CB_WALLPAPER:
  132. case IDC_TSPG_CB_ICONS:
  133. case IDC_TSPG_CB_COLORS:
  134. case IDC_TSPG_CB_FONTS:
  135. case IDC_TSPG_CB_BORDERS:
  136. m_fDirty = TRUE;
  137. break;
  138. default:
  139. break;
  140. }
  141. return fHandled;
  142. }
  143. // This Property Sheet appear in the top level of the "Display Control Panel".
  144. INT_PTR CThemeSettingsPage::_ThemeSettingsDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
  145. {
  146. switch(message)
  147. {
  148. case WM_INITDIALOG:
  149. _OnInitThemesDlg(hDlg);
  150. break;
  151. case WM_HELP:
  152. WinHelp((HWND) ((LPHELPINFO) lParam)->hItemHandle, SZ_HELPFILE_THEMESETTINGS, HELP_WM_HELP, (DWORD_PTR) aThemeSettingsHelpIds);
  153. break;
  154. case WM_CONTEXTMENU: // right mouse click
  155. WinHelp((HWND) wParam, SZ_HELPFILE_THEMESETTINGS, HELP_CONTEXTMENU, (DWORD_PTR) aThemeSettingsHelpIds);
  156. break;
  157. case WM_COMMAND:
  158. _OnCommand(hDlg, message, wParam, lParam);
  159. break;
  160. }
  161. return FALSE;
  162. }
  163. HRESULT CThemeSettingsPage::_IsDirty(IN BOOL * pIsDirty)
  164. {
  165. HRESULT hr = E_INVALIDARG;
  166. if (pIsDirty)
  167. {
  168. *pIsDirty = m_fDirty;
  169. hr = S_OK;
  170. }
  171. return hr;
  172. }
  173. HRESULT CThemeSettingsPage::_LoadState(IN IPropertyBag * pPropertyBag)
  174. {
  175. HRESULT hr = E_INVALIDARG;
  176. if (pPropertyBag)
  177. {
  178. for (int nIndex = IDC_TSPG_CB_SCREENSAVER; nIndex <= IDC_TSPG_CB_BORDERS; nIndex++)
  179. {
  180. VARIANT varFilter;
  181. varFilter.vt = VT_BOOL;
  182. varFilter.boolVal = VARIANT_TRUE;
  183. hr = pPropertyBag->Read(g_szCBNames[nIndex - IDC_TSPG_CB_SCREENSAVER], &varFilter, NULL);
  184. CheckDlgButton(m_hDlg, nIndex, ((VARIANT_TRUE == varFilter.boolVal) ? BST_CHECKED : BST_UNCHECKED));
  185. }
  186. }
  187. return hr;
  188. }
  189. HRESULT CThemeSettingsPage::_SaveState(IN IPropertyBag * pBasePage)
  190. {
  191. HRESULT hr = E_INVALIDARG;
  192. if (pBasePage)
  193. {
  194. for (int nIndex = IDC_TSPG_CB_SCREENSAVER; nIndex <= IDC_TSPG_CB_BORDERS; nIndex++)
  195. {
  196. VARIANT varFilter;
  197. varFilter.vt = VT_BOOL;
  198. varFilter.boolVal = ((BST_UNCHECKED != IsDlgButtonChecked(m_hDlg, nIndex)) ? VARIANT_TRUE : VARIANT_FALSE);
  199. hr = pBasePage->Write(g_szCBNames[nIndex - IDC_TSPG_CB_SCREENSAVER], &varFilter);
  200. }
  201. }
  202. return hr;
  203. }
  204. //===========================
  205. // *** IAdvancedDialog Interface ***
  206. //===========================
  207. HRESULT CThemeSettingsPage::DisplayAdvancedDialog(IN HWND hwndParent, IN IPropertyBag * pBasePage, IN BOOL * pfEnableApply)
  208. {
  209. HRESULT hr = E_INVALIDARG;
  210. if (hwndParent && pBasePage && pfEnableApply)
  211. {
  212. // Load State Into Advanced Dialog
  213. *pfEnableApply = FALSE;
  214. IUnknown_Set((IUnknown **) &m_pPropertyBag, pBasePage);
  215. hr = S_OK;
  216. // Display Advanced Dialog
  217. if (IDOK == DialogBoxParam(HINST_THISDLL, MAKEINTRESOURCE(DLG_THEMESETTINGSPG), hwndParent, CThemeSettingsPage::ThemeSettingsDlgProc, (LPARAM)this))
  218. {
  219. // The user clicked OK, so merge modified state back into base dialog
  220. _IsDirty(pfEnableApply);
  221. }
  222. }
  223. return hr;
  224. }
  225. //===========================
  226. // *** IUnknown Interface ***
  227. //===========================
  228. ULONG CThemeSettingsPage::AddRef()
  229. {
  230. return InterlockedIncrement(&m_cRef);
  231. }
  232. ULONG CThemeSettingsPage::Release()
  233. {
  234. ASSERT( 0 != m_cRef );
  235. ULONG cRef = InterlockedDecrement(&m_cRef);
  236. if ( 0 == cRef )
  237. {
  238. delete this;
  239. }
  240. return cRef;
  241. }
  242. HRESULT CThemeSettingsPage::QueryInterface(REFIID riid, void **ppvObj)
  243. {
  244. static const QITAB qit[] = {
  245. QITABENT(CThemeSettingsPage, IObjectWithSite),
  246. QITABENT(CThemeSettingsPage, IAdvancedDialog),
  247. { 0 },
  248. };
  249. return QISearch(this, qit, riid, ppvObj);
  250. }
  251. //===========================
  252. // *** Class Methods ***
  253. //===========================
  254. CThemeSettingsPage::CThemeSettingsPage() : m_cRef(1)
  255. {
  256. DllAddRef();
  257. // This needs to be allocated in Zero Inited Memory.
  258. // Assert that all Member Variables are inited to Zero.
  259. ASSERT(!m_fDirty);
  260. ASSERT(!m_hDlg);
  261. ASSERT(!m_pPropertyBag);
  262. }
  263. CThemeSettingsPage::~CThemeSettingsPage()
  264. {
  265. IUnknown_Set((IUnknown **) &m_pPropertyBag, NULL);
  266. DllRelease();
  267. }
  268. HRESULT CThemeSettingsPage_CreateInstance(OUT IAdvancedDialog ** ppAdvDialog)
  269. {
  270. HRESULT hr = E_INVALIDARG;
  271. if (ppAdvDialog)
  272. {
  273. CThemeSettingsPage * pThis = new CThemeSettingsPage();
  274. if (pThis)
  275. {
  276. hr = pThis->QueryInterface(IID_PPV_ARG(IAdvancedDialog, ppAdvDialog));
  277. pThis->Release();
  278. }
  279. else
  280. {
  281. *ppAdvDialog = NULL;
  282. hr = E_OUTOFMEMORY;
  283. }
  284. }
  285. return hr;
  286. }