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.

382 lines
10 KiB

  1. /*****************************************************************************\
  2. FILE: thStyle.cpp
  3. DESCRIPTION:
  4. This is the Autmation Object to theme style 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 "theme.h"
  14. #include "thsize.h"
  15. #include "thstyle.h"
  16. //===========================
  17. // *** Class Internals & Helpers ***
  18. //===========================
  19. //===========================
  20. // *** ITheme Interface ***
  21. //===========================
  22. HRESULT CSkinStyle::get_DisplayName(OUT BSTR * pbstrDisplayName)
  23. {
  24. return HrSysAllocString(m_pszDisplayName, pbstrDisplayName);
  25. }
  26. HRESULT CSkinStyle::put_DisplayName(IN BSTR bstrDisplayName)
  27. {
  28. HRESULT hr = E_INVALIDARG;
  29. if (bstrDisplayName)
  30. {
  31. Str_SetPtr(&m_pszDisplayName, bstrDisplayName);
  32. hr = (m_pszDisplayName ? S_OK : E_OUTOFMEMORY);
  33. }
  34. return hr;
  35. }
  36. HRESULT CSkinStyle::get_Name(OUT BSTR * pbstrName)
  37. {
  38. return HrSysAllocString(m_pszStyleName, pbstrName);
  39. }
  40. HRESULT CSkinStyle::put_Name(IN BSTR bstrName)
  41. {
  42. HRESULT hr = E_INVALIDARG;
  43. if (bstrName)
  44. {
  45. Str_SetPtr(&m_pszStyleName, bstrName);
  46. hr = (m_pszStyleName ? S_OK : E_OUTOFMEMORY);
  47. }
  48. return hr;
  49. }
  50. HRESULT CSkinStyle::get_length(OUT long * pnLength)
  51. {
  52. HRESULT hr = E_INVALIDARG;
  53. if (pnLength)
  54. {
  55. hr = S_OK;
  56. if (COLLECTION_SIZE_UNINITIALIZED == m_nSize)
  57. {
  58. THEMENAMEINFO themeInfo;
  59. m_nSize = 0;
  60. while (SUCCEEDED(EnumThemeSizes(m_pszFilename, m_pszStyleName, m_nSize, &themeInfo)))
  61. {
  62. m_nSize++;
  63. }
  64. }
  65. *pnLength = m_nSize;
  66. }
  67. return hr;
  68. }
  69. HRESULT CSkinStyle::get_item(IN VARIANT varIndex, OUT IThemeSize ** ppThemeSize)
  70. {
  71. HRESULT hr = E_INVALIDARG;
  72. if (ppThemeSize)
  73. {
  74. long nCount = 0;
  75. get_length(&nCount);
  76. *ppThemeSize = NULL;
  77. // This is sortof gross, but if we are passed a pointer to another variant, simply
  78. // update our copy here...
  79. if (varIndex.vt == (VT_BYREF | VT_VARIANT) && varIndex.pvarVal)
  80. varIndex = *(varIndex.pvarVal);
  81. switch (varIndex.vt)
  82. {
  83. case VT_I2:
  84. varIndex.lVal = (long)varIndex.iVal;
  85. // And fall through...
  86. case VT_I4:
  87. if ((varIndex.lVal >= 0) && (varIndex.lVal < nCount))
  88. {
  89. THEMENAMEINFO themeInfo;
  90. hr = EnumThemeSizes(m_pszFilename, m_pszStyleName, varIndex.lVal, &themeInfo);
  91. LogStatus("EnumThemeSizes(path=\"%ls\", style=\"%ls\") returned %#08lx in CSkinStyle::get_item.\r\n", m_pszFilename, m_pszStyleName, hr);
  92. if (SUCCEEDED(hr))
  93. {
  94. hr = CSkinSize_CreateInstance(m_pszFilename, m_pszStyleName, themeInfo.szName, themeInfo.szDisplayName, ppThemeSize);
  95. }
  96. }
  97. break;
  98. case VT_BSTR:
  99. if (varIndex.bstrVal)
  100. {
  101. if (varIndex.bstrVal[0])
  102. {
  103. THEMENAMEINFO themeInfo;
  104. for (long nIndex = 0; FAILED(hr) && (nIndex < nCount) && SUCCEEDED(EnumThemeSizes(m_pszFilename, m_pszStyleName, nIndex, &themeInfo));
  105. nIndex++)
  106. {
  107. if (!StrCmpIW(themeInfo.szDisplayName, varIndex.bstrVal) ||
  108. !StrCmpIW(themeInfo.szName, varIndex.bstrVal))
  109. {
  110. hr = CSkinSize_CreateInstance(m_pszFilename, m_pszStyleName, themeInfo.szName, themeInfo.szDisplayName, ppThemeSize);
  111. }
  112. }
  113. }
  114. else
  115. {
  116. if (m_pszFilename && m_pszStyleName)
  117. {
  118. TCHAR szColor[MAX_PATH];
  119. TCHAR szSize[MAX_PATH];
  120. hr = GetThemeDefaults(m_pszFilename, szColor, ARRAYSIZE(szColor), szSize, ARRAYSIZE(szSize));
  121. LogStatus("GetThemeDefaults(szCurrentStyle=\"%ls\", szColor=\"%ls\", szSize=\"%ls\") returned %#08lx in CSkinStyle::get_item.\r\n", m_pszFilename, szColor, szSize, hr);
  122. if (SUCCEEDED(hr) && !StrCmpI(m_pszStyleName, szColor))
  123. {
  124. hr = CSkinSize_CreateInstance(m_pszFilename, m_pszStyleName, szSize, ppThemeSize);
  125. }
  126. }
  127. }
  128. }
  129. break;
  130. default:
  131. hr = E_NOTIMPL;
  132. }
  133. }
  134. return hr;
  135. }
  136. HRESULT CSkinStyle::get_SelectedSize(OUT IThemeSize ** ppThemeSize)
  137. {
  138. HRESULT hr = E_INVALIDARG;
  139. if (ppThemeSize)
  140. {
  141. WCHAR szCurrentPath[MAX_PATH];
  142. WCHAR szCurrentStyle[MAX_PATH];
  143. WCHAR szCurrentSize[MAX_PATH];
  144. szCurrentPath[0] = 0;
  145. szCurrentPath[0] = 0;
  146. szCurrentPath[0] = 0;
  147. *ppThemeSize = NULL;
  148. if (!m_pSelectedSize)
  149. {
  150. hr = GetCurrentThemeName(szCurrentPath, ARRAYSIZE(szCurrentPath), szCurrentStyle, ARRAYSIZE(szCurrentStyle), szCurrentSize, ARRAYSIZE(szCurrentSize));
  151. LogStatus("GetCurrentThemeName(path=\"%ls\", color=\"%ls\", size=\"%ls\") returned %#08lx.\r\n", szCurrentPath, szCurrentStyle, szCurrentSize, hr);
  152. if (SUCCEEDED(hr))
  153. {
  154. // Is this the currently selected skin and style?
  155. if (!StrCmpIW(m_pszFilename, szCurrentPath) &&
  156. !StrCmpIW(m_pszStyleName, szCurrentStyle))
  157. {
  158. // Yes, so get the size from that API.
  159. hr = CSkinSize_CreateInstance(szCurrentPath, szCurrentStyle, szCurrentSize, &m_pSelectedSize);
  160. }
  161. else
  162. {
  163. hr = E_FAIL;
  164. }
  165. }
  166. if (FAILED(hr))
  167. {
  168. // No, so find the default color style for this skin(scheme).
  169. hr = GetThemeDefaults(m_pszFilename, szCurrentStyle, ARRAYSIZE(szCurrentStyle), szCurrentSize, ARRAYSIZE(szCurrentSize));
  170. LogStatus("GetThemeDefaults(m_pszFilename=\"%ls\", szCurrentStyle=\"%ls\", szCurrentSize=\"%ls\") returned %#08lx in CSkinStyle::get_SelectedSize.\r\n", m_pszFilename, szCurrentStyle, szCurrentSize, hr);
  171. if (SUCCEEDED(hr))
  172. {
  173. hr = CSkinSize_CreateInstance(m_pszFilename, szCurrentStyle, szCurrentSize, &m_pSelectedSize);
  174. }
  175. }
  176. }
  177. if (m_pSelectedSize)
  178. {
  179. IUnknown_Set((IUnknown **)ppThemeSize, m_pSelectedSize);
  180. if (*ppThemeSize)
  181. {
  182. hr = S_OK;
  183. }
  184. }
  185. }
  186. return hr;
  187. }
  188. HRESULT CSkinStyle::put_SelectedSize(IN IThemeSize * pThemeSize)
  189. {
  190. IUnknown_Set((IUnknown **)&m_pSelectedSize, pThemeSize);
  191. return S_OK;
  192. }
  193. HRESULT CSkinStyle::AddSize(OUT IThemeSize ** ppThemeSize)
  194. {
  195. HRESULT hr = E_INVALIDARG;
  196. if (ppThemeSize)
  197. {
  198. *ppThemeSize = NULL;
  199. hr = E_NOTIMPL;
  200. }
  201. return hr;
  202. }
  203. //===========================
  204. // *** IUnknown Interface ***
  205. //===========================
  206. ULONG CSkinStyle::AddRef()
  207. {
  208. return InterlockedIncrement(&m_cRef);
  209. }
  210. ULONG CSkinStyle::Release()
  211. {
  212. ASSERT( 0 != m_cRef );
  213. ULONG cRef = InterlockedDecrement(&m_cRef);
  214. if ( 0 == cRef )
  215. {
  216. delete this;
  217. }
  218. return cRef;
  219. }
  220. //===========================
  221. // *** Class Methods ***
  222. //===========================
  223. HRESULT CSkinStyle::QueryInterface(REFIID riid, void **ppvObj)
  224. {
  225. static const QITAB qit[] = {
  226. QITABENT(CSkinStyle, IThemeStyle),
  227. QITABENT(CSkinStyle, IDispatch),
  228. { 0 },
  229. };
  230. return QISearch(this, qit, riid, ppvObj);
  231. }
  232. CSkinStyle::CSkinStyle(IN LPCWSTR pszFilename, IN LPCWSTR pszStyleName, IN LPCWSTR pszDisplayName) : m_cRef(1)
  233. {
  234. DllAddRef();
  235. // This needs to be allocated in Zero Inited Memory.
  236. // Assert that all Member Variables are inited to Zero.
  237. ASSERT(!m_pSelectedSize);
  238. Str_SetPtr(&m_pszFilename, pszFilename);
  239. Str_SetPtr(&m_pszDisplayName, pszDisplayName);
  240. Str_SetPtr(&m_pszStyleName, pszStyleName);
  241. m_nSize = COLLECTION_SIZE_UNINITIALIZED;
  242. }
  243. CSkinStyle::~CSkinStyle()
  244. {
  245. ATOMICRELEASE(m_pSelectedSize);
  246. Str_SetPtr(&m_pszFilename, NULL);
  247. Str_SetPtr(&m_pszDisplayName, NULL);
  248. Str_SetPtr(&m_pszStyleName, NULL);
  249. DllRelease();
  250. }
  251. HRESULT CSkinStyle_CreateInstance(IN LPCWSTR pszFilename, IN LPCWSTR pszStyleName, IN LPCWSTR pszDisplayName, OUT IThemeStyle ** ppThemeStyle)
  252. {
  253. HRESULT hr = E_INVALIDARG;
  254. if (ppThemeStyle)
  255. {
  256. CSkinStyle * pObject = new CSkinStyle(pszFilename, pszStyleName, pszDisplayName);
  257. *ppThemeStyle = NULL;
  258. hr = E_OUTOFMEMORY;
  259. if (pObject)
  260. {
  261. if (pObject->m_pszFilename && pObject->m_pszStyleName && pObject->m_pszDisplayName)
  262. {
  263. hr = pObject->QueryInterface(IID_PPV_ARG(IThemeStyle, ppThemeStyle));
  264. }
  265. pObject->Release();
  266. }
  267. }
  268. return hr;
  269. }
  270. HRESULT CSkinStyle_CreateInstance(IN LPCWSTR pszFilename, IN LPCWSTR pszStyleName, OUT IThemeStyle ** ppThemeStyle)
  271. {
  272. HRESULT hr = E_INVALIDARG;
  273. if (ppThemeStyle)
  274. {
  275. *ppThemeStyle = NULL;
  276. hr = S_OK;
  277. // Find the display name
  278. for (int nIndex = 0; SUCCEEDED(hr); nIndex++)
  279. {
  280. THEMENAMEINFO themeInfo;
  281. hr = EnumThemeColors(pszFilename, NULL, nIndex, &themeInfo);
  282. LogStatus("EnumThemeColors(pszFilename=\"%ls\") returned %#08lx in CSkinStyle_CreateInstance.\r\n", pszFilename, hr);
  283. if (SUCCEEDED(hr))
  284. {
  285. // Did we find the correct color style?
  286. if (!StrCmpIW(pszStyleName, themeInfo.szName))
  287. {
  288. // Yes, now use it's display name to use the other creator function.
  289. hr = CSkinStyle_CreateInstance(pszFilename, pszStyleName, themeInfo.szDisplayName, ppThemeStyle);
  290. break;
  291. }
  292. }
  293. }
  294. }
  295. return hr;
  296. }