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.

441 lines
12 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. StringCchCopy(szPath, ARRAYSIZE(szPath), m_pszFilename);
  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. if (!PathAppend(szPath, szFilename))
  92. {
  93. hr = E_FAIL;
  94. }
  95. else
  96. {
  97. hr = HrSysAllocString(szPath, pbstrPath);
  98. }
  99. }
  100. }
  101. }
  102. return hr;
  103. }
  104. HRESULT CSkinSize::get_SystemMetricColor(IN int nSysColorIndex, OUT COLORREF * pColorRef)
  105. {
  106. HRESULT hr = E_INVALIDARG;
  107. if (pColorRef)
  108. {
  109. *pColorRef = 0x00000000;
  110. hr = _InitVisualStyle();
  111. if (SUCCEEDED(hr))
  112. {
  113. *pColorRef = GetThemeSysColor(m_hTheme, nSysColorIndex);
  114. hr = S_OK;
  115. }
  116. }
  117. return hr;
  118. }
  119. HRESULT CSkinSize::get_SystemMetricSize(IN enumSystemMetricSize nSystemMetricIndex, OUT int * pnSize)
  120. {
  121. HRESULT hr = E_INVALIDARG;
  122. if (pnSize)
  123. {
  124. *pnSize = 0;
  125. hr = _InitVisualStyle();
  126. if (SUCCEEDED(hr))
  127. {
  128. hr = S_OK;
  129. switch (nSystemMetricIndex)
  130. {
  131. case SMS_BORDERWIDTH:
  132. *pnSize = GetThemeSysSize96(m_hTheme, SM_CXBORDER);
  133. break;
  134. case SMS_SCROLLWIDTH:
  135. *pnSize = GetThemeSysSize96(m_hTheme, SM_CXVSCROLL);
  136. break;
  137. case SMS_SCROLLHEIGHT:
  138. *pnSize = GetThemeSysSize96(m_hTheme, SM_CYHSCROLL);
  139. break;
  140. case SMS_CAPTIONWIDTH:
  141. *pnSize = GetThemeSysSize96(m_hTheme, SM_CXSIZE);
  142. break;
  143. case SMS_CAPTIONHEIGHT:
  144. *pnSize = GetThemeSysSize96(m_hTheme, SM_CYSIZE);
  145. break;
  146. case SMS_SMCAPTIONWIDTH:
  147. *pnSize = GetThemeSysSize96(m_hTheme, SM_CXSMSIZE);
  148. break;
  149. case SMS_SMCAPTIONHEIGHT:
  150. *pnSize = GetThemeSysSize96(m_hTheme, SM_CYSMSIZE);
  151. break;
  152. case SMS_MENUWIDTH:
  153. *pnSize = GetThemeSysSize96(m_hTheme, SM_CXMENUSIZE);
  154. break;
  155. case SMS_MENUHEIGHT:
  156. *pnSize = GetThemeSysSize96(m_hTheme, SM_CYMENUSIZE);
  157. break;
  158. default:
  159. hr = E_INVALIDARG;
  160. break;
  161. }
  162. }
  163. }
  164. return hr;
  165. }
  166. HRESULT CSkinSize::GetSystemMetricFont(IN enumSystemMetricFont nSPIFontIndex, IN LOGFONTW * plfFont)
  167. {
  168. HRESULT hr = E_INVALIDARG;
  169. if (plfFont)
  170. {
  171. hr = _InitVisualStyle();
  172. if (SUCCEEDED(hr))
  173. {
  174. if (!m_fFontsLoaded)
  175. {
  176. if (SUCCEEDED(hr = GetThemeSysFont96(m_hTheme, TMT_CAPTIONFONT, &m_sysMetrics.schemeData.ncm.lfCaptionFont)) &&
  177. SUCCEEDED(hr = GetThemeSysFont96(m_hTheme, TMT_SMALLCAPTIONFONT, &m_sysMetrics.schemeData.ncm.lfSmCaptionFont)) &&
  178. SUCCEEDED(hr = GetThemeSysFont96(m_hTheme, TMT_MENUFONT, &m_sysMetrics.schemeData.ncm.lfMenuFont)) &&
  179. SUCCEEDED(hr = GetThemeSysFont96(m_hTheme, TMT_STATUSFONT, &m_sysMetrics.schemeData.ncm.lfStatusFont)) &&
  180. SUCCEEDED(hr = GetThemeSysFont96(m_hTheme, TMT_MSGBOXFONT, &m_sysMetrics.schemeData.ncm.lfMessageFont)) &&
  181. SUCCEEDED(hr = GetThemeSysFont96(m_hTheme, TMT_ICONTITLEFONT, &m_sysMetrics.schemeData.lfIconTitle)))
  182. {
  183. m_fFontsLoaded = TRUE;
  184. }
  185. }
  186. if (SUCCEEDED(hr))
  187. {
  188. switch (nSPIFontIndex)
  189. {
  190. case SMF_CAPTIONFONT:
  191. *plfFont = m_sysMetrics.schemeData.ncm.lfCaptionFont;
  192. break;
  193. case SMF_SMCAPTIONFONT:
  194. *plfFont = m_sysMetrics.schemeData.ncm.lfSmCaptionFont;
  195. break;
  196. case SMF_MENUFONT:
  197. *plfFont = m_sysMetrics.schemeData.ncm.lfMenuFont;
  198. break;
  199. case SMF_STATUSFONT:
  200. *plfFont = m_sysMetrics.schemeData.ncm.lfStatusFont;
  201. break;
  202. case SMF_MESSAGEFONT:
  203. *plfFont = m_sysMetrics.schemeData.ncm.lfMessageFont;
  204. break;
  205. case SMF_ICONTITLEFONT:
  206. *plfFont = m_sysMetrics.schemeData.lfIconTitle;
  207. break;
  208. default:
  209. hr = E_INVALIDARG;
  210. break;
  211. }
  212. }
  213. }
  214. }
  215. return hr;
  216. }
  217. //===========================
  218. // *** IPropertyBag Interface ***
  219. //===========================
  220. HRESULT CSkinSize::Read(IN LPCOLESTR pszPropName, IN VARIANT * pVar, IN IErrorLog *pErrorLog)
  221. {
  222. HRESULT hr = E_INVALIDARG;
  223. if (pszPropName && pVar)
  224. {
  225. if (!StrCmpW(pszPropName, SZ_PBPROP_VSBEHAVIOR_FLATMENUS))
  226. {
  227. hr = _InitVisualStyle();
  228. if (SUCCEEDED(hr))
  229. {
  230. pVar->vt = VT_BOOL;
  231. pVar->boolVal = (GetThemeSysBool(m_hTheme, TMT_FLATMENUS) ? VARIANT_TRUE : VARIANT_FALSE);
  232. LogStatus("GetThemeSysBool()=%#08lx returned %#08lx in CSkinSize::Read.\r\n", pVar->boolVal, hr);
  233. }
  234. }
  235. }
  236. return hr;
  237. }
  238. //===========================
  239. // *** IUnknown Interface ***
  240. //===========================
  241. ULONG CSkinSize::AddRef()
  242. {
  243. return InterlockedIncrement(&m_cRef);
  244. }
  245. ULONG CSkinSize::Release()
  246. {
  247. ASSERT( 0 != m_cRef );
  248. ULONG cRef = InterlockedDecrement(&m_cRef);
  249. if ( 0 == cRef )
  250. {
  251. delete this;
  252. }
  253. return cRef;
  254. }
  255. //===========================
  256. // *** Class Methods ***
  257. //===========================
  258. HRESULT CSkinSize::QueryInterface(REFIID riid, void **ppvObj)
  259. {
  260. static const QITAB qit[] = {
  261. QITABENT(CSkinSize, IThemeSize),
  262. QITABENT(CSkinSize, IPropertyBag),
  263. QITABENT(CSkinSize, IDispatch),
  264. { 0 },
  265. };
  266. return QISearch(this, qit, riid, ppvObj);
  267. }
  268. CSkinSize::CSkinSize(IN LPCWSTR pszFilename, IN LPCWSTR pszStyleName, IN LPCWSTR pszSizeName, IN LPCWSTR pszDisplayName) : m_cRef(1)
  269. {
  270. DllAddRef();
  271. // This needs to be allocated in Zero Inited Memory.
  272. // Assert that all Member Variables are inited to Zero.
  273. ASSERT(!m_hTheme);
  274. m_fFontsLoaded = FALSE;
  275. Str_SetPtr(&m_pszFilename, pszFilename);
  276. Str_SetPtr(&m_pszDisplayName, pszDisplayName);
  277. Str_SetPtr(&m_pszStyleName, pszStyleName);
  278. Str_SetPtr(&m_pszSizeName, pszSizeName);
  279. }
  280. CSkinSize::~CSkinSize()
  281. {
  282. Str_SetPtr(&m_pszFilename, NULL);
  283. Str_SetPtr(&m_pszDisplayName, NULL);
  284. Str_SetPtr(&m_pszStyleName, NULL);
  285. Str_SetPtr(&m_pszSizeName, NULL);
  286. if (m_hTheme)
  287. {
  288. CloseThemeData(m_hTheme);
  289. }
  290. DllRelease();
  291. }
  292. HRESULT CSkinSize_CreateInstance(IN LPCWSTR pszFilename, IN LPCWSTR pszStyleName, IN LPCWSTR pszSizeName, IN LPCWSTR pszDisplayName, OUT IThemeSize ** ppThemeSize)
  293. {
  294. HRESULT hr = E_INVALIDARG;
  295. if (ppThemeSize)
  296. {
  297. CSkinSize * pObject = new CSkinSize(pszFilename, pszStyleName, pszSizeName, pszDisplayName);
  298. *ppThemeSize = NULL;
  299. hr = E_OUTOFMEMORY;
  300. if (pObject)
  301. {
  302. if (pObject->m_pszFilename && pObject->m_pszStyleName &&pObject->m_pszSizeName && pObject->m_pszDisplayName)
  303. {
  304. hr = pObject->QueryInterface(IID_PPV_ARG(IThemeSize, ppThemeSize));
  305. }
  306. pObject->Release();
  307. }
  308. }
  309. return hr;
  310. }
  311. HRESULT CSkinSize_CreateInstance(IN LPCWSTR pszFilename, IN LPCWSTR pszStyleName, IN LPCWSTR pszSizeName, OUT IThemeSize ** ppThemeSize)
  312. {
  313. HRESULT hr = E_INVALIDARG;
  314. if (ppThemeSize)
  315. {
  316. *ppThemeSize = NULL;
  317. hr = E_FAIL;
  318. int nIndex;
  319. // Find the display name
  320. for (nIndex = 0; ; nIndex++)
  321. {
  322. THEMENAMEINFO themeInfo;
  323. if (SUCCEEDED(EnumThemeSizes(pszFilename, pszStyleName, nIndex, &themeInfo)))
  324. {
  325. // Did we find the correct color style?
  326. if (!StrCmpIW(pszSizeName, themeInfo.szName))
  327. {
  328. // Yes, now use it's display name to use the other creator function.
  329. hr = CSkinSize_CreateInstance(pszFilename, pszStyleName, pszSizeName, themeInfo.szDisplayName, ppThemeSize);
  330. break;
  331. }
  332. }
  333. }
  334. }
  335. return hr;
  336. }