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.

435 lines
11 KiB

  1. /*****************************************************************************\
  2. FILE: thSize.cpp
  3. DESCRIPTION:
  4. This is the Autmation Object to theme size object. This one will be
  5. for the Skin objects.
  6. BryanSt 5/13/2000 (Bryan Starbuck)
  7. Copyright (C) Microsoft Corp 2000-2000. All rights reserved.
  8. \*****************************************************************************/
  9. #include "priv.h"
  10. #include <cowsite.h>
  11. #include <atlbase.h>
  12. #include "util.h"
  13. #include "thsize.h"
  14. //===========================
  15. // *** Class Internals & Helpers ***
  16. //===========================
  17. HRESULT CSkinSize::_InitVisualStyle(void)
  18. {
  19. HRESULT hr = S_OK;
  20. if (!m_hTheme)
  21. {
  22. if (m_pszFilename && m_pszStyleName && m_pszSizeName)
  23. {
  24. HTHEMEFILE hThemeFile;
  25. // Load the skin
  26. hr = OpenThemeFile(m_pszFilename, m_pszStyleName, m_pszSizeName, &hThemeFile, FALSE);
  27. LogStatus("OpenThemeFile(path=\"%ls\", color=\"%ls\", size=\"%ls\") returned %#08lx in CSkinSize::_InitVisualStyle.\r\n", m_pszFilename, m_pszStyleName, m_pszSizeName, hr);
  28. if (SUCCEEDED(hr))
  29. {
  30. m_hTheme = OpenThemeDataFromFile(hThemeFile, NULL, NULL, FALSE);
  31. LogStatus("OpenThemeDataFromFile() returned %#08lx in CSkinSize::_InitVisualStyle.\r\n", m_hTheme);
  32. hr = ((NULL == m_hTheme) ? E_FAIL : S_OK);
  33. CloseThemeFile(hThemeFile);
  34. }
  35. }
  36. else
  37. {
  38. hr = E_INVALIDARG;
  39. }
  40. }
  41. return hr;
  42. }
  43. //===========================
  44. // *** IThemeSize Interface ***
  45. //===========================
  46. HRESULT CSkinSize::get_DisplayName(OUT BSTR * pbstrDisplayName)
  47. {
  48. return HrSysAllocString(m_pszDisplayName, pbstrDisplayName);
  49. }
  50. HRESULT CSkinSize::put_DisplayName(IN BSTR bstrDisplayName)
  51. {
  52. HRESULT hr = E_INVALIDARG;
  53. if (bstrDisplayName)
  54. {
  55. Str_SetPtr(&m_pszDisplayName, bstrDisplayName);
  56. hr = (m_pszDisplayName ? S_OK : E_OUTOFMEMORY);
  57. }
  58. return hr;
  59. }
  60. HRESULT CSkinSize::get_Name(OUT BSTR * pbstrName)
  61. {
  62. return HrSysAllocString(m_pszSizeName, pbstrName);
  63. }
  64. HRESULT CSkinSize::put_Name(IN BSTR bstrName)
  65. {
  66. HRESULT hr = E_INVALIDARG;
  67. if (bstrName)
  68. {
  69. Str_SetPtr(&m_pszSizeName, bstrName);
  70. hr = (m_pszSizeName ? S_OK : E_OUTOFMEMORY);
  71. }
  72. return hr;
  73. }
  74. HRESULT CSkinSize::get_WebviewCSS(OUT BSTR * pbstrPath)
  75. {
  76. HRESULT hr = E_INVALIDARG;
  77. if (pbstrPath)
  78. {
  79. *pbstrPath = NULL;
  80. hr = _InitVisualStyle();
  81. if (SUCCEEDED(hr))
  82. {
  83. WCHAR szPath[MAX_PATH];
  84. WCHAR szFilename[MAX_PATH];
  85. StrCpyNW(szPath, m_pszFilename, ARRAYSIZE(szPath));
  86. PathRemoveFileSpec(szPath); // Remove the filename ("xx.msstyles") from the path.
  87. hr = GetThemeSysString(m_hTheme, TMT_CSSNAME, szFilename, ARRAYSIZE(szFilename));
  88. LogStatus("GetThemeDefaults(szFilename=\"%ls\") returned %#08lx in CSkinSize::get_WebviewCSS.\r\n", szFilename, hr);
  89. if (SUCCEEDED(hr))
  90. {
  91. PathAppend(szPath, szFilename);
  92. hr = HrSysAllocString(szPath, pbstrPath);
  93. }
  94. }
  95. }
  96. return hr;
  97. }
  98. HRESULT CSkinSize::get_SystemMetricColor(IN int nSysColorIndex, OUT COLORREF * pColorRef)
  99. {
  100. HRESULT hr = E_INVALIDARG;
  101. if (pColorRef)
  102. {
  103. *pColorRef = 0x00000000;
  104. hr = _InitVisualStyle();
  105. if (SUCCEEDED(hr))
  106. {
  107. *pColorRef = GetThemeSysColor(m_hTheme, nSysColorIndex);
  108. hr = S_OK;
  109. }
  110. // LogStatus("CSkinSize::get_SystemMetricColor() GetThemeSysColor()=%#08lx returned %#08lx in CSkinSize::get_SystemMetricColor.\r\n", *pColorRef, hr);
  111. }
  112. return hr;
  113. }
  114. HRESULT CSkinSize::get_SystemMetricSize(IN enumSystemMetricSize nSystemMetricIndex, OUT int * pnSize)
  115. {
  116. HRESULT hr = E_INVALIDARG;
  117. if (pnSize)
  118. {
  119. *pnSize = 0;
  120. hr = _InitVisualStyle();
  121. if (SUCCEEDED(hr))
  122. {
  123. hr = S_OK;
  124. switch (nSystemMetricIndex)
  125. {
  126. case SMS_BORDERWIDTH:
  127. *pnSize = GetThemeSysSize96(m_hTheme, SM_CXBORDER);
  128. break;
  129. case SMS_SCROLLWIDTH:
  130. *pnSize = GetThemeSysSize96(m_hTheme, SM_CXVSCROLL);
  131. break;
  132. case SMS_SCROLLHEIGHT:
  133. *pnSize = GetThemeSysSize96(m_hTheme, SM_CYHSCROLL);
  134. break;
  135. case SMS_CAPTIONWIDTH:
  136. *pnSize = GetThemeSysSize96(m_hTheme, SM_CXSIZE);
  137. break;
  138. case SMS_CAPTIONHEIGHT:
  139. *pnSize = GetThemeSysSize96(m_hTheme, SM_CYSIZE);
  140. break;
  141. case SMS_SMCAPTIONWIDTH:
  142. *pnSize = GetThemeSysSize96(m_hTheme, SM_CXSMSIZE);
  143. break;
  144. case SMS_SMCAPTIONHEIGHT:
  145. *pnSize = GetThemeSysSize96(m_hTheme, SM_CYSMSIZE);
  146. break;
  147. case SMS_MENUWIDTH:
  148. *pnSize = GetThemeSysSize96(m_hTheme, SM_CXMENUSIZE);
  149. break;
  150. case SMS_MENUHEIGHT:
  151. *pnSize = GetThemeSysSize96(m_hTheme, SM_CYMENUSIZE);
  152. break;
  153. default:
  154. hr = E_INVALIDARG;
  155. break;
  156. }
  157. }
  158. }
  159. return hr;
  160. }
  161. HRESULT CSkinSize::GetSystemMetricFont(IN enumSystemMetricFont nSPIFontIndex, IN LOGFONTW * plfFont)
  162. {
  163. HRESULT hr = E_INVALIDARG;
  164. if (plfFont)
  165. {
  166. hr = _InitVisualStyle();
  167. if (SUCCEEDED(hr))
  168. {
  169. if (!m_fFontsLoaded)
  170. {
  171. if (SUCCEEDED(hr = GetThemeSysFont96(m_hTheme, TMT_CAPTIONFONT, &m_sysMetrics.schemeData.ncm.lfCaptionFont)) &&
  172. SUCCEEDED(hr = GetThemeSysFont96(m_hTheme, TMT_SMALLCAPTIONFONT, &m_sysMetrics.schemeData.ncm.lfSmCaptionFont)) &&
  173. SUCCEEDED(hr = GetThemeSysFont96(m_hTheme, TMT_MENUFONT, &m_sysMetrics.schemeData.ncm.lfMenuFont)) &&
  174. SUCCEEDED(hr = GetThemeSysFont96(m_hTheme, TMT_STATUSFONT, &m_sysMetrics.schemeData.ncm.lfStatusFont)) &&
  175. SUCCEEDED(hr = GetThemeSysFont96(m_hTheme, TMT_MSGBOXFONT, &m_sysMetrics.schemeData.ncm.lfMessageFont)) &&
  176. SUCCEEDED(hr = GetThemeSysFont96(m_hTheme, TMT_ICONTITLEFONT, &m_sysMetrics.schemeData.lfIconTitle)))
  177. {
  178. m_fFontsLoaded = TRUE;
  179. }
  180. }
  181. if (SUCCEEDED(hr))
  182. {
  183. switch (nSPIFontIndex)
  184. {
  185. case SMF_CAPTIONFONT:
  186. *plfFont = m_sysMetrics.schemeData.ncm.lfCaptionFont;
  187. break;
  188. case SMF_SMCAPTIONFONT:
  189. *plfFont = m_sysMetrics.schemeData.ncm.lfSmCaptionFont;
  190. break;
  191. case SMF_MENUFONT:
  192. *plfFont = m_sysMetrics.schemeData.ncm.lfMenuFont;
  193. break;
  194. case SMF_STATUSFONT:
  195. *plfFont = m_sysMetrics.schemeData.ncm.lfStatusFont;
  196. break;
  197. case SMF_MESSAGEFONT:
  198. *plfFont = m_sysMetrics.schemeData.ncm.lfMessageFont;
  199. break;
  200. case SMF_ICONTITLEFONT:
  201. *plfFont = m_sysMetrics.schemeData.lfIconTitle;
  202. break;
  203. default:
  204. hr = E_INVALIDARG;
  205. break;
  206. }
  207. }
  208. }
  209. }
  210. return hr;
  211. }
  212. //===========================
  213. // *** IPropertyBag Interface ***
  214. //===========================
  215. HRESULT CSkinSize::Read(IN LPCOLESTR pszPropName, IN VARIANT * pVar, IN IErrorLog *pErrorLog)
  216. {
  217. HRESULT hr = E_INVALIDARG;
  218. if (pszPropName && pVar)
  219. {
  220. if (!StrCmpW(pszPropName, SZ_PBPROP_VSBEHAVIOR_FLATMENUS))
  221. {
  222. hr = _InitVisualStyle();
  223. if (SUCCEEDED(hr))
  224. {
  225. pVar->vt = VT_BOOL;
  226. pVar->boolVal = (GetThemeSysBool(m_hTheme, TMT_FLATMENUS) ? VARIANT_TRUE : VARIANT_FALSE);
  227. LogStatus("GetThemeSysBool()=%#08lx returned %#08lx in CSkinSize::Read.\r\n", pVar->boolVal, hr);
  228. }
  229. }
  230. }
  231. return hr;
  232. }
  233. //===========================
  234. // *** IUnknown Interface ***
  235. //===========================
  236. ULONG CSkinSize::AddRef()
  237. {
  238. return InterlockedIncrement(&m_cRef);
  239. }
  240. ULONG CSkinSize::Release()
  241. {
  242. if (InterlockedDecrement(&m_cRef))
  243. return m_cRef;
  244. delete this;
  245. return 0;
  246. }
  247. //===========================
  248. // *** Class Methods ***
  249. //===========================
  250. HRESULT CSkinSize::QueryInterface(REFIID riid, void **ppvObj)
  251. {
  252. static const QITAB qit[] = {
  253. QITABENT(CSkinSize, IThemeSize),
  254. QITABENT(CSkinSize, IPropertyBag),
  255. QITABENT(CSkinSize, IDispatch),
  256. { 0 },
  257. };
  258. return QISearch(this, qit, riid, ppvObj);
  259. }
  260. CSkinSize::CSkinSize(IN LPCWSTR pszFilename, IN LPCWSTR pszStyleName, IN LPCWSTR pszSizeName, IN LPCWSTR pszDisplayName) : CImpIDispatch(LIBID_Theme, 1, 0, IID_IThemeSize), m_cRef(1)
  261. {
  262. DllAddRef();
  263. // This needs to be allocated in Zero Inited Memory.
  264. // Assert that all Member Variables are inited to Zero.
  265. ASSERT(!m_hTheme);
  266. m_fFontsLoaded = FALSE;
  267. Str_SetPtr(&m_pszFilename, pszFilename);
  268. Str_SetPtr(&m_pszDisplayName, pszDisplayName);
  269. Str_SetPtr(&m_pszStyleName, pszStyleName);
  270. Str_SetPtr(&m_pszSizeName, pszSizeName);
  271. }
  272. CSkinSize::~CSkinSize()
  273. {
  274. Str_SetPtr(&m_pszFilename, NULL);
  275. Str_SetPtr(&m_pszDisplayName, NULL);
  276. Str_SetPtr(&m_pszStyleName, NULL);
  277. Str_SetPtr(&m_pszSizeName, NULL);
  278. if (m_hTheme)
  279. {
  280. CloseThemeData(m_hTheme);
  281. }
  282. DllRelease();
  283. }
  284. HRESULT CSkinSize_CreateInstance(IN LPCWSTR pszFilename, IN LPCWSTR pszStyleName, IN LPCWSTR pszSizeName, IN LPCWSTR pszDisplayName, OUT IThemeSize ** ppThemeSize)
  285. {
  286. HRESULT hr = E_INVALIDARG;
  287. if (ppThemeSize)
  288. {
  289. CSkinSize * pObject = new CSkinSize(pszFilename, pszStyleName, pszSizeName, pszDisplayName);
  290. *ppThemeSize = NULL;
  291. hr = E_OUTOFMEMORY;
  292. if (pObject)
  293. {
  294. if (pObject->m_pszFilename && pObject->m_pszStyleName &&pObject->m_pszSizeName && pObject->m_pszDisplayName)
  295. {
  296. hr = pObject->QueryInterface(IID_PPV_ARG(IThemeSize, ppThemeSize));
  297. }
  298. pObject->Release();
  299. }
  300. }
  301. return hr;
  302. }
  303. HRESULT CSkinSize_CreateInstance(IN LPCWSTR pszFilename, IN LPCWSTR pszStyleName, IN LPCWSTR pszSizeName, OUT IThemeSize ** ppThemeSize)
  304. {
  305. HRESULT hr = E_INVALIDARG;
  306. if (ppThemeSize)
  307. {
  308. *ppThemeSize = NULL;
  309. hr = E_FAIL;
  310. int nIndex;
  311. // Find the display name
  312. for (nIndex = 0; ; nIndex++)
  313. {
  314. THEMENAMEINFO themeInfo;
  315. if (SUCCEEDED(EnumThemeSizes(pszFilename, pszStyleName, nIndex, &themeInfo)))
  316. {
  317. // Did we find the correct color style?
  318. if (!StrCmpIW(pszSizeName, themeInfo.szName))
  319. {
  320. // Yes, now use it's display name to use the other creator function.
  321. hr = CSkinSize_CreateInstance(pszFilename, pszStyleName, pszSizeName, themeInfo.szDisplayName, ppThemeSize);
  322. break;
  323. }
  324. }
  325. }
  326. }
  327. return hr;
  328. }