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.

440 lines
12 KiB

  1. /*****************************************************************************\
  2. FILE: appSize.cpp
  3. DESCRIPTION:
  4. This is the Autmation Object to theme scheme object.
  5. BryanSt 4/3/2000 (Bryan Starbuck)
  6. Copyright (C) Microsoft Corp 2000-2000. All rights reserved.
  7. \*****************************************************************************/
  8. #include "priv.h"
  9. #include <cowsite.h>
  10. #include <atlbase.h>
  11. #include "util.h"
  12. #include "theme.h"
  13. #include "appsize.h"
  14. #include "stgtheme.h"
  15. //===========================
  16. // *** Class Internals & Helpers ***
  17. //===========================
  18. //===========================
  19. // *** IThemeSize Interface ***
  20. //===========================
  21. HRESULT CAppearanceSize::get_DisplayName(OUT BSTR * pbstrDisplayName)
  22. {
  23. HRESULT hr = E_INVALIDARG;
  24. if (pbstrDisplayName)
  25. {
  26. CComBSTR bstrDisplayName;
  27. *pbstrDisplayName = NULL;
  28. hr = HrBStrRegQueryValue(m_hkeySize, SZ_REGVALUE_DISPLAYNAME, &bstrDisplayName);
  29. if (SUCCEEDED(hr))
  30. {
  31. WCHAR szDisplayName[MAX_PATH];
  32. if (SUCCEEDED(SHLoadIndirectString(bstrDisplayName, szDisplayName, ARRAYSIZE(szDisplayName), NULL)))
  33. {
  34. hr = HrSysAllocStringW(szDisplayName, pbstrDisplayName);
  35. }
  36. else
  37. {
  38. hr = HrSysAllocStringW(bstrDisplayName, pbstrDisplayName);
  39. }
  40. }
  41. }
  42. return hr;
  43. }
  44. HRESULT CAppearanceSize::put_DisplayName(IN BSTR bstrDisplayName)
  45. {
  46. return HrRegSetValueString(m_hkeySize, NULL, SZ_REGVALUE_DISPLAYNAME, bstrDisplayName);
  47. }
  48. HRESULT CAppearanceSize::get_Name(OUT BSTR * pbstrName)
  49. {
  50. return HrBStrRegQueryValue(m_hkeySize, SZ_REGVALUE_DISPLAYNAME, pbstrName);
  51. }
  52. HRESULT CAppearanceSize::put_Name(IN BSTR bstrName)
  53. {
  54. return HrRegSetValueString(m_hkeySize, NULL, SZ_REGVALUE_DISPLAYNAME, bstrName);
  55. }
  56. HRESULT CAppearanceSize::get_SystemMetricColor(IN int nSysColorIndex, OUT COLORREF * pColorRef)
  57. {
  58. HRESULT hr = E_INVALIDARG;
  59. if (pColorRef)
  60. {
  61. TCHAR szFontRegValue[MAXIMUM_SUB_KEY_LENGTH];
  62. DWORD dwType;
  63. DWORD cbSize = sizeof(*pColorRef);
  64. wnsprintf(szFontRegValue, ARRAYSIZE(szFontRegValue), TEXT("Color #%d"), nSysColorIndex);
  65. hr = HrRegQueryValueEx(m_hkeySize, szFontRegValue, 0, &dwType, (BYTE *)pColorRef, &cbSize);
  66. if (SUCCEEDED(hr))
  67. {
  68. if (cbSize != sizeof(*pColorRef))
  69. {
  70. hr = E_FAIL;
  71. }
  72. }
  73. }
  74. return hr;
  75. }
  76. HRESULT CAppearanceSize::put_SystemMetricColor(IN int nSysColorIndex, IN COLORREF ColorRef)
  77. {
  78. HRESULT hr = E_INVALIDARG;
  79. TCHAR szFontRegValue[MAXIMUM_SUB_KEY_LENGTH];
  80. wnsprintf(szFontRegValue, ARRAYSIZE(szFontRegValue), TEXT("Color #%d"), nSysColorIndex);
  81. hr = HrRegSetValueEx(m_hkeySize, szFontRegValue, 0, REG_DWORD, (BYTE *)&ColorRef, sizeof(ColorRef));
  82. return hr;
  83. }
  84. HRESULT CAppearanceSize::GetSystemMetricFont(IN enumSystemMetricFont nFontIndex, IN LOGFONTW * pLogFontW)
  85. {
  86. HRESULT hr = E_INVALIDARG;
  87. if (pLogFontW)
  88. {
  89. TCHAR szFontRegValue[MAXIMUM_SUB_KEY_LENGTH];
  90. DWORD dwType;
  91. DWORD cbSize = sizeof(*pLogFontW);
  92. wnsprintf(szFontRegValue, ARRAYSIZE(szFontRegValue), TEXT("Font #%d"), nFontIndex);
  93. hr = HrRegQueryValueEx(m_hkeySize, szFontRegValue, 0, &dwType, (BYTE *)pLogFontW, &cbSize);
  94. if (SUCCEEDED(hr))
  95. {
  96. if (cbSize != sizeof(*pLogFontW))
  97. {
  98. hr = E_FAIL;
  99. }
  100. else
  101. {
  102. // CHARSET: In Win2k, fontfix.cpp was used as a hack to change the CHARSET from one language to another.
  103. // That doesn't work for many reasons: a) not called on roaming, b) not called for OS lang changes,
  104. // c) won't fix the problem for strings with multiple languages, d) etc.
  105. // Therefore, the SHELL team (BryanSt) had the NTUSER team (MSadek) agree to use DEFAULT_CHARSET all the time.
  106. // If some app has bad logic testing the charset parameter, then the NTUSER team will shim that app to fix it.
  107. // The shim would be really simple, on the return from a SystemParametersInfo(SPI_GETNONCLIENTMETRICS or ICONFONTS)
  108. // just patch the lfCharSet param to the current charset.
  109. // For all CHARSETs to DEFAULT_CHARSET
  110. pLogFontW->lfCharSet = DEFAULT_CHARSET;
  111. }
  112. }
  113. }
  114. return hr;
  115. }
  116. HRESULT CAppearanceSize::PutSystemMetricFont(IN enumSystemMetricFont nFontIndex, IN LOGFONTW * pLogFontW)
  117. {
  118. HRESULT hr = E_INVALIDARG;
  119. if (pLogFontW)
  120. {
  121. TCHAR szFontRegValue[MAXIMUM_SUB_KEY_LENGTH];
  122. wnsprintf(szFontRegValue, ARRAYSIZE(szFontRegValue), TEXT("Font #%d"), nFontIndex);
  123. hr = HrRegSetValueEx(m_hkeySize, szFontRegValue, 0, REG_BINARY, (BYTE *)pLogFontW, sizeof(*pLogFontW));
  124. }
  125. return hr;
  126. }
  127. HRESULT CAppearanceSize::get_SystemMetricSize(IN enumSystemMetricSize nSystemMetricIndex, OUT int * pnSize)
  128. {
  129. HRESULT hr = E_INVALIDARG;
  130. if (pnSize)
  131. {
  132. TCHAR szFontRegValue[MAXIMUM_SUB_KEY_LENGTH];
  133. DWORD dwType;
  134. INT64 nSize64;
  135. DWORD cbSize = sizeof(nSize64);
  136. *pnSize = 0;
  137. wnsprintf(szFontRegValue, ARRAYSIZE(szFontRegValue), TEXT("Size #%d"), nSystemMetricIndex);
  138. hr = HrRegQueryValueEx(m_hkeySize, szFontRegValue, 0, &dwType, (BYTE *)&nSize64, &cbSize);
  139. if (SUCCEEDED(hr))
  140. {
  141. if (cbSize != sizeof(nSize64))
  142. {
  143. hr = E_FAIL;
  144. }
  145. else
  146. {
  147. *pnSize = (int)nSize64;
  148. }
  149. }
  150. }
  151. return hr;
  152. }
  153. HRESULT CAppearanceSize::put_SystemMetricSize(IN enumSystemMetricSize nSystemMetricIndex, IN int nSize)
  154. {
  155. HRESULT hr = E_INVALIDARG;
  156. TCHAR szFontRegValue[MAXIMUM_SUB_KEY_LENGTH];
  157. INT64 nSize64 = (INT64)nSize;
  158. wnsprintf(szFontRegValue, ARRAYSIZE(szFontRegValue), TEXT("Size #%d"), nSystemMetricIndex);
  159. hr = HrRegSetValueEx(m_hkeySize, szFontRegValue, 0, REG_QWORD, (BYTE *)&nSize64, sizeof(nSize64));
  160. return hr;
  161. }
  162. #define SZ_WEBVW_NOSKIN_NORMAL_DIR L"NormalContrast"
  163. #define SZ_WEBVW_NOSKIN_HIBLACK_DIR L"HighContrastBlack"
  164. #define SZ_WEBVW_NOSKIN_HIWHITE_DIR L"HighContrastWhite"
  165. #define SZ_DIR_RESOURCES_THEMES L"Themes"
  166. HRESULT CAppearanceSize::get_WebviewCSS(OUT BSTR * pbstrPath)
  167. {
  168. HRESULT hr = E_INVALIDARG;
  169. if (pbstrPath)
  170. {
  171. WCHAR szPath[MAX_PATH];
  172. *pbstrPath = NULL;
  173. hr = SHGetResourcePath(TRUE, szPath, ARRAYSIZE(szPath));
  174. if (SUCCEEDED(hr))
  175. {
  176. PathAppend(szPath, SZ_DIR_RESOURCES_THEMES);
  177. enumThemeContrastLevels ContrastLevel = CONTRAST_NORMAL;
  178. get_ContrastLevel(&ContrastLevel);
  179. switch (ContrastLevel)
  180. {
  181. case CONTRAST_HIGHBLACK:
  182. PathAppend(szPath, SZ_WEBVW_NOSKIN_HIBLACK_DIR);
  183. break;
  184. case CONTRAST_HIGHWHITE:
  185. PathAppend(szPath, SZ_WEBVW_NOSKIN_HIWHITE_DIR);
  186. break;
  187. default:
  188. case CONTRAST_NORMAL:
  189. PathAppend(szPath, SZ_WEBVW_NOSKIN_NORMAL_DIR);
  190. break;
  191. }
  192. PathAppend(szPath, SZ_WEBVW_SKIN_FILE);
  193. hr = HrSysAllocString(szPath, pbstrPath);
  194. }
  195. }
  196. return hr;
  197. }
  198. HRESULT CAppearanceSize::get_ContrastLevel(OUT enumThemeContrastLevels * pContrastLevel)
  199. {
  200. HRESULT hr = E_INVALIDARG;
  201. if (pContrastLevel)
  202. {
  203. DWORD dwType;
  204. DWORD cbSize = sizeof(*pContrastLevel);
  205. *pContrastLevel = CONTRAST_NORMAL;
  206. hr = HrRegQueryValueEx(m_hkeySize, SZ_REGVALUE_CONTRASTLEVEL, 0, &dwType, (BYTE *)pContrastLevel, &cbSize);
  207. if (SUCCEEDED(hr))
  208. {
  209. if (REG_DWORD != dwType)
  210. {
  211. *pContrastLevel = CONTRAST_NORMAL;
  212. hr = E_FAIL;
  213. }
  214. }
  215. }
  216. return hr;
  217. }
  218. HRESULT CAppearanceSize::put_ContrastLevel(IN enumThemeContrastLevels ContrastLevel)
  219. {
  220. return HrRegSetValueEx(m_hkeySize, SZ_REGVALUE_CONTRASTLEVEL, 0, REG_DWORD, (BYTE *)&ContrastLevel, sizeof(ContrastLevel));
  221. }
  222. //===========================
  223. // *** IPropertyBag Interface ***
  224. //===========================
  225. HRESULT CAppearanceSize::Read(IN LPCOLESTR pszPropName, IN VARIANT * pVar, IN IErrorLog *pErrorLog)
  226. {
  227. HRESULT hr = E_INVALIDARG;
  228. if (pszPropName && pVar)
  229. {
  230. if (!StrCmpW(pszPropName, SZ_PBPROP_VSBEHAVIOR_FLATMENUS))
  231. {
  232. pVar->vt = VT_BOOL;
  233. hr = S_OK;
  234. // We default to zero because that's what non-visual styles will have.
  235. pVar->boolVal = (HrRegGetDWORD(m_hkeySize, NULL, SZ_REGVALUE_FLATMENUS, 0x00000001) ? VARIANT_TRUE : VARIANT_FALSE);
  236. }
  237. else if (!StrCmpW(pszPropName, SZ_PBPROP_COLORSCHEME_LEGACYNAME))
  238. {
  239. TCHAR szLegacyName[MAX_PATH];
  240. hr = HrRegGetValueString(m_hkeySize, NULL, SZ_REGVALUE_LEGACYNAME, szLegacyName, ARRAYSIZE(szLegacyName));
  241. if (SUCCEEDED(hr))
  242. {
  243. pVar->vt = VT_BSTR;
  244. hr = HrSysAllocString(szLegacyName, &pVar->bstrVal);
  245. }
  246. }
  247. }
  248. return hr;
  249. }
  250. HRESULT CAppearanceSize::Write(IN LPCOLESTR pszPropName, IN VARIANT * pVar)
  251. {
  252. HRESULT hr = E_INVALIDARG;
  253. if (pszPropName && pVar)
  254. {
  255. if (!StrCmpW(pszPropName, SZ_PBPROP_VSBEHAVIOR_FLATMENUS) &&
  256. (VT_BOOL == pVar->vt))
  257. {
  258. DWORD dwData = ((VARIANT_TRUE == pVar->boolVal) ? 0x00000001 : 0x000000);
  259. hr = HrRegSetDWORD(m_hkeySize, NULL, SZ_REGVALUE_FLATMENUS, dwData);
  260. }
  261. else if (!StrCmpW(pszPropName, SZ_PBPROP_COLORSCHEME_LEGACYNAME) &&
  262. (VT_BSTR == pVar->vt))
  263. {
  264. hr = HrRegSetValueString(m_hkeySize, NULL, SZ_REGVALUE_LEGACYNAME, pVar->bstrVal);
  265. }
  266. }
  267. return hr;
  268. }
  269. //===========================
  270. // *** IUnknown Interface ***
  271. //===========================
  272. ULONG CAppearanceSize::AddRef()
  273. {
  274. return InterlockedIncrement(&m_cRef);
  275. }
  276. ULONG CAppearanceSize::Release()
  277. {
  278. if (InterlockedDecrement(&m_cRef))
  279. return m_cRef;
  280. delete this;
  281. return 0;
  282. }
  283. //===========================
  284. // *** Class Methods ***
  285. //===========================
  286. HRESULT CAppearanceSize::QueryInterface(REFIID riid, void **ppvObj)
  287. {
  288. static const QITAB qit[] = {
  289. QITABENT(CAppearanceSize, IThemeSize),
  290. QITABENT(CAppearanceSize, IDispatch),
  291. QITABENT(CAppearanceSize, IPropertyBag),
  292. { 0 },
  293. };
  294. return QISearch(this, qit, riid, ppvObj);
  295. }
  296. CAppearanceSize::CAppearanceSize(IN HKEY hkeyStyle, IN HKEY hkeySize) : CImpIDispatch(LIBID_Theme, 1, 0, IID_IThemeSize), m_cRef(1)
  297. {
  298. DllAddRef();
  299. // This needs to be allocated in Zero Inited Memory.
  300. // Assert that all Member Variables are inited to Zero.
  301. m_hkeyStyle = hkeyStyle;
  302. m_hkeySize = hkeySize;
  303. }
  304. CAppearanceSize::~CAppearanceSize()
  305. {
  306. if (m_hkeyStyle)
  307. {
  308. RegCloseKey(m_hkeyStyle);
  309. }
  310. if (m_hkeySize)
  311. {
  312. RegCloseKey(m_hkeySize);
  313. }
  314. DllRelease();
  315. }
  316. HRESULT CAppearanceSize_CreateInstance(IN HKEY hkeyStyle, IN HKEY hkeySize, OUT IThemeSize ** ppThemeSize)
  317. {
  318. HRESULT hr = E_INVALIDARG;
  319. if (ppThemeSize)
  320. {
  321. CAppearanceSize * pObject = new CAppearanceSize(hkeyStyle, hkeySize);
  322. *ppThemeSize = NULL;
  323. if (pObject)
  324. {
  325. hr = pObject->QueryInterface(IID_PPV_ARG(IThemeSize, ppThemeSize));
  326. pObject->Release();
  327. }
  328. else
  329. {
  330. hr = E_OUTOFMEMORY;
  331. }
  332. }
  333. return hr;
  334. }