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.

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