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.

256 lines
6.1 KiB

  1. /*****************************************************************************\
  2. FILE: EffectsBasePg.cpp
  3. DESCRIPTION:
  4. This code will be the base object that won't add any pages to the base
  5. "Display Properties" dialog. However, it will request a "Effects" page be
  6. added to the Advanced.
  7. BryanSt 4/13/2000 Updated and Converted to C++
  8. Copyright (C) Microsoft Corp 2000-2000. All rights reserved.
  9. \*****************************************************************************/
  10. #include "priv.h"
  11. #include <shlwapip.h>
  12. #include <shlguidp.h>
  13. #include <shsemip.h>
  14. #pragma hdrstop
  15. #include "EffectsBasePg.h"
  16. #include "EffectsAdvPg.h"
  17. #include <cfgmgr32.h> // For MAX_GUID_STRING_LEN
  18. //============================================================================================================
  19. // *** Globals ***
  20. //============================================================================================================
  21. //===========================
  22. // *** Class Internals & Helpers ***
  23. //===========================
  24. HRESULT CEffectsBasePage::_InitState(void)
  25. {
  26. HRESULT hr = S_OK;
  27. if (!m_pEffectsState)
  28. {
  29. m_pEffectsState = new CEffectState();
  30. if (m_pEffectsState)
  31. {
  32. m_pEffectsState->Load();
  33. }
  34. else
  35. {
  36. hr = E_OUTOFMEMORY;
  37. }
  38. }
  39. return hr;
  40. }
  41. HRESULT CEffectsBasePage::_SaveState(CEffectState * pEffectsState)
  42. {
  43. HRESULT hr = E_INVALIDARG;
  44. if (pEffectsState)
  45. {
  46. if (m_pEffectsState)
  47. {
  48. m_pEffectsState->Release();
  49. }
  50. m_pEffectsState = pEffectsState;
  51. pEffectsState->AddRef();
  52. hr = S_OK;
  53. }
  54. return hr;
  55. }
  56. //===========================
  57. // *** IBasePropPage Interface ***
  58. //===========================
  59. HRESULT CEffectsBasePage::Read(IN LPCOLESTR pszPropName, IN VARIANT * pVar, IN IErrorLog *pErrorLog)
  60. {
  61. HRESULT hr = E_INVALIDARG;
  62. if (pszPropName && pVar)
  63. {
  64. if (!StrCmpW(SZ_PBPROP_EFFECTSSTATE, pszPropName) && m_pEffectsState)
  65. {
  66. pVar->vt = VT_BYREF;
  67. pVar->byref = (void *)&m_pEffectsState;
  68. if (m_pEffectsState)
  69. {
  70. m_pEffectsState->AddRef();
  71. }
  72. hr = S_OK;
  73. }
  74. }
  75. return hr;
  76. }
  77. HRESULT CEffectsBasePage::Write(IN LPCOLESTR pszPropName, IN VARIANT *pVar)
  78. {
  79. HRESULT hr = E_INVALIDARG;
  80. if (pszPropName && pVar)
  81. {
  82. if (VT_BYREF == pVar->vt)
  83. {
  84. // The caller is passing us a (CEffectState *) object to save.
  85. if (!StrCmpW(SZ_PBPROP_EFFECTSSTATE, pszPropName))
  86. {
  87. hr = _SaveState((CEffectState *) pVar->byref);
  88. }
  89. }
  90. else if (VT_BOOL == pVar->vt)
  91. {
  92. // The caller is passing us a (CEffectState *) object to save.
  93. if (!StrCmpW(SZ_PBPROP_EFFECTS_MENUDROPSHADOWS, pszPropName))
  94. {
  95. hr = _InitState();
  96. if (SUCCEEDED(hr) && m_pEffectsState)
  97. {
  98. m_pEffectsState->_fMenuShadows = (VARIANT_TRUE == pVar->boolVal);
  99. }
  100. }
  101. }
  102. }
  103. return hr;
  104. }
  105. //===========================
  106. // *** IBasePropPage Interface ***
  107. //===========================
  108. HRESULT CEffectsBasePage::GetAdvancedDialog(OUT IAdvancedDialog ** ppAdvDialog)
  109. {
  110. HRESULT hr = E_INVALIDARG;
  111. if (ppAdvDialog)
  112. {
  113. *ppAdvDialog = NULL;
  114. hr = _InitState();
  115. if (SUCCEEDED(hr))
  116. {
  117. hr = CEffectsPage_CreateInstance(ppAdvDialog);
  118. }
  119. }
  120. return hr;
  121. }
  122. HRESULT CEffectsBasePage::OnApply(IN PROPPAGEONAPPLY oaAction)
  123. {
  124. HRESULT hr = S_OK;
  125. if ((PPOAACTION_CANCEL != oaAction) && m_pEffectsState)
  126. {
  127. hr = m_pEffectsState->Save();
  128. // Make sure we reload the state next time we open the dialog.
  129. m_pEffectsState->Release();
  130. m_pEffectsState = NULL;
  131. }
  132. return hr;
  133. }
  134. //===========================
  135. // *** IShellPropSheetExt Interface ***
  136. //===========================
  137. HRESULT CEffectsBasePage::AddPages(IN LPFNSVADDPROPSHEETPAGE pfnAddPage, IN LPARAM lParam)
  138. {
  139. // We don't want to add any pages to the base dialog since we moved the
  140. // "Effects" tab to the Advanced dlg.
  141. return S_OK;
  142. }
  143. //===========================
  144. // *** IUnknown Interface ***
  145. //===========================
  146. ULONG CEffectsBasePage::AddRef()
  147. {
  148. return InterlockedIncrement(&m_cRef);
  149. }
  150. ULONG CEffectsBasePage::Release()
  151. {
  152. ASSERT( 0 != m_cRef );
  153. ULONG cRef = InterlockedDecrement(&m_cRef);
  154. if ( 0 == cRef )
  155. {
  156. delete this;
  157. }
  158. return cRef;
  159. }
  160. HRESULT CEffectsBasePage::QueryInterface(REFIID riid, void **ppvObj)
  161. {
  162. static const QITAB qit[] =
  163. {
  164. QITABENT(CEffectsBasePage, IBasePropPage),
  165. QITABENT(CEffectsBasePage, IPropertyBag),
  166. QITABENT(CEffectsBasePage, IPersist),
  167. QITABENT(CEffectsBasePage, IObjectWithSite),
  168. QITABENTMULTI(CEffectsBasePage, IShellPropSheetExt, IBasePropPage),
  169. { 0 },
  170. };
  171. return QISearch(this, qit, riid, ppvObj);
  172. }
  173. //===========================
  174. // *** Class Methods ***
  175. //===========================
  176. CEffectsBasePage::CEffectsBasePage() : CObjectCLSID(&PPID_Effects), m_cRef(1)
  177. {
  178. // This needs to be allocated in Zero Inited Memory.
  179. // Assert that all Member Variables are inited to Zero.
  180. m_fDirty = FALSE;
  181. }
  182. HRESULT CEffectsBasePage_CreateInstance(IN IUnknown * punkOuter, IN REFIID riid, OUT LPVOID * ppvObj)
  183. {
  184. HRESULT hr = E_INVALIDARG;
  185. if (!punkOuter && ppvObj)
  186. {
  187. CEffectsBasePage * pThis = new CEffectsBasePage();
  188. *ppvObj = NULL;
  189. if (pThis)
  190. {
  191. hr = pThis->QueryInterface(riid, ppvObj);
  192. pThis->Release();
  193. }
  194. else
  195. {
  196. hr = E_OUTOFMEMORY;
  197. }
  198. }
  199. return hr;
  200. }