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.

196 lines
5.3 KiB

  1. #include "shellprv.h"
  2. #include "clsobj.h"
  3. #include "theme.h"
  4. class CRegTreeItemBase : public IRegTreeItem
  5. {
  6. public:
  7. STDMETHODIMP QueryInterface(REFIID riid, void** ppvObj)
  8. {
  9. static const QITAB qit[] =
  10. {
  11. QITABENT(CRegTreeItemBase, IRegTreeItem),
  12. { 0 },
  13. };
  14. return QISearch(this, qit, riid, ppvObj);
  15. }
  16. STDMETHODIMP_(ULONG) AddRef()
  17. {
  18. return ++_cRef;
  19. }
  20. STDMETHODIMP_(ULONG) Release()
  21. {
  22. if (--_cRef == 0)
  23. {
  24. delete this;
  25. return 0;
  26. }
  27. return _cRef;
  28. }
  29. STDMETHODIMP GetCheckState(BOOL *pbCheck) PURE;
  30. STDMETHODIMP SetCheckState(BOOL bCheck) PURE;
  31. virtual ~CRegTreeItemBase() { }
  32. protected:
  33. CRegTreeItemBase() : _cRef(1) { }
  34. ULONG _cRef;
  35. };
  36. class CWebViewRegTreeItem : public CRegTreeItemBase
  37. {
  38. public:
  39. STDMETHODIMP GetCheckState(BOOL *pbCheck)
  40. {
  41. SHELLSTATE ss;
  42. SHGetSetSettings(&ss, SSF_WEBVIEW, FALSE);
  43. *pbCheck = BOOLIFY(ss.fWebView);
  44. return S_OK;
  45. }
  46. STDMETHODIMP SetCheckState(BOOL bCheck)
  47. {
  48. SHELLSTATE ss;
  49. ss.fWebView = bCheck;
  50. SHGetSetSettings(&ss, SSF_WEBVIEW, TRUE);
  51. return S_OK;
  52. }
  53. protected:
  54. friend HRESULT CWebViewRegTreeItem_CreateInstance(IUnknown *punkOuter, REFIID riid, void **ppv);
  55. };
  56. // aggregation checking is handled in class factory
  57. HRESULT CWebViewRegTreeItem_CreateInstance(IUnknown *punkOuter, REFIID riid, void **ppv)
  58. {
  59. HRESULT hr = E_OUTOFMEMORY;
  60. CWebViewRegTreeItem* pwvi = new CWebViewRegTreeItem();
  61. if (pwvi)
  62. {
  63. hr = pwvi->QueryInterface(riid, ppv);
  64. pwvi->Release();
  65. }
  66. return hr;
  67. }
  68. class CThemesRegTreeItem : public CRegTreeItemBase
  69. {
  70. CThemesRegTreeItem() { m_fVisualStyleOn = 2;}
  71. public:
  72. STDMETHODIMP GetCheckState(BOOL *pbCheck)
  73. {
  74. // We want to return TRUE if the visual style has a path.
  75. IThemeManager * pThemeManager;
  76. HRESULT hr = CoCreateInstance(CLSID_ThemeManager, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARG(IThemeManager, &pThemeManager));
  77. *pbCheck = FALSE;
  78. if (SUCCEEDED(hr))
  79. {
  80. IThemeScheme * pThemeScheme;
  81. hr = pThemeManager->get_SelectedScheme(&pThemeScheme);
  82. if (SUCCEEDED(hr))
  83. {
  84. CComBSTR bstrPathSelected;
  85. // This will return failure if no "Visual Style" is selected.
  86. if (SUCCEEDED(pThemeScheme->get_Path(&bstrPathSelected)) &&
  87. bstrPathSelected && bstrPathSelected[0])
  88. {
  89. *pbCheck = TRUE;
  90. }
  91. pThemeScheme->Release();
  92. }
  93. pThemeManager->Release();
  94. }
  95. m_fVisualStyleOn = *pbCheck;
  96. return hr;
  97. }
  98. STDMETHODIMP SetCheckState(BOOL bCheck)
  99. {
  100. HRESULT hr = S_OK;
  101. if (2 == m_fVisualStyleOn)
  102. {
  103. GetCheckState(&m_fVisualStyleOn);
  104. }
  105. // The user will loose settings when visual styles are switch so
  106. // only do it if the user made a change.
  107. if (bCheck != m_fVisualStyleOn)
  108. {
  109. IThemeManager * pThemeManager;
  110. hr = CoCreateInstance(CLSID_ThemeManager, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARG(IThemeManager, &pThemeManager));
  111. if (SUCCEEDED(hr))
  112. {
  113. IThemeScheme * pThemeSchemeNew;
  114. IThemeStyle * pThemeColorNew;
  115. IThemeSize * pThemeSizeNew;
  116. hr = pThemeManager->GetSpecialScheme((bCheck ? SZ_SSDEFAULVISUALSTYLEON : SZ_SSDEFAULVISUALSTYLEOFF), &pThemeSchemeNew, &pThemeColorNew, &pThemeSizeNew);
  117. if (SUCCEEDED(hr))
  118. {
  119. hr = pThemeColorNew->put_SelectedSize(pThemeSizeNew);
  120. if (SUCCEEDED(hr))
  121. {
  122. hr = pThemeSchemeNew->put_SelectedStyle(pThemeColorNew);
  123. if (SUCCEEDED(hr))
  124. {
  125. hr = pThemeManager->put_SelectedScheme(pThemeSchemeNew);
  126. if (SUCCEEDED(hr))
  127. {
  128. // This ApplyNow() call will take a little while in normal situation (~10-20 seconds) in order
  129. // to broadcast the message to all open apps. If a top level window is hung, it may take the
  130. // full 30 seconds to timeout. This code may want to move this code onto a background thread.
  131. hr = pThemeManager->ApplyNow();
  132. }
  133. }
  134. }
  135. pThemeSchemeNew->Release();
  136. pThemeColorNew->Release();
  137. pThemeSizeNew->Release();
  138. }
  139. pThemeManager->Release();
  140. }
  141. }
  142. return hr;
  143. }
  144. protected:
  145. friend HRESULT CThemesRegTreeItem_CreateInstance(IUnknown *punkOuter, REFIID riid, void **ppv);
  146. private:
  147. BOOL m_fVisualStyleOn;
  148. };
  149. HRESULT CThemesRegTreeItem_CreateInstance(IUnknown *punkOuter, REFIID riid, void **ppv)
  150. {
  151. HRESULT hr = E_OUTOFMEMORY;
  152. CThemesRegTreeItem* pti = new CThemesRegTreeItem();
  153. if (pti)
  154. {
  155. hr = pti->QueryInterface(riid, ppv);
  156. pti->Release();
  157. }
  158. return hr;
  159. }