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.

2153 lines
65 KiB

  1. //---------------------------------------------------------------------------
  2. // Wrapper.cpp - wrappers for win32-style API (handle-based)
  3. //---------------------------------------------------------------------------
  4. #include "stdafx.h"
  5. #include "Render.h"
  6. #include "Utils.h"
  7. #include "Loader.h"
  8. #include "Wrapper.h"
  9. #include "SetHook.h"
  10. #include "Info.h"
  11. #include "Services.h"
  12. #include "appinfo.h"
  13. #include "tmreg.h"
  14. #include "tmutils.h"
  15. #include "themeldr.h"
  16. #include "borderfill.h"
  17. #include "imagefile.h"
  18. #include "textdraw.h"
  19. #include "renderlist.h"
  20. #include "filedump.h"
  21. #include "Signing.h"
  22. //---------------------------------------------------------------------------
  23. #include "paramchecks.h"
  24. //---------------------------------------------------------------------------
  25. #define RETURN_VALIDATE_RETVAL(hr) { if (FAILED(hr)) return MakeError32(hr); } // HRESULT functions
  26. //---------------------------------------------------------------------------
  27. #define MAX_THEMEAPI_STRINGPARAM MAX_PATH // Strings used by Themes APIs can't be bigger than this
  28. #define MAX_FILENAMEPARAM (MAX_PATH + 1) // + 1 for the NULL terminator
  29. //---------------------------------------------------------------------------
  30. THEMEAPI GetThemePropertyOrigin(HTHEME hTheme, int iPartId, int iStateId,
  31. int iPropId, OUT PROPERTYORIGIN *pOrigin)
  32. {
  33. APIHELPER(L"GetThemePropertyOrigin", hTheme);
  34. VALIDATE_WRITE_PTR(ApiHelper, pOrigin, sizeof(PROPERTYORIGIN));
  35. CRenderObj *pRender;
  36. VALIDATE_THEME_HANDLE(ApiHelper, hTheme, &pRender);
  37. return pRender->GetPropertyOrigin(iPartId, iStateId, iPropId, pOrigin);
  38. }
  39. //-----------------------------------------------------------------------
  40. THEMEAPI GetThemeColor(HTHEME hTheme, int iPartId, int iStateId,
  41. int iPropId, OUT COLORREF *pColor)
  42. {
  43. APIHELPER(L"GetThemeColor", hTheme);
  44. VALIDATE_WRITE_PTR(ApiHelper, pColor, sizeof(COLORREF));
  45. CRenderObj *pRender;
  46. VALIDATE_THEME_HANDLE(ApiHelper, hTheme, &pRender);
  47. return pRender->GetColor(iPartId, iStateId, iPropId, pColor);
  48. }
  49. //-----------------------------------------------------------------------
  50. THEMEAPI GetThemeBitmap(HTHEME hTheme, HDC hdc, int iPartId, int iStateId,
  51. const RECT *prc, OUT HBITMAP *phBitmap)
  52. {
  53. APIHELPER(L"GetThemeBitmap", hTheme);
  54. VALIDATE_WRITE_PTR(ApiHelper, phBitmap, sizeof(HBITMAP));
  55. CRenderObj *pRender;
  56. VALIDATE_THEME_HANDLE(ApiHelper, hTheme, &pRender);
  57. CDrawBase *pDrawObj;
  58. HRESULT hr = pRender->GetDrawObj(iPartId, iStateId, &pDrawObj);
  59. if (SUCCEEDED(hr))
  60. {
  61. if (pDrawObj->_eBgType == BT_IMAGEFILE)
  62. {
  63. CImageFile *pImageFile = (CImageFile *)pDrawObj;
  64. hr = pImageFile->GetBitmap(pRender, hdc, prc, phBitmap);
  65. }
  66. else // BorderFill
  67. {
  68. hr = E_FAIL;
  69. }
  70. }
  71. return hr;
  72. }
  73. //-----------------------------------------------------------------------
  74. THEMEAPI GetThemeMetric(HTHEME hTheme, OPTIONAL HDC hdc, int iPartId, int iStateId,
  75. int iPropId, OUT int *piVal)
  76. {
  77. APIHELPER(L"GetThemeMetric", hTheme);
  78. if (hdc)
  79. {
  80. VALIDATE_HDC(ApiHelper, hdc);
  81. }
  82. VALIDATE_WRITE_PTR(ApiHelper, piVal, sizeof(int));
  83. CRenderObj *pRender;
  84. VALIDATE_THEME_HANDLE(ApiHelper, hTheme, &pRender);
  85. return pRender->GetMetric(hdc, iPartId, iStateId, iPropId, piVal);
  86. }
  87. //-----------------------------------------------------------------------
  88. THEMEAPI GetThemeString(HTHEME hTheme, int iPartId, int iStateId,
  89. int iPropId, OUT LPWSTR pszBuff, int cchMaxBuffChars)
  90. {
  91. APIHELPER(L"GetThemeString", hTheme);
  92. VALIDATE_WRITE_PTR(ApiHelper, pszBuff, sizeof(WCHAR)*cchMaxBuffChars);
  93. CRenderObj *pRender;
  94. VALIDATE_THEME_HANDLE(ApiHelper, hTheme, &pRender);
  95. return pRender->GetString(iPartId, iStateId, iPropId, pszBuff, cchMaxBuffChars);
  96. }
  97. //-----------------------------------------------------------------------
  98. THEMEAPI GetThemeBool(HTHEME hTheme, int iPartId, int iStateId,
  99. int iPropId, OUT BOOL *pfVal)
  100. {
  101. APIHELPER(L"GetThemeBool", hTheme);
  102. VALIDATE_WRITE_PTR(ApiHelper, pfVal, sizeof(BOOL));
  103. CRenderObj *pRender;
  104. VALIDATE_THEME_HANDLE(ApiHelper, hTheme, &pRender);
  105. return pRender->GetBool(iPartId, iStateId, iPropId, pfVal);
  106. }
  107. //-----------------------------------------------------------------------
  108. THEMEAPI GetThemeInt(HTHEME hTheme, int iPartId, int iStateId,
  109. int iPropId, OUT int *piVal)
  110. {
  111. APIHELPER(L"GetThemeInt", hTheme);
  112. VALIDATE_WRITE_PTR(ApiHelper, piVal, sizeof(int));
  113. CRenderObj *pRender;
  114. VALIDATE_THEME_HANDLE(ApiHelper, hTheme, &pRender);
  115. return pRender->GetInt(iPartId, iStateId, iPropId, piVal);
  116. }
  117. //-----------------------------------------------------------------------
  118. THEMEAPI GetThemeEnumValue(HTHEME hTheme, int iPartId, int iStateId,
  119. int iPropId, OUT int *piVal)
  120. {
  121. APIHELPER(L"GetThemeEnumValue", hTheme);
  122. VALIDATE_WRITE_PTR(ApiHelper, piVal, sizeof(int));
  123. CRenderObj *pRender;
  124. VALIDATE_THEME_HANDLE(ApiHelper, hTheme, &pRender);
  125. return pRender->GetEnumValue(iPartId, iStateId, iPropId, piVal);
  126. }
  127. //-----------------------------------------------------------------------
  128. THEMEAPI GetThemePosition(HTHEME hTheme, int iPartId, int iStateId,
  129. int iPropId, OUT POINT *ppt)
  130. {
  131. APIHELPER(L"GetThemePosition", hTheme);
  132. VALIDATE_WRITE_PTR(ApiHelper, ppt, sizeof(POINT));
  133. CRenderObj *pRender;
  134. VALIDATE_THEME_HANDLE(ApiHelper, hTheme, &pRender);
  135. return pRender->GetPosition(iPartId, iStateId, iPropId, ppt);
  136. }
  137. //-----------------------------------------------------------------------
  138. THEMEAPI GetThemeFont(HTHEME hTheme, OPTIONAL HDC hdc, int iPartId, int iStateId,
  139. int iPropId, OUT LOGFONT *pFont)
  140. {
  141. APIHELPER(L"GetThemeFont", hTheme);
  142. VALIDATE_WRITE_PTR(ApiHelper, pFont, sizeof(LOGFONT));
  143. if (hdc)
  144. {
  145. VALIDATE_HDC(ApiHelper, hdc);
  146. }
  147. CRenderObj *pRender;
  148. VALIDATE_THEME_HANDLE(ApiHelper, hTheme, &pRender);
  149. return pRender->GetFont(hdc, iPartId, iStateId, iPropId, TRUE, pFont);
  150. }
  151. //-----------------------------------------------------------------------
  152. THEMEAPI GetThemeIntList(HTHEME hTheme, int iPartId,
  153. int iStateId, int iPropId, OUT INTLIST *pIntList)
  154. {
  155. APIHELPER(L"GetThemeIntList", hTheme);
  156. VALIDATE_WRITE_PTR(ApiHelper, pIntList, sizeof(INTLIST));
  157. CRenderObj *pRender;
  158. VALIDATE_THEME_HANDLE(ApiHelper, hTheme, &pRender);
  159. return pRender->GetIntList(iPartId, iStateId, iPropId, pIntList);
  160. }
  161. //-----------------------------------------------------------------------
  162. THEMEAPI GetThemeMargins(HTHEME hTheme, OPTIONAL HDC hdc, int iPartId,
  163. int iStateId, int iPropId, OPTIONAL RECT *prc, OUT MARGINS *pMargins)
  164. {
  165. APIHELPER(L"GetThemeMargins", hTheme);
  166. VALIDATE_WRITE_PTR(ApiHelper, pMargins, sizeof(MARGINS));
  167. if (hdc)
  168. {
  169. VALIDATE_HDC(ApiHelper, hdc);
  170. }
  171. if (prc)
  172. {
  173. VALIDATE_READ_PTR(ApiHelper, prc, sizeof(RECT));
  174. }
  175. CRenderObj *pRender;
  176. VALIDATE_THEME_HANDLE(ApiHelper, hTheme, &pRender);
  177. //---- look up unscaled value of margins ----
  178. HRESULT hr = pRender->GetMargins(hdc, iPartId, iStateId, iPropId, prc, pMargins);
  179. if (FAILED(hr))
  180. goto exit;
  181. //---- try to convert to scaled margins ----
  182. CDrawBase *pDrawObj;
  183. HRESULT hr2 = pRender->GetDrawObj(iPartId, iStateId, &pDrawObj);
  184. if (SUCCEEDED(hr2))
  185. {
  186. if (pDrawObj->_eBgType == BT_IMAGEFILE)
  187. {
  188. SIZE szDraw;
  189. TRUESTRETCHINFO tsInfo;
  190. CImageFile *pImageFile = (CImageFile *)pDrawObj;
  191. DIBINFO *pdi = pImageFile->SelectCorrectImageFile(pRender, hdc, prc, FALSE, NULL);
  192. pImageFile->GetDrawnImageSize(pdi, prc, &tsInfo, &szDraw);
  193. hr = pImageFile->ScaleMargins(pMargins, hdc, pRender, pdi, &szDraw);
  194. }
  195. }
  196. exit:
  197. return hr;
  198. }
  199. //-----------------------------------------------------------------------
  200. THEMEAPI GetThemeRect(HTHEME hTheme, int iPartId, int iStateId,
  201. int iPropId, OUT RECT *pRect)
  202. {
  203. APIHELPER(L"GetThemeRect", hTheme);
  204. VALIDATE_WRITE_PTR(ApiHelper, pRect, sizeof(RECT));
  205. CRenderObj *pRender;
  206. VALIDATE_THEME_HANDLE(ApiHelper, hTheme, &pRender);
  207. return pRender->GetRect(iPartId, iStateId, iPropId, pRect);
  208. }
  209. //-----------------------------------------------------------------------
  210. THEMEAPI GetThemeFilename(HTHEME hTheme, int iPartId, int iStateId,
  211. int iPropId, OUT LPWSTR pszBuff, int cchMaxBuffChars)
  212. {
  213. APIHELPER(L"GetThemeFilename", hTheme);
  214. VALIDATE_WRITE_PTR(ApiHelper, pszBuff, sizeof(WCHAR)*cchMaxBuffChars);
  215. CRenderObj *pRender;
  216. VALIDATE_THEME_HANDLE(ApiHelper, hTheme, &pRender);
  217. return pRender->GetFilename(iPartId, iStateId, iPropId, pszBuff, cchMaxBuffChars);
  218. }
  219. //-----------------------------------------------------------------------
  220. THEMEAPI DrawThemeBackgroundEx(HTHEME hTheme, HDC hdc,
  221. int iPartId, int iStateId, const RECT *pRect, OPTIONAL const DTBGOPTS *pOptions)
  222. {
  223. APIHELPER(L"DrawThemeBackground", hTheme);
  224. HRESULT hr = S_OK;
  225. CRenderObj *pRender;
  226. VALIDATE_THEME_HANDLE(ApiHelper, hTheme, &pRender);
  227. CDrawBase *pDrawObj;
  228. VALIDATE_HDC(ApiHelper, hdc);
  229. VALIDATE_READ_PTR(ApiHelper, pRect, sizeof(RECT));
  230. if (pOptions)
  231. {
  232. VALIDATE_READ_PTR(ApiHelper, pOptions, sizeof(*pOptions));
  233. if (pOptions->dwSize != sizeof(*pOptions))
  234. {
  235. hr = MakeError32(E_FAIL);
  236. return hr;
  237. }
  238. }
  239. hr = pRender->GetDrawObj(iPartId, iStateId, &pDrawObj);
  240. if (SUCCEEDED(hr))
  241. {
  242. if (pDrawObj->_eBgType == BT_BORDERFILL)
  243. {
  244. CBorderFill *pBorderFill = (CBorderFill *)pDrawObj;
  245. hr = pBorderFill->DrawBackground(pRender, hdc, pRect, pOptions);
  246. }
  247. else // imagefile
  248. {
  249. CImageFile *pImageFile = (CImageFile *)pDrawObj;
  250. hr = pImageFile->DrawBackground(pRender, hdc, iStateId, pRect, pOptions);
  251. }
  252. }
  253. return hr;
  254. }
  255. //-----------------------------------------------------------------------
  256. THEMEAPI DrawThemeBackground(HTHEME hTheme, HDC hdc, int iPartId,
  257. int iStateId, const RECT *pRect, OPTIONAL const RECT *pClipRect)
  258. {
  259. APIHELPER(L"DrawThemeBackground", hTheme);
  260. HRESULT hr = S_OK;
  261. CRenderObj *pRender;
  262. VALIDATE_THEME_HANDLE(ApiHelper, hTheme, &pRender);
  263. CDrawBase *pDrawObj;
  264. VALIDATE_HDC(ApiHelper, hdc);
  265. VALIDATE_READ_PTR(ApiHelper, pRect, sizeof(RECT));
  266. if (pClipRect)
  267. {
  268. VALIDATE_READ_PTR(ApiHelper, pClipRect, sizeof(RECT));
  269. RECT rcx;
  270. if (! IntersectRect(&rcx, pRect, pClipRect)) // nothing to paint
  271. goto exit;
  272. }
  273. hr = pRender->GetDrawObj(iPartId, iStateId, &pDrawObj);
  274. if (SUCCEEDED(hr))
  275. {
  276. DTBGOPTS Opts = {sizeof(Opts)};
  277. DTBGOPTS *pOpts = NULL;
  278. if (pClipRect)
  279. {
  280. pOpts = &Opts;
  281. Opts.dwFlags |= DTBG_CLIPRECT;
  282. Opts.rcClip = *pClipRect;
  283. }
  284. if (pDrawObj->_eBgType == BT_BORDERFILL ||
  285. pDrawObj->_eBgType == BT_NONE)
  286. {
  287. CBorderFill *pBorderFill = (CBorderFill *)pDrawObj;
  288. hr = pBorderFill->DrawBackground(pRender, hdc, pRect, pOpts);
  289. }
  290. else // imagefile
  291. {
  292. CImageFile *pImageFile = (CImageFile *)pDrawObj;
  293. hr = pImageFile->DrawBackground(pRender, hdc, iStateId, pRect, pOpts);
  294. }
  295. }
  296. exit:
  297. return hr;
  298. }
  299. //-----------------------------------------------------------------------
  300. THEMEAPI HitTestThemeBackground(
  301. HTHEME hTheme,
  302. OPTIONAL HDC hdc,
  303. int iPartId,
  304. int iStateId,
  305. DWORD dwOptions,
  306. const RECT *pRect,
  307. OPTIONAL HRGN hrgn,
  308. POINT ptTest,
  309. OUT WORD *pwHitTestCode)
  310. {
  311. APIHELPER(L"HitTestThemeBackground", hTheme);
  312. HRESULT hr;
  313. CRenderObj *pRender;
  314. VALIDATE_THEME_HANDLE(ApiHelper, hTheme, &pRender);
  315. CDrawBase *pDrawObj;
  316. VALIDATE_READ_PTR(ApiHelper, pRect, sizeof(RECT));
  317. VALIDATE_WRITE_PTR(ApiHelper, pwHitTestCode, sizeof(WORD));
  318. if (hdc)
  319. {
  320. VALIDATE_HDC(ApiHelper, hdc);
  321. }
  322. if( hrgn )
  323. {
  324. VALIDATE_HANDLE(ApiHelper, hrgn);
  325. }
  326. hr = pRender->GetDrawObj(iPartId, iStateId, &pDrawObj);
  327. if (SUCCEEDED(hr))
  328. {
  329. if (pDrawObj->_eBgType == BT_BORDERFILL)
  330. {
  331. CBorderFill *pBorderFill = (CBorderFill *)pDrawObj;
  332. hr = pBorderFill->HitTestBackground(pRender, hdc, dwOptions, pRect,
  333. hrgn, ptTest, pwHitTestCode);
  334. }
  335. else // imagefile
  336. {
  337. CImageFile *pImageFile = (CImageFile *)pDrawObj;
  338. hr = pImageFile->HitTestBackground(pRender, hdc, iStateId, dwOptions, pRect,
  339. hrgn, ptTest, pwHitTestCode);
  340. }
  341. }
  342. return hr;
  343. }
  344. //-----------------------------------------------------------------------
  345. THEMEAPI DrawThemeTextEx(HTHEME hTheme, HDC hdc, int iPartId,
  346. int iStateId, LPCWSTR pszText, int iCharCount, DWORD dwTextFlags,
  347. const RECT *pRect, OPTIONAL const DTTOPTS *pOptions)
  348. {
  349. APIHELPER(L"DrawThemeTextEx", hTheme);
  350. VALIDATE_HDC(ApiHelper, hdc);
  351. if (iCharCount == -1)
  352. {
  353. VALIDATE_INPUT_UNLIMITED_STRING(ApiHelper, pszText);
  354. }
  355. else
  356. {
  357. VALIDATE_READ_PTR(ApiHelper, pszText, sizeof(WCHAR)*iCharCount);
  358. }
  359. VALIDATE_READ_PTR(ApiHelper, pRect, sizeof(RECT));
  360. if (pOptions)
  361. {
  362. VALIDATE_READ_PTR(ApiHelper, pOptions, sizeof(*pOptions));
  363. if (pOptions->dwSize != sizeof(*pOptions))
  364. {
  365. return MakeError32(E_FAIL);
  366. }
  367. }
  368. CRenderObj *pRender;
  369. VALIDATE_THEME_HANDLE(ApiHelper, hTheme, &pRender);
  370. CTextDraw *pTextObj;
  371. HRESULT hr = pRender->GetTextObj(iPartId, iStateId, &pTextObj);
  372. if (SUCCEEDED(hr))
  373. {
  374. hr = pTextObj->DrawText(pRender, hdc, iPartId, iStateId, pszText, iCharCount,
  375. dwTextFlags, pRect, pOptions);
  376. }
  377. return hr;
  378. }
  379. //-----------------------------------------------------------------------
  380. THEMEAPI DrawThemeText(HTHEME hTheme, HDC hdc, int iPartId,
  381. int iStateId, LPCWSTR pszText, int iCharCount, DWORD dwTextFlags,
  382. DWORD dwTextFlags2, const RECT *pRect)
  383. {
  384. APIHELPER(L"DrawThemeText", hTheme);
  385. VALIDATE_HDC(ApiHelper, hdc);
  386. if (iCharCount == -1)
  387. {
  388. VALIDATE_INPUT_UNLIMITED_STRING(ApiHelper, pszText);
  389. }
  390. else
  391. {
  392. VALIDATE_READ_PTR(ApiHelper, pszText, sizeof(WCHAR)*iCharCount);
  393. }
  394. VALIDATE_READ_PTR(ApiHelper, pRect, sizeof(RECT));
  395. CRenderObj *pRender;
  396. VALIDATE_THEME_HANDLE(ApiHelper, hTheme, &pRender);
  397. CTextDraw *pTextObj;
  398. HRESULT hr = pRender->GetTextObj(iPartId, iStateId, &pTextObj);
  399. if (SUCCEEDED(hr))
  400. {
  401. hr = pTextObj->DrawText(pRender, hdc, iPartId, iStateId, pszText, iCharCount,
  402. dwTextFlags, pRect, NULL);
  403. }
  404. return hr;
  405. }
  406. //---------------------------------------------------------------------------
  407. THEMEAPI CloseThemeData(HTHEME hTheme)
  408. {
  409. //---- don't take a refcount on hTheme since we are about to close it ----
  410. APIHELPER(L"CloseThemeData", NULL);
  411. return g_pRenderList->CloseRenderObject(hTheme);
  412. }
  413. //-----------------------------------------------------------------------
  414. THEMEAPI GetThemeBackgroundContentRect(HTHEME hTheme, OPTIONAL HDC hdc,
  415. int iPartId, int iStateId, const RECT *pBoundingRect,
  416. OUT RECT *pContentRect)
  417. {
  418. APIHELPER(L"GetThemeBackgroundContentRect", hTheme);
  419. HRESULT hr;
  420. CRenderObj *pRender;
  421. VALIDATE_THEME_HANDLE(ApiHelper, hTheme, &pRender);
  422. CDrawBase *pDrawObj;
  423. VALIDATE_READ_PTR(ApiHelper, pBoundingRect, sizeof(RECT));
  424. VALIDATE_WRITE_PTR(ApiHelper, pContentRect, sizeof(RECT));
  425. if (hdc)
  426. {
  427. VALIDATE_HDC(ApiHelper, hdc);
  428. }
  429. hr = pRender->GetDrawObj(iPartId, iStateId, &pDrawObj);
  430. if (SUCCEEDED(hr))
  431. {
  432. if (pDrawObj->_eBgType == BT_BORDERFILL)
  433. {
  434. CBorderFill *pBorderFill = (CBorderFill *)pDrawObj;
  435. hr = pBorderFill->GetBackgroundContentRect(pRender, hdc,
  436. pBoundingRect, pContentRect);
  437. }
  438. else // imagefile
  439. {
  440. CImageFile *pImageFile = (CImageFile *)pDrawObj;
  441. hr = pImageFile->GetBackgroundContentRect(pRender, hdc,
  442. pBoundingRect, pContentRect);
  443. }
  444. }
  445. return hr;
  446. }
  447. //-----------------------------------------------------------------------
  448. THEMEAPI GetThemeBackgroundRegion(HTHEME hTheme, OPTIONAL HDC hdc,
  449. int iPartId, int iStateId, const RECT *pRect, OUT HRGN *pRegion)
  450. {
  451. APIHELPER(L"GetThemeBackgroundRegion", hTheme);
  452. VALIDATE_READ_PTR(ApiHelper, pRect, sizeof(RECT));
  453. VALIDATE_WRITE_PTR(ApiHelper, pRegion, sizeof(HRGN));
  454. if (hdc)
  455. {
  456. VALIDATE_HDC(ApiHelper, hdc);
  457. }
  458. if (IsRectEmpty(pRect))
  459. {
  460. *pRegion = NULL;
  461. return S_FALSE;
  462. }
  463. HRESULT hr;
  464. CRenderObj *pRender;
  465. VALIDATE_THEME_HANDLE(ApiHelper, hTheme, &pRender);
  466. CDrawBase *pDrawObj;
  467. hr = pRender->GetDrawObj(iPartId, iStateId, &pDrawObj);
  468. if (SUCCEEDED(hr))
  469. {
  470. if (pDrawObj->_eBgType == BT_BORDERFILL)
  471. {
  472. CBorderFill *pBorderFill = (CBorderFill *)pDrawObj;
  473. hr = pBorderFill->GetBackgroundRegion(pRender, hdc, pRect, pRegion);
  474. }
  475. else // imagefile
  476. {
  477. CImageFile *pImageFile = (CImageFile *)pDrawObj;
  478. hr = pImageFile->GetBackgroundRegion(pRender, hdc, iStateId, pRect, pRegion);
  479. }
  480. }
  481. return hr;
  482. }
  483. //-----------------------------------------------------------------------
  484. THEMEAPI GetThemeTextExtent(HTHEME hTheme, HDC hdc,
  485. int iPartId, int iStateId, LPCWSTR pszText, int iCharCount,
  486. DWORD dwTextFlags, OPTIONAL const RECT *pBoundingRect,
  487. OUT RECT *pExtentRect)
  488. {
  489. APIHELPER(L"GetThemeTextExtent", hTheme);
  490. VALIDATE_HDC(ApiHelper, hdc);
  491. if (iCharCount == -1)
  492. {
  493. VALIDATE_INPUT_UNLIMITED_STRING(ApiHelper, pszText);
  494. } else
  495. {
  496. VALIDATE_READ_PTR(ApiHelper, pszText, sizeof(WCHAR)*iCharCount);
  497. }
  498. if (pBoundingRect)
  499. {
  500. VALIDATE_READ_PTR(ApiHelper, pBoundingRect, sizeof(RECT));
  501. }
  502. VALIDATE_WRITE_PTR(ApiHelper, pExtentRect, sizeof(RECT));
  503. CRenderObj *pRender;
  504. VALIDATE_THEME_HANDLE(ApiHelper, hTheme, &pRender);
  505. CTextDraw *pTextObj;
  506. HRESULT hr = pRender->GetTextObj(iPartId, iStateId, &pTextObj);
  507. if (SUCCEEDED(hr))
  508. {
  509. hr = pTextObj->GetTextExtent(pRender, hdc, iPartId, iStateId, pszText, iCharCount,
  510. dwTextFlags, pBoundingRect, pExtentRect);
  511. }
  512. return hr;
  513. }
  514. //-----------------------------------------------------------------------
  515. THEMEAPI GetThemeTextMetrics(HTHEME hTheme, HDC hdc,
  516. int iPartId, int iStateId, OUT TEXTMETRIC* ptm)
  517. {
  518. APIHELPER(L"GetThemeTextMetrics", hTheme);
  519. VALIDATE_HDC(ApiHelper, hdc);
  520. VALIDATE_WRITE_PTR(ApiHelper, ptm, sizeof(TEXTMETRIC));
  521. CRenderObj *pRender;
  522. VALIDATE_THEME_HANDLE(ApiHelper, hTheme, &pRender);
  523. CTextDraw *pTextObj;
  524. HRESULT hr = pRender->GetTextObj(iPartId, iStateId, &pTextObj);
  525. if (SUCCEEDED(hr))
  526. {
  527. hr = pTextObj->GetTextMetrics(pRender, hdc, iPartId, iStateId, ptm);
  528. }
  529. return hr;
  530. }
  531. //-----------------------------------------------------------------------
  532. THEMEAPI GetThemeBackgroundExtent(HTHEME hTheme, OPTIONAL HDC hdc,
  533. int iPartId, int iStateId, const RECT *pContentRect, OUT RECT *pExtentRect)
  534. {
  535. APIHELPER(L"GetThemeBackgroundExtent", hTheme);
  536. VALIDATE_READ_PTR(ApiHelper, pContentRect, sizeof(RECT));
  537. VALIDATE_WRITE_PTR(ApiHelper, pExtentRect, sizeof(RECT));
  538. if (hdc)
  539. {
  540. VALIDATE_HDC(ApiHelper, hdc);
  541. }
  542. CRenderObj *pRender;
  543. VALIDATE_THEME_HANDLE(ApiHelper, hTheme, &pRender);
  544. CDrawBase *pDrawObj;
  545. HRESULT hr = pRender->GetDrawObj(iPartId, iStateId, &pDrawObj);
  546. if (SUCCEEDED(hr))
  547. {
  548. if (pDrawObj->_eBgType == BT_BORDERFILL)
  549. {
  550. CBorderFill *pBorderFill = (CBorderFill *)pDrawObj;
  551. hr = pBorderFill->GetBackgroundExtent(pRender, hdc, pContentRect,
  552. pExtentRect);
  553. }
  554. else // imagefile
  555. {
  556. CImageFile *pImageFile = (CImageFile *)pDrawObj;
  557. hr = pImageFile->GetBackgroundExtent(pRender, hdc,
  558. pContentRect, pExtentRect);
  559. }
  560. }
  561. return hr;
  562. }
  563. //-----------------------------------------------------------------------
  564. THEMEAPI GetThemePartSize(HTHEME hTheme, HDC hdc,
  565. int iPartId, int iStateId, OPTIONAL RECT *prc, THEMESIZE eSize, OUT SIZE *psz)
  566. {
  567. APIHELPER(L"GetThemePartSize", hTheme);
  568. HRESULT hr;
  569. CRenderObj *pRender;
  570. VALIDATE_THEME_HANDLE(ApiHelper, hTheme, &pRender);
  571. CDrawBase *pDrawObj;
  572. if (hdc)
  573. {
  574. VALIDATE_HDC(ApiHelper, hdc);
  575. }
  576. if (prc)
  577. {
  578. VALIDATE_READ_PTR(ApiHelper, prc, sizeof(RECT));
  579. }
  580. VALIDATE_WRITE_PTR(ApiHelper, psz, sizeof(SIZE));
  581. hr = pRender->GetDrawObj(iPartId, iStateId, &pDrawObj);
  582. if (SUCCEEDED(hr))
  583. {
  584. if (pDrawObj->_eBgType == BT_BORDERFILL)
  585. {
  586. CBorderFill *pBorderFill = (CBorderFill *)pDrawObj;
  587. hr = pBorderFill->GetPartSize(hdc, eSize, psz);
  588. }
  589. else // imagefile
  590. {
  591. CImageFile *pImageFile = (CImageFile *)pDrawObj;
  592. hr = pImageFile->GetPartSize(pRender, hdc, prc, eSize, psz);
  593. }
  594. }
  595. return hr;
  596. }
  597. //-----------------------------------------------------------------------
  598. THEMEAPI SetWindowTheme(HWND hwnd, LPCWSTR pszSubAppName,
  599. LPCWSTR pszSubIdList)
  600. {
  601. APIHELPER(L"SetWindowTheme", NULL);
  602. VALIDATE_HWND(ApiHelper, hwnd);
  603. if (pszSubAppName)
  604. {
  605. VALIDATE_INPUT_STRING(ApiHelper, pszSubAppName, 255); // Atom
  606. }
  607. if (pszSubIdList)
  608. {
  609. VALIDATE_INPUT_STRING(ApiHelper, pszSubIdList, 255); // Atom
  610. }
  611. ApplyStringProp(hwnd, pszSubAppName, GetThemeAtom(THEMEATOM_SUBAPPNAME));
  612. ApplyStringProp(hwnd, pszSubIdList, GetThemeAtom(THEMEATOM_SUBIDLIST));
  613. //---- tell target window to get a new theme handle ----
  614. SendMessage(hwnd, WM_THEMECHANGED, static_cast<WPARAM>(-1), WTC_THEMEACTIVE | WTC_CUSTOMTHEME);
  615. return S_OK;
  616. }
  617. //---------------------------------------------------------------------------
  618. THEMEAPI GetCurrentThemeName(
  619. OUT LPWSTR pszNameBuff, int cchMaxNameChars,
  620. OUT OPTIONAL LPWSTR pszColorBuff, int cchMaxColorChars,
  621. OUT OPTIONAL LPWSTR pszSizeBuff, int cchMaxSizeChars)
  622. {
  623. APIHELPER(L"GetCurrentThemeName", NULL);
  624. VALIDATE_WRITE_PTR(ApiHelper, pszNameBuff, sizeof(WCHAR)*cchMaxNameChars);
  625. if (pszColorBuff)
  626. {
  627. VALIDATE_WRITE_PTR(ApiHelper, pszColorBuff, sizeof(WCHAR)*cchMaxColorChars);
  628. }
  629. if (pszSizeBuff)
  630. {
  631. VALIDATE_WRITE_PTR(ApiHelper, pszSizeBuff, sizeof(WCHAR)*cchMaxSizeChars);
  632. }
  633. HRESULT hr;
  634. CUxThemeFile *pThemeFile = NULL;
  635. //---- get a shared CUxThemeFile object ----
  636. hr = g_pAppInfo->OpenWindowThemeFile(NULL, &pThemeFile);
  637. if (FAILED(hr))
  638. goto exit;
  639. //---- get info about current theme ----
  640. hr = GetThemeNameId(pThemeFile, pszNameBuff, cchMaxNameChars, pszColorBuff, cchMaxColorChars,
  641. pszSizeBuff, cchMaxSizeChars, NULL, NULL);
  642. exit:
  643. if (pThemeFile)
  644. g_pAppInfo->CloseThemeFile(pThemeFile);
  645. return hr;
  646. }
  647. //---------------------------------------------------------------------------
  648. THEMEAPI OpenThemeFile(LPCWSTR pszThemeName, OPTIONAL LPCWSTR pszColorParam,
  649. OPTIONAL LPCWSTR pszSizeParam, OUT HTHEMEFILE *phThemeFile, BOOL fGlobalTheme)
  650. {
  651. HRESULT hr = S_OK;
  652. APIHELPER(L"OpenThemeFile", NULL);
  653. VALIDATE_INPUT_STRING(ApiHelper, pszThemeName, MAX_FILENAMEPARAM);
  654. if (pszColorParam)
  655. {
  656. VALIDATE_INPUT_STRING(ApiHelper, pszColorParam, MAX_THEMEAPI_STRINGPARAM);
  657. }
  658. if (pszSizeParam)
  659. {
  660. VALIDATE_INPUT_STRING(ApiHelper, pszSizeParam, MAX_THEMEAPI_STRINGPARAM);
  661. }
  662. VALIDATE_WRITE_PTR(ApiHelper, phThemeFile, sizeof(HTHEMEFILE));
  663. // TCB (trusted computing base) privilege is required to create a
  664. // global theme section.
  665. if( fGlobalTheme == FALSE || TokenHasPrivilege( NULL, SE_TCB_PRIVILEGE ) )
  666. {
  667. HANDLE handle;
  668. hr = CThemeServices::LoadTheme(&handle, pszThemeName, pszColorParam, pszSizeParam,
  669. fGlobalTheme);
  670. if (FAILED(hr))
  671. goto exit;
  672. //---- convert from Memory Mapped File handle to a CUxThemeFile ptr ----
  673. CUxThemeFile *pThemeFile;
  674. //---- set new file ----
  675. hr = g_pAppInfo->OpenThemeFile(handle, &pThemeFile);
  676. if (SUCCEEDED(hr))
  677. {
  678. *phThemeFile = (HTHEMEFILE *)pThemeFile;
  679. }
  680. else
  681. {
  682. // We don't have a CUxThemeFile, have to clear ourselves
  683. ClearTheme(handle);
  684. }
  685. }
  686. else
  687. {
  688. hr = E_ACCESSDENIED;
  689. }
  690. exit:
  691. return hr;
  692. }
  693. //---------------------------------------------------------------------------
  694. THEMEAPI ApplyTheme(OPTIONAL HTHEMEFILE hThemeFile, DWORD dwApplyFlags,
  695. OPTIONAL HWND hwndTarget)
  696. {
  697. APIHELPER(L"ApplyTheme", NULL);
  698. HRESULT hr = S_OK;
  699. if (hThemeFile)
  700. {
  701. VALIDATE_READ_PTR(ApiHelper, hThemeFile, sizeof(HTHEMEFILE));
  702. }
  703. if (hwndTarget)
  704. {
  705. VALIDATE_HWND(ApiHelper, hwndTarget);
  706. }
  707. CUxThemeFile *pThemeFile = (CUxThemeFile *)hThemeFile;
  708. //----- set preview info, if targeted at a window ----
  709. if (hwndTarget)
  710. g_pAppInfo->SetPreviewThemeFile(pThemeFile->Handle(), hwndTarget);
  711. hr = CThemeServices::ApplyTheme(pThemeFile, dwApplyFlags, hwndTarget);
  712. return hr;
  713. }
  714. //---------------------------------------------------------------------------
  715. THEMEAPI CloseThemeFile(HTHEMEFILE hThemeFile)
  716. {
  717. APIHELPER(L"CloseThemeFile", NULL);
  718. if (hThemeFile)
  719. {
  720. VALIDATE_READ_PTR(ApiHelper, hThemeFile, sizeof(HTHEMEFILE));
  721. }
  722. CUxThemeFile *pThemeFile = (CUxThemeFile *)hThemeFile;
  723. if (pThemeFile)
  724. {
  725. VALIDATE_READ_PTR(ApiHelper, pThemeFile, sizeof(CUxThemeFile));
  726. g_pAppInfo->CloseThemeFile(pThemeFile);
  727. }
  728. return S_OK;
  729. }
  730. //---------------------------------------------------------------------------
  731. THEMEAPI SetSystemVisualStyle(
  732. LPCWSTR pszVisualStyleFile,
  733. OPTIONAL LPCWSTR pszColorParam,
  734. OPTIONAL LPCWSTR pszSizeParam,
  735. DWORD dwFlags )
  736. {
  737. APIHELPER(L"SetSystemVisualStyle", NULL);
  738. HRESULT hr = E_INVALIDARG;
  739. if( pszVisualStyleFile )
  740. {
  741. VALIDATE_INPUT_STRING(ApiHelper, pszVisualStyleFile, MAX_FILENAMEPARAM);
  742. if (pszColorParam)
  743. {
  744. VALIDATE_INPUT_STRING(ApiHelper, pszColorParam, MAX_THEMEAPI_STRINGPARAM);
  745. }
  746. if (pszSizeParam)
  747. {
  748. VALIDATE_INPUT_STRING(ApiHelper, pszSizeParam, MAX_THEMEAPI_STRINGPARAM);
  749. }
  750. HANDLE hSection;
  751. hr = CThemeServices::ProcessLoadGlobalTheme(pszVisualStyleFile, pszColorParam, pszSizeParam, &hSection);
  752. if( FAILED(hr) )
  753. {
  754. ASSERT(hSection == NULL); // the service is up to no good.
  755. }
  756. if( SUCCEEDED(hr) )
  757. {
  758. //---- convert from Memory Mapped File handle to a CUxThemeFile ptr ----
  759. CUxThemeFile *pThemeFile;
  760. //---- set new file ----
  761. hr = g_pAppInfo->OpenThemeFile(hSection, &pThemeFile);
  762. if (SUCCEEDED(hr))
  763. {
  764. hr = CThemeServices::ApplyTheme(pThemeFile, dwFlags, NULL);
  765. g_pAppInfo->CloseThemeFile(pThemeFile);
  766. }
  767. else
  768. {
  769. // We don't have a CUxThemeFile, have to clear ourselves
  770. ClearTheme(hSection);
  771. }
  772. }
  773. }
  774. else
  775. {
  776. hr = CThemeServices::ApplyTheme(NULL, dwFlags, NULL);
  777. }
  778. return hr;
  779. }
  780. //---------------------------------------------------------------------------
  781. THEMEAPI EnumThemes(LPCWSTR pszThemeRoot, THEMEENUMPROC lpEnumFunc, LPARAM lParam)
  782. {
  783. APIHELPER(L"EnumThemes", NULL);
  784. VALIDATE_INPUT_STRING(ApiHelper, pszThemeRoot, MAX_FILENAMEPARAM);
  785. VALIDATE_CALLBACK(ApiHelper, lpEnumFunc);
  786. HRESULT hr;
  787. HANDLE hFile = NULL;
  788. if (! lpEnumFunc)
  789. hr = MakeError32(E_INVALIDARG);
  790. else
  791. {
  792. WCHAR szSearchPath[MAX_PATH+1];
  793. WCHAR szFileName[MAX_PATH+1];
  794. WCHAR szDisplayName[MAX_PATH+1];
  795. WCHAR szToolTip[MAX_PATH+1];
  796. StringCchPrintfW(szSearchPath, ARRAYSIZE(szSearchPath), L"%s\\*.*", pszThemeRoot);
  797. //---- first find all child directories containing a *.msstyles files ----
  798. BOOL bFile = TRUE;
  799. WIN32_FIND_DATA wfd;
  800. hr = S_FALSE; // assume interrupted until we complete
  801. bool bRemote = GetSystemMetrics(SM_REMOTESESSION) ? true : false;
  802. DWORD dwCurMinDepth = 0;
  803. if (bRemote)
  804. {
  805. dwCurMinDepth = MinimumDisplayColorDepth();
  806. }
  807. for( hFile = FindFirstFile( szSearchPath, &wfd ); hFile != INVALID_HANDLE_VALUE && bFile;
  808. bFile = FindNextFile( hFile, &wfd ) )
  809. {
  810. if(! ( wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY ))
  811. continue;
  812. if ((lstrcmp(wfd.cFileName, TEXT("."))==0) || (lstrcmp(wfd.cFileName, TEXT(".."))==0))
  813. continue;
  814. StringCchPrintfW(szFileName, ARRAYSIZE(szFileName), L"%s\\%s\\%s.msstyles", pszThemeRoot, wfd.cFileName, wfd.cFileName);
  815. //---- ensure its signed by ms ----
  816. hr = CThemeServices::CheckThemeSignature(szFileName);
  817. if (FAILED(hr))
  818. continue;
  819. //---- ensure its loadable & has a supported version ----
  820. HINSTANCE hInst;
  821. hr = LoadThemeLibrary(szFileName, &hInst);
  822. if (FAILED(hr))
  823. continue;
  824. int iBaseNum = RES_BASENUM_DOCPROPERTIES - TMT_FIRST_RCSTRING_NAME;
  825. //---- get DisplayName ----
  826. if (! LoadString(hInst, iBaseNum + TMT_DISPLAYNAME, szDisplayName, ARRAYSIZE(szDisplayName)))
  827. *szDisplayName = 0;
  828. //---- get ToolTip ----
  829. if (! LoadString(hInst, iBaseNum + TMT_TOOLTIP, szToolTip, ARRAYSIZE(szToolTip)))
  830. *szToolTip = 0;
  831. //---- see if one class file supports this color depth
  832. bool bMatch = true;
  833. // Check on remote sessions only (the console can be in 8-bit mode)
  834. if (bRemote)
  835. {
  836. bMatch = CheckMinColorDepth(hInst, dwCurMinDepth);
  837. }
  838. //---- free the lib ----
  839. FreeLibrary(hInst);
  840. if (bMatch)
  841. {
  842. //---- its a good one - call the callback ----
  843. BOOL fContinue = (*lpEnumFunc)(TCB_THEMENAME, szFileName, szDisplayName,
  844. szToolTip, 0, lParam); // call the callback
  845. if (! fContinue)
  846. goto exit;
  847. }
  848. }
  849. hr = S_OK; // completed
  850. }
  851. exit:
  852. if (hFile)
  853. FindClose(hFile);
  854. return hr;
  855. }
  856. //---------------------------------------------------------------------------
  857. THEMEAPI EnumThemeSizes(LPCWSTR pszThemeName,
  858. OPTIONAL LPCWSTR pszColorScheme, DWORD dwSizeIndex, OUT THEMENAMEINFO *ptn)
  859. {
  860. APIHELPER(L"EnumThemeSizes", NULL);
  861. VALIDATE_INPUT_STRING(ApiHelper, pszThemeName, MAX_FILENAMEPARAM);
  862. if (pszColorScheme)
  863. {
  864. VALIDATE_INPUT_STRING(ApiHelper, pszColorScheme, MAX_THEMEAPI_STRINGPARAM);
  865. }
  866. VALIDATE_WRITE_PTR(ApiHelper, ptn, sizeof(THEMENAMEINFO));
  867. HINSTANCE hInst = NULL;
  868. HRESULT hr = LoadThemeLibrary(pszThemeName, &hInst);
  869. if (SUCCEEDED(hr))
  870. {
  871. hr = _EnumThemeSizes(hInst, pszThemeName, pszColorScheme, dwSizeIndex, ptn, (BOOL) GetSystemMetrics(SM_REMOTESESSION));
  872. FreeLibrary(hInst);
  873. }
  874. return hr;
  875. }
  876. //---------------------------------------------------------------------------
  877. THEMEAPI EnumThemeColors(LPCWSTR pszThemeName,
  878. OPTIONAL LPCWSTR pszSizeName, DWORD dwColorIndex, OUT THEMENAMEINFO *ptn)
  879. {
  880. APIHELPER(L"EnumThemeColors", NULL);
  881. VALIDATE_INPUT_STRING(ApiHelper, pszThemeName, MAX_FILENAMEPARAM);
  882. if (pszSizeName)
  883. {
  884. VALIDATE_INPUT_STRING(ApiHelper, pszSizeName, MAX_THEMEAPI_STRINGPARAM);
  885. }
  886. VALIDATE_WRITE_PTR(ApiHelper, ptn, sizeof(THEMENAMEINFO));
  887. HINSTANCE hInst = NULL;
  888. HRESULT hr = LoadThemeLibrary(pszThemeName, &hInst);
  889. if (SUCCEEDED(hr))
  890. {
  891. hr = _EnumThemeColors(hInst, pszThemeName, pszSizeName, dwColorIndex, ptn, (BOOL) GetSystemMetrics(SM_REMOTESESSION));
  892. FreeLibrary(hInst);
  893. }
  894. return hr;
  895. }
  896. //---------------------------------------------------------------------------
  897. THEMEAPI DrawThemeEdge(HTHEME hTheme, HDC hdc, int iPartId, int iStateId,
  898. const RECT *pDestRect, UINT uEdge, UINT uFlags, OUT RECT *pContentRect)
  899. {
  900. APIHELPER(L"DrawThemeEdge", hTheme);
  901. VALIDATE_HDC(ApiHelper, hdc);
  902. VALIDATE_READ_PTR(ApiHelper, pDestRect, sizeof(RECT));
  903. if (pContentRect)
  904. {
  905. VALIDATE_WRITE_PTR(ApiHelper, pContentRect, sizeof(RECT));
  906. }
  907. CRenderObj *pRender;
  908. VALIDATE_THEME_HANDLE(ApiHelper, hTheme, &pRender);
  909. CTextDraw *pTextObj;
  910. HRESULT hr = pRender->GetTextObj(iPartId, iStateId, &pTextObj);
  911. if (SUCCEEDED(hr))
  912. {
  913. hr = pTextObj->DrawEdge(pRender, hdc, iPartId, iStateId, pDestRect, uEdge, uFlags, pContentRect);
  914. }
  915. return hr;
  916. }
  917. //---------------------------------------------------------------------------
  918. THEMEAPI DrawThemeIcon(HTHEME hTheme, HDC hdc, int iPartId,
  919. int iStateId, const RECT *pRect, HIMAGELIST himl, int iImageIndex)
  920. {
  921. APIHELPER(L"DrawThemeIcon", hTheme);
  922. VALIDATE_HDC(ApiHelper, hdc);
  923. VALIDATE_READ_PTR(ApiHelper, pRect, sizeof(RECT));
  924. VALIDATE_HANDLE(ApiHelper, himl);
  925. IMAGELISTDRAWPARAMS params = {sizeof(params)};
  926. HRESULT hr = EnsureUxCtrlLoaded();
  927. if (FAILED(hr))
  928. goto exit;
  929. CRenderObj *pRender;
  930. VALIDATE_THEME_HANDLE(ApiHelper, hTheme, &pRender);
  931. //---- build up the IMAGELISTDRAWPARAMS struct ----
  932. params.hdcDst = hdc;
  933. params.himl = himl;
  934. params.i = iImageIndex;
  935. params.x = pRect->left;
  936. params.y = pRect->top;
  937. params.cx = WIDTH(*pRect);
  938. params.cy = HEIGHT(*pRect);
  939. params.rgbBk = CLR_NONE;
  940. params.rgbFg = CLR_NONE;
  941. params.fStyle = ILD_TRANSPARENT;
  942. //---- get IconEffect ----
  943. ICONEFFECT effect;
  944. if (FAILED(pRender->GetEnumValue(iPartId, iStateId, TMT_ICONEFFECT, (int *)&effect)))
  945. effect = ICE_NONE;
  946. if (effect == ICE_GLOW)
  947. {
  948. params.fState = ILS_GLOW;
  949. //---- get GlowColor ----
  950. COLORREF glow;
  951. if (FAILED(pRender->GetColor(iPartId, iStateId, TMT_GLOWCOLOR, &glow)))
  952. glow = RGB(0, 0, 255);
  953. params.crEffect = glow;
  954. }
  955. else if (effect == ICE_SHADOW)
  956. {
  957. params.fState = ILS_SHADOW;
  958. //---- get ShadowColor ----
  959. COLORREF shadow;
  960. if (FAILED(pRender->GetColor(iPartId, iStateId, TMT_SHADOWCOLOR, &shadow)))
  961. shadow = RGB(0, 0, 0);
  962. params.crEffect = shadow;
  963. }
  964. else if (effect == ICE_PULSE)
  965. {
  966. params.fState = ILS_SATURATE;
  967. //---- get Saturation ----
  968. int saturate;
  969. if (FAILED(pRender->GetInt(iPartId, iStateId, TMT_SATURATION, &saturate)))
  970. saturate = 128; // 50% of 255
  971. params.Frame = saturate;
  972. }
  973. else if (effect == ICE_ALPHA)
  974. {
  975. params.fState = ILS_ALPHA;
  976. //---- get AlphaLevel ----
  977. int alpha;
  978. if (FAILED(pRender->GetInt(iPartId, iStateId, TMT_ALPHALEVEL, &alpha)))
  979. alpha = 128; // 50% of 255
  980. params.Frame = alpha;
  981. }
  982. if (! (*ImageList_DrawProc)(&params))
  983. hr = MakeError32(E_FAIL); // no other error info available
  984. exit:
  985. return hr;
  986. }
  987. //---------------------------------------------------------------------------
  988. THEMEAPI GetThemeDefaults(LPCWSTR pszThemeName,
  989. OUT OPTIONAL LPWSTR pszDefaultColor, int cchMaxColorChars,
  990. OUT OPTIONAL LPWSTR pszDefaultSize, int cchMaxSizeChars)
  991. {
  992. APIHELPER(L"GetThemeDefaults", NULL);
  993. VALIDATE_INPUT_STRING(ApiHelper, pszThemeName, MAX_FILENAMEPARAM);
  994. if (pszDefaultColor)
  995. {
  996. VALIDATE_WRITE_PTR(ApiHelper, pszDefaultColor, sizeof(WCHAR) * cchMaxColorChars);
  997. }
  998. if (pszDefaultSize)
  999. {
  1000. VALIDATE_WRITE_PTR(ApiHelper, pszDefaultSize, sizeof(WCHAR) * cchMaxSizeChars);
  1001. }
  1002. HRESULT hr;
  1003. HINSTANCE hInst = NULL;
  1004. hr = LoadThemeLibrary(pszThemeName, &hInst);
  1005. if (FAILED(hr))
  1006. goto exit;
  1007. if (pszDefaultColor)
  1008. {
  1009. hr = GetResString(hInst, L"COLORNAMES", 0, pszDefaultColor, cchMaxColorChars);
  1010. if (FAILED(hr))
  1011. goto exit;
  1012. }
  1013. if (pszDefaultSize)
  1014. {
  1015. hr = GetResString(hInst, L"SIZENAMES", 0, pszDefaultSize, cchMaxSizeChars);
  1016. if (FAILED(hr))
  1017. goto exit;
  1018. }
  1019. exit:
  1020. FreeLibrary(hInst);
  1021. return hr;
  1022. }
  1023. //---------------------------------------------------------------------------
  1024. THEMEAPI GetThemeDocumentationProperty(LPCWSTR pszThemeName,
  1025. LPCWSTR pszPropertyName, OUT LPWSTR pszValueBuff, int cchMaxValChars)
  1026. {
  1027. APIHELPER(L"GetThemeDocumentationProperty", NULL);
  1028. VALIDATE_INPUT_STRING(ApiHelper, pszThemeName, MAX_FILENAMEPARAM);
  1029. VALIDATE_INPUT_STRING(ApiHelper, pszPropertyName, MAX_THEMEAPI_STRINGPARAM);
  1030. VALIDATE_WRITE_PTR(ApiHelper, pszValueBuff, sizeof(WCHAR)*cchMaxValChars);
  1031. HRESULT hr;
  1032. CThemeParser *pParser = NULL;
  1033. HINSTANCE hInst = NULL;
  1034. hr = LoadThemeLibrary(pszThemeName, &hInst);
  1035. if (FAILED(hr))
  1036. goto exit;
  1037. pParser = new CThemeParser;
  1038. if (! pParser)
  1039. {
  1040. hr = MakeError32(E_OUTOFMEMORY);
  1041. goto exit;
  1042. }
  1043. //---- is this a recognized (localized) property name? ----
  1044. int iPropNum;
  1045. hr = pParser->GetPropertyNum(pszPropertyName, &iPropNum);
  1046. if (SUCCEEDED(hr))
  1047. {
  1048. //---- try to read from string table of recognized [documentation] properties ----
  1049. if (LoadString(hInst, iPropNum+RES_BASENUM_DOCPROPERTIES, pszValueBuff, cchMaxValChars))
  1050. goto exit;
  1051. }
  1052. //---- load the themes.ini text into memory ----
  1053. LPWSTR pThemesIni;
  1054. hr = AllocateTextResource(hInst, CONTAINER_RESNAME, &pThemesIni);
  1055. if (FAILED(hr))
  1056. goto exit;
  1057. hr = pParser->ParseThemeBuffer(pThemesIni, NULL, NULL, NULL, NULL, NULL, NULL,
  1058. PTF_QUERY_DOCPROPERTY | PTF_CONTAINER_PARSE, pszPropertyName, pszValueBuff, cchMaxValChars);
  1059. exit:
  1060. if (pParser)
  1061. delete pParser;
  1062. FreeLibrary(hInst);
  1063. return hr;
  1064. }
  1065. //---------------------------------------------------------------------------
  1066. THEMEAPI GetThemeSysFont96(HTHEME hTheme, int iFontId, OUT LOGFONT *plf)
  1067. {
  1068. APIHELPER(L"GetThemeSysFont96", hTheme);
  1069. CRenderObj *pRender = NULL;
  1070. HRESULT hr = S_OK;
  1071. VALIDATE_THEME_HANDLE(ApiHelper, hTheme, &pRender);
  1072. VALIDATE_WRITE_PTR(ApiHelper, plf, sizeof(LOGFONT));
  1073. //---- check font index limits ----
  1074. if ((iFontId < TMT_FIRSTFONT) || (iFontId > TMT_LASTFONT))
  1075. {
  1076. hr = MakeError32(E_INVALIDARG);
  1077. goto exit;
  1078. }
  1079. //---- return unscaled value ----
  1080. *plf = pRender->_ptm->lfFonts[iFontId - TMT_FIRSTFONT];
  1081. exit:
  1082. return hr;
  1083. }
  1084. //---------------------------------------------------------------------------
  1085. THEMEAPI GetThemeSysFont(OPTIONAL HTHEME hTheme, int iFontId, OUT LOGFONT *plf)
  1086. {
  1087. APIHELPER(L"GetThemeSysFont", hTheme);
  1088. CRenderObj *pRender = NULL;
  1089. if (hTheme)
  1090. {
  1091. VALIDATE_THEME_HANDLE(ApiHelper, hTheme, &pRender);
  1092. }
  1093. VALIDATE_WRITE_PTR(ApiHelper, plf, sizeof(LOGFONT));
  1094. //---- check font index limits ----
  1095. HRESULT hr = S_OK;
  1096. if ((iFontId < TMT_FIRSTFONT) || (iFontId > TMT_LASTFONT))
  1097. {
  1098. hr = MakeError32(E_INVALIDARG);
  1099. goto exit;
  1100. }
  1101. if (pRender) // get theme value
  1102. {
  1103. *plf = pRender->_ptm->lfFonts[iFontId - TMT_FIRSTFONT];
  1104. //---- convert to current screen dpi ----
  1105. ScaleFontForScreenDpi(plf);
  1106. }
  1107. else // get system value
  1108. {
  1109. if (iFontId == TMT_ICONTITLEFONT)
  1110. {
  1111. BOOL fGet = ClassicSystemParametersInfo(SPI_GETICONTITLELOGFONT, sizeof(LOGFONT), plf, 0);
  1112. if (! fGet)
  1113. {
  1114. Log(LOG_ERROR, L"Error returned from ClassicSystemParametersInfo(SPI_GETICONTITLELOGFONT)");
  1115. hr = MakeErrorLast();
  1116. goto exit;
  1117. }
  1118. }
  1119. else
  1120. {
  1121. NONCLIENTMETRICS ncm = {sizeof(ncm)};
  1122. BOOL fGet = ClassicSystemParametersInfo(SPI_GETNONCLIENTMETRICS, sizeof(ncm), &ncm, 0);
  1123. if (! fGet)
  1124. {
  1125. Log(LOG_ERROR, L"Error returned from ClassicSystemParametersInfo(SPI_GETNONCLIENTMETRICS)");
  1126. hr = MakeErrorLast();
  1127. goto exit;
  1128. }
  1129. switch (iFontId)
  1130. {
  1131. case TMT_CAPTIONFONT:
  1132. *plf = ncm.lfCaptionFont;
  1133. break;
  1134. case TMT_SMALLCAPTIONFONT:
  1135. *plf = ncm.lfSmCaptionFont;
  1136. break;
  1137. case TMT_MENUFONT:
  1138. *plf = ncm.lfMenuFont;
  1139. break;
  1140. case TMT_STATUSFONT:
  1141. *plf = ncm.lfStatusFont;
  1142. break;
  1143. case TMT_MSGBOXFONT:
  1144. *plf = ncm.lfMessageFont;
  1145. break;
  1146. }
  1147. }
  1148. }
  1149. exit:
  1150. return hr;
  1151. }
  1152. //---------------------------------------------------------------------------
  1153. THEMEAPI GetThemeSysString(HTHEME hTheme, int iStringId,
  1154. OUT LPWSTR pszStringBuff, int cchStringBuff)
  1155. {
  1156. APIHELPER(L"GetThemeSysString", hTheme);
  1157. CRenderObj *pRender = NULL;
  1158. VALIDATE_THEME_HANDLE(ApiHelper, hTheme, &pRender);
  1159. VALIDATE_WRITE_PTR(ApiHelper, pszStringBuff, sizeof(WCHAR)*cchStringBuff);
  1160. HRESULT hr;
  1161. //---- check string index limits ----
  1162. if ((iStringId < TMT_FIRSTSTRING) || (iStringId > TMT_LASTSTRING))
  1163. {
  1164. hr = MakeError32(E_INVALIDARG);
  1165. goto exit;
  1166. }
  1167. LPCWSTR p;
  1168. p = ThemeString(pRender->_pThemeFile, pRender->_ptm->iStringOffsets[iStringId - TMT_FIRSTSTRING]);
  1169. hr = SafeStringCchCopyW(pszStringBuff, cchStringBuff, p );
  1170. if (FAILED(hr))
  1171. goto exit;
  1172. hr = S_OK;
  1173. exit:
  1174. return hr;
  1175. }
  1176. //---------------------------------------------------------------------------
  1177. THEMEAPI GetThemeSysInt(HTHEME hTheme, int iIntId, int *piValue)
  1178. {
  1179. APIHELPER(L"GetThemeSysInt", hTheme);
  1180. CRenderObj *pRender = NULL;
  1181. VALIDATE_THEME_HANDLE(ApiHelper, hTheme, &pRender);
  1182. VALIDATE_WRITE_PTR(ApiHelper, piValue, sizeof(int));
  1183. HRESULT hr;
  1184. //---- check int index limits ----
  1185. if ((iIntId < TMT_FIRSTINT) || (iIntId > TMT_LASTINT))
  1186. {
  1187. hr = MakeError32(E_INVALIDARG);
  1188. goto exit;
  1189. }
  1190. *piValue = pRender->_ptm->iInts[iIntId - TMT_FIRSTINT];
  1191. hr = S_OK;
  1192. exit:
  1193. return hr;
  1194. }
  1195. //---------------------------------------------------------------------------
  1196. #define THEME_FORCE_VERSION 103 // increment this when you want to force
  1197. // new theme settings
  1198. //---------------------------------------------------------------------------
  1199. THEMEAPI RegisterDefaultTheme(LPCWSTR pszFileName, BOOL fOverride)
  1200. {
  1201. APIHELPER(L"RegisterDefaultTheme", NULL);
  1202. RESOURCE HKEY tmkey = NULL;
  1203. HRESULT hr = S_OK;
  1204. //---- Note: at install time, its not possible to access each ----
  1205. //---- user's registry info (may be roaming on server) so ----
  1206. //---- we put default theme under HKEY_LM. Then, during ----
  1207. //---- themeldr init for a user, we propagate the info ----
  1208. //---- to the HKEY_CU root. ----
  1209. //---- open LM + THEMEMGR key (create if needed) ----
  1210. int code32 = RegCreateKeyEx(HKEY_LOCAL_MACHINE, THEMEMGR_REGKEY, NULL, NULL,
  1211. REG_OPTION_NON_VOLATILE, KEY_WRITE | KEY_READ, NULL, &tmkey, NULL);
  1212. if (code32 != ERROR_SUCCESS)
  1213. {
  1214. hr = MakeErrorLast();
  1215. goto exit;
  1216. }
  1217. //---- read the value of "THEMEPROP_LMVERSION" ----
  1218. int iValue;
  1219. hr = RegistryIntRead(tmkey, THEMEPROP_LMVERSION, &iValue);
  1220. if (FAILED(hr))
  1221. iValue = 0;
  1222. //---- write the "THEMEPROP_LOADEDBEFORE" = "0" ----
  1223. hr = RegistryIntWrite(tmkey, THEMEPROP_LOADEDBEFORE, 0);
  1224. if (FAILED(hr))
  1225. goto exit;
  1226. if (iValue == THEME_FORCE_VERSION) // matches - don't update anything
  1227. goto exit;
  1228. //---- write the NEW value of "THEMEPROP_LMVERSION" ----
  1229. hr = RegistryIntWrite(tmkey, THEMEPROP_LMVERSION, THEME_FORCE_VERSION);
  1230. if (FAILED(hr))
  1231. goto exit;
  1232. //---- write the value of "THEMEPROP_LMOVERRIDE" ----
  1233. iValue = (fOverride != 0);
  1234. hr = RegistryIntWrite(tmkey, THEMEPROP_LMOVERRIDE, iValue);
  1235. if (FAILED(hr))
  1236. goto exit;
  1237. //---- write the "THEMEPROP_THEMEACTIVE" = "1" ----
  1238. hr = RegistryIntWrite(tmkey, THEMEPROP_THEMEACTIVE, 1);
  1239. if (FAILED(hr))
  1240. goto exit;
  1241. //---- write "DllName=xxxx" string/value ----
  1242. hr = RegistryStrWriteExpand(tmkey, THEMEPROP_DLLNAME, pszFileName);
  1243. if (FAILED(hr))
  1244. goto exit;
  1245. exit:
  1246. if (tmkey)
  1247. RegCloseKey(tmkey);
  1248. return hr;
  1249. }
  1250. //---------------------------------------------------------------------------
  1251. THEMEAPI DumpLoadedThemeToTextFile(HTHEMEFILE hThemeFile, LPCWSTR pszTextFile,
  1252. BOOL fPacked, BOOL fFullInfo)
  1253. {
  1254. APIHELPER(L"DumpLoadedThemeToTextFile", NULL);
  1255. VALIDATE_READ_PTR(ApiHelper, hThemeFile, sizeof(HTHEMEFILE));
  1256. VALIDATE_INPUT_STRING(ApiHelper, pszTextFile, MAX_FILENAMEPARAM);
  1257. CUxThemeFile *pThemeFile = (CUxThemeFile *)hThemeFile;
  1258. return DumpThemeFile(pszTextFile, pThemeFile, fPacked, fFullInfo);
  1259. }
  1260. //---------------------------------------------------------------------------
  1261. THEMEAPI GetThemeParseErrorInfo(OUT PARSE_ERROR_INFO *pInfo)
  1262. {
  1263. APIHELPER(L"GetThemeParseErrorInfo", NULL);
  1264. VALIDATE_WRITE_PTR(ApiHelper, pInfo, sizeof(*pInfo));
  1265. return _GetThemeParseErrorInfo(pInfo);
  1266. }
  1267. //---------------------------------------------------------------------------
  1268. THEMEAPI ParseThemeIniFile(LPCWSTR pszFileName,
  1269. DWORD dwParseFlags, OPTIONAL THEMEENUMPROC pfnCallBack, OPTIONAL LPARAM lparam)
  1270. {
  1271. APIHELPER(L"ParseThemeIniFile", NULL);
  1272. VALIDATE_INPUT_STRING(ApiHelper, pszFileName, MAX_FILENAMEPARAM);
  1273. if (pfnCallBack)
  1274. {
  1275. VALIDATE_CALLBACK(ApiHelper, pfnCallBack);
  1276. }
  1277. return _ParseThemeIniFile(pszFileName, dwParseFlags, pfnCallBack, lparam);
  1278. }
  1279. //---------------------------------------------------------------------------
  1280. THEMEAPI OpenThemeFileFromData(HTHEME hTheme, HTHEMEFILE *phThemeFile)
  1281. {
  1282. APIHELPER(L"OpenThemeFileFromData", hTheme);
  1283. CRenderObj *pRender = NULL;
  1284. VALIDATE_THEME_HANDLE(ApiHelper, hTheme, &pRender);
  1285. VALIDATE_WRITE_PTR(ApiHelper, phThemeFile, sizeof(HTHEMEFILE));
  1286. return _OpenThemeFileFromData(pRender, phThemeFile);
  1287. }
  1288. //---------------------------------------------------------------------------
  1289. THEMEAPI DrawThemeParentBackground(HWND hwnd, HDC hdc, OPTIONAL RECT* prc)
  1290. {
  1291. APIHELPER(L"DrawThemeParentBackground", NULL);
  1292. //---- param validation ----
  1293. VALIDATE_HWND(ApiHelper, hwnd);
  1294. VALIDATE_HDC(ApiHelper, hdc);
  1295. if (prc)
  1296. {
  1297. VALIDATE_READ_PTR(ApiHelper, prc, sizeof(RECT));
  1298. }
  1299. // INVESTIGATE: There is a possible sync problem. If we have a window
  1300. // parented to a window in another thread, then the property stuff may get out of
  1301. // sync between the threads. If this is an issue, then we may have to leave the
  1302. // property on the window instead of removing it when we're done.
  1303. RECT rc;
  1304. POINT pt;
  1305. CSaveClipRegion csrPrevClip;
  1306. HRESULT hr = S_OK;
  1307. HWND hwndParent = GetParent(hwnd);
  1308. ATOM aIsPrinting = GetThemeAtom(THEMEATOM_PRINTING);
  1309. if (prc)
  1310. {
  1311. rc = *prc;
  1312. hr = csrPrevClip.Save(hdc); // save current clipping region
  1313. if (FAILED(hr))
  1314. goto exit;
  1315. IntersectClipRect(hdc, prc->left, prc->top, prc->right, prc->bottom);
  1316. }
  1317. //---- get RECT of "hwnd" client area in parent coordinates ----
  1318. GetClientRect(hwnd, &rc);
  1319. MapWindowPoints(hwnd, hwndParent, (POINT*)&rc, 2);
  1320. // Set a property saying "We want to see if this window handles WM_PRINTCLIENT. i.e. if it passes
  1321. // it to DefWindowProc it didn't handle it.
  1322. SetProp(hwndParent, (PCTSTR)aIsPrinting, (HANDLE)PRINTING_ASKING);
  1323. // Setup the viewport so that it is aligned with the parents.
  1324. GetViewportOrgEx(hdc, &pt);
  1325. SetViewportOrgEx(hdc, pt.x - rc.left, pt.y - rc.top, &pt);
  1326. SendMessage(hwndParent, WM_ERASEBKGND, (WPARAM)hdc, (LPARAM)0);
  1327. SendMessage(hwndParent, WM_PRINTCLIENT, (WPARAM)hdc, (LPARAM)PRF_CLIENT);
  1328. SetViewportOrgEx(hdc, pt.x, pt.y, NULL);
  1329. // See if the window handled the print. If this is set to PRINTING_WINDOWDIDNOTHANDLE,
  1330. // it means they did not handle it (i.e. it was passed to DefWindowProc)
  1331. if (PtrToUlong(GetProp(hwndParent, (PCTSTR)aIsPrinting)) == PRINTING_WINDOWDIDNOTHANDLE)
  1332. {
  1333. hr = S_FALSE;
  1334. }
  1335. exit:
  1336. RemoveProp(hwndParent, (PCTSTR)aIsPrinting);
  1337. csrPrevClip.Restore(hdc); // restore current clipping region
  1338. return hr;
  1339. }
  1340. //---------------------------------------------------------------------------
  1341. THEMEAPI EnableThemeDialogTexture(HWND hwnd, DWORD dwFlagsIn)
  1342. {
  1343. APIHELPER(L"EnableThemeDialogTexture", NULL);
  1344. HRESULT hr = S_OK;
  1345. if (TESTFLAG(dwFlagsIn, ETDT_DISABLE))
  1346. {
  1347. RemoveProp(hwnd, MAKEINTATOM(GetThemeAtom(THEMEATOM_DLGTEXTURING)));
  1348. }
  1349. else
  1350. {
  1351. ULONG ulFlagsOut = HandleToUlong(GetProp(hwnd, MAKEINTATOM(GetThemeAtom(THEMEATOM_DLGTEXTURING))));
  1352. // validate and add requested flags:
  1353. ulFlagsOut |= (dwFlagsIn & (ETDT_ENABLE|ETDT_USETABTEXTURE));
  1354. if (!SetProp(hwnd, MAKEINTATOM(GetThemeAtom(THEMEATOM_DLGTEXTURING)), ULongToHandle(ulFlagsOut)))
  1355. {
  1356. DWORD dwErr = GetLastError();
  1357. hr = (ERROR_SUCCESS == dwErr) ? E_FAIL : HRESULT_FROM_WIN32(dwErr);
  1358. }
  1359. }
  1360. return hr;
  1361. }
  1362. //---------------------------------------------------------------------------
  1363. THEMEAPI RefreshThemeForTS()
  1364. {
  1365. APIHELPER(L"RefreshThemeForTS", NULL);
  1366. return CThemeServices::InitUserTheme();
  1367. }
  1368. //---------------------------------------------------------------------------
  1369. //---- put all non-HRESULT returning functions down at the bottom here ----
  1370. //---------------------------------------------------------------------------
  1371. #undef RETURN_VALIDATE_RETVAL
  1372. #define RETURN_VALIDATE_RETVAL(hr) { if (FAILED(hr)) { SET_LAST_ERROR(hr); return NULL; } } // HANDLE functions
  1373. //---------------------------------------------------------------------------
  1374. THEMEAPI_(HTHEME) CreateThemeDataFromObjects(OPTIONAL CDrawBase *pDrawObj,
  1375. OPTIONAL CTextDraw *pTextObj, DWORD dwOtdFlags)
  1376. {
  1377. APIHELPER(L"CreateThemeDataFromObjects", NULL);
  1378. HTHEME hTheme = NULL;
  1379. BOOL fGotOne = FALSE;
  1380. HRESULT hr = S_OK;
  1381. if (pDrawObj)
  1382. {
  1383. VALIDATE_READ_PTR(ApiHelper, pDrawObj, sizeof(pDrawObj->_eBgType));
  1384. if (pDrawObj->_eBgType == BT_BORDERFILL)
  1385. {
  1386. VALIDATE_READ_PTR(ApiHelper, pDrawObj, sizeof(CBorderFill));
  1387. }
  1388. else if (pDrawObj->_eBgType == BT_IMAGEFILE)
  1389. {
  1390. VALIDATE_READ_PTR(ApiHelper, pDrawObj, sizeof(CImageFile));
  1391. }
  1392. else
  1393. goto exit; // unknown object type
  1394. fGotOne = TRUE;
  1395. }
  1396. if (pTextObj)
  1397. {
  1398. VALIDATE_READ_PTR(ApiHelper, pTextObj, sizeof(CTextDraw));
  1399. fGotOne = TRUE;
  1400. }
  1401. if (! fGotOne)
  1402. {
  1403. hr = MakeError32(E_POINTER);
  1404. goto exit;
  1405. }
  1406. hr = g_pRenderList->OpenRenderObject(NULL, 0, 0, pDrawObj, pTextObj, NULL, dwOtdFlags,
  1407. &hTheme);
  1408. if (FAILED(hr))
  1409. {
  1410. hTheme = NULL;
  1411. }
  1412. exit:
  1413. SET_LAST_ERROR(hr);
  1414. return hTheme;
  1415. }
  1416. //---------------------------------------------------------------------------
  1417. THEMEAPI_(HTHEME) OpenThemeData(OPTIONAL HWND hwnd, LPCWSTR pszClassIdList)
  1418. {
  1419. APIHELPER(L"OpenThemeData", NULL);
  1420. if (hwnd)
  1421. VALIDATE_HWND(ApiHelper, hwnd);
  1422. VALIDATE_INPUT_STRING(ApiHelper, pszClassIdList, MAX_THEMEAPI_STRINGPARAM);
  1423. return _OpenThemeData(hwnd, pszClassIdList, 0);
  1424. }
  1425. //---------------------------------------------------------------------------
  1426. THEMEAPI_(HTHEME) OpenThemeDataEx(OPTIONAL HWND hwnd, LPCWSTR pszClassIdList, DWORD dwFlags)
  1427. {
  1428. APIHELPER(L"OpenThemeDataEx", NULL);
  1429. if (hwnd)
  1430. VALIDATE_HWND(ApiHelper, hwnd);
  1431. VALIDATE_INPUT_STRING(ApiHelper, pszClassIdList, MAX_THEMEAPI_STRINGPARAM);
  1432. return _OpenThemeData(hwnd, pszClassIdList, dwFlags);
  1433. }
  1434. //-----------------------------------------------------------------------
  1435. THEMEAPI_(HTHEME) OpenNcThemeData(HWND hwnd, LPCWSTR pszClassIdList)
  1436. {
  1437. APIHELPER(L"OpenNcThemeData", NULL);
  1438. if (hwnd)
  1439. VALIDATE_HWND(ApiHelper, hwnd);
  1440. VALIDATE_INPUT_STRING(ApiHelper, pszClassIdList, MAX_THEMEAPI_STRINGPARAM);
  1441. return _OpenThemeData(hwnd, pszClassIdList, OTD_NONCLIENT);
  1442. }
  1443. //---------------------------------------------------------------------------
  1444. THEMEAPI_(HTHEME) OpenThemeDataFromFile(HTHEMEFILE hLoadedThemeFile,
  1445. OPTIONAL HWND hwnd, OPTIONAL LPCWSTR pszClassList, BOOL fClient)
  1446. {
  1447. APIHELPER(L"OpenThemeDataFromFile", NULL);
  1448. VALIDATE_READ_PTR(ApiHelper, hLoadedThemeFile, sizeof(HTHEMEFILE));
  1449. if (hwnd)
  1450. VALIDATE_HWND(ApiHelper, hwnd);
  1451. if (pszClassList)
  1452. {
  1453. VALIDATE_INPUT_STRING(ApiHelper, pszClassList, MAX_THEMEAPI_STRINGPARAM);
  1454. }
  1455. else
  1456. {
  1457. pszClassList = L"globals";
  1458. }
  1459. //---- caller holds a REFCOUNT on hLoadedThemeFile so we don't need to adjust it ----
  1460. //---- for the call to _OpenThemeDataFromFile. If it succeeds, CRenderObj will ----
  1461. //---- add its own REFCOUNT. If it fails, the REFCOUNT will be the orig REFCOUNT ----
  1462. DWORD dwFlags = 0;
  1463. if (! fClient)
  1464. {
  1465. dwFlags |= OTD_NONCLIENT;
  1466. }
  1467. return _OpenThemeDataFromFile(hLoadedThemeFile, hwnd, pszClassList, dwFlags);
  1468. }
  1469. //---------------------------------------------------------------------------
  1470. THEMEAPI EnableTheming(BOOL fEnable)
  1471. {
  1472. APIHELPER(L"EnableTheming", NULL);
  1473. return CThemeServices::AdjustTheme(fEnable);
  1474. }
  1475. //---------------------------------------------------------------------------
  1476. THEMEAPI_(HBRUSH) GetThemeSysColorBrush(OPTIONAL HTHEME hTheme, int iSysColorId)
  1477. {
  1478. APIHELPER(L"GetThemeSysColorBrush", hTheme);
  1479. HBRUSH hbr;
  1480. CRenderObj *pRender = NULL;
  1481. if (hTheme)
  1482. {
  1483. VALIDATE_THEME_HANDLE(ApiHelper, hTheme, &pRender);
  1484. }
  1485. //---- keep orig & make our own version of ColorId ----
  1486. int iThemeColorId = iSysColorId + TMT_FIRSTCOLOR;
  1487. //---- check color index limits ----
  1488. if ((iThemeColorId < TMT_FIRSTCOLOR) || (iThemeColorId > TMT_LASTCOLOR))
  1489. iThemeColorId = TMT_FIRSTCOLOR;
  1490. //---- make index 0-relative ----
  1491. iThemeColorId -= TMT_FIRSTCOLOR;
  1492. if (! pRender)
  1493. {
  1494. hbr = GetSysColorBrush(iSysColorId);
  1495. }
  1496. else
  1497. {
  1498. COLORREF cr = pRender->_ptm->crColors[iThemeColorId];
  1499. hbr = CreateSolidBrush(cr);
  1500. }
  1501. return hbr;
  1502. }
  1503. //---------------------------------------------------------------------------
  1504. THEMEAPI_(HTHEME) GetWindowTheme(HWND hwnd)
  1505. {
  1506. APIHELPER(L"GetWindowTheme", NULL);
  1507. VALIDATE_HWND(ApiHelper, hwnd);
  1508. return (HTHEME)GetProp(hwnd, MAKEINTATOM(GetThemeAtom(THEMEATOM_HTHEME)));
  1509. }
  1510. //---------------------------------------------------------------------------
  1511. #undef RETURN_VALIDATE_RETVAL
  1512. #define RETURN_VALIDATE_RETVAL { if (FAILED(hr)) { SET_LAST_ERROR(hr); return FALSE; } } // BOOL functions
  1513. //---------------------------------------------------------------------------
  1514. THEMEAPI_(BOOL) IsThemeActive()
  1515. {
  1516. APIHELPER(L"IsThemeActive", NULL);
  1517. SetLastError(0);
  1518. Log(LOG_TMLOAD, L"IsThemeActive(): start...");
  1519. BOOL fThemeActive = g_pAppInfo->IsSystemThemeActive();
  1520. Log(LOG_TMLOAD, L"IsThemeActive(): fThemeActive=%d", fThemeActive);
  1521. return fThemeActive;
  1522. }
  1523. //---------------------------------------------------------------------------
  1524. THEMEAPI_(BOOL) IsThemePartDefined(HTHEME hTheme, int iPartId, int iStateId)
  1525. {
  1526. APIHELPER(L"IsThemePartDefined", hTheme);
  1527. BOOL fDefined;
  1528. CRenderObj *pRender;
  1529. VALIDATE_THEME_HANDLE(ApiHelper, hTheme, &pRender);
  1530. SetLastError(0);
  1531. fDefined = pRender->IsPartDefined(iPartId, iStateId);
  1532. return fDefined;
  1533. }
  1534. //---------------------------------------------------------------------------
  1535. THEMEAPI_(BOOL) IsThemeBackgroundPartiallyTransparent(HTHEME hTheme, int iPartId, int iStateId)
  1536. {
  1537. APIHELPER(L"IsThemeBackgroundPartiallyTransparent", hTheme);
  1538. BOOL fTrans = FALSE;
  1539. HRESULT hr = S_OK;
  1540. CRenderObj *pRender;
  1541. VALIDATE_THEME_HANDLE(ApiHelper, hTheme, &pRender);
  1542. CDrawBase *pDrawObj;
  1543. hr = pRender->GetDrawObj(iPartId, iStateId, &pDrawObj);
  1544. if (SUCCEEDED(hr))
  1545. {
  1546. if (pDrawObj->_eBgType == BT_BORDERFILL)
  1547. {
  1548. CBorderFill *pBorderFill = (CBorderFill *)pDrawObj;
  1549. fTrans = pBorderFill->IsBackgroundPartiallyTransparent();
  1550. }
  1551. else // imagefile
  1552. {
  1553. CImageFile *pImageFile = (CImageFile *)pDrawObj;
  1554. fTrans = pImageFile->IsBackgroundPartiallyTransparent(iStateId);
  1555. }
  1556. }
  1557. SET_LAST_ERROR(hr);
  1558. return fTrans;
  1559. }
  1560. //---------------------------------------------------------------------------
  1561. THEMEAPI_(BOOL) IsAppThemed()
  1562. {
  1563. APIHELPER(L"IsAppThemed", NULL);
  1564. SetLastError(0);
  1565. return g_pAppInfo->AppIsThemed();
  1566. }
  1567. //---------------------------------------------------------------------------
  1568. THEMEAPI_(BOOL) IsThemeDialogTextureEnabled(HWND hwnd)
  1569. {
  1570. APIHELPER(L"IsThemeDialogTextureEnabled", NULL);
  1571. SetLastError(0);
  1572. INT_PTR iDialogTexture = (INT_PTR)GetProp(hwnd, MAKEINTATOM(GetThemeAtom(THEMEATOM_DLGTEXTURING)));
  1573. return iDialogTexture != 0; // If it's 1 or 2 then it's textured
  1574. }
  1575. //---------------------------------------------------------------------------
  1576. THEMEAPI_(BOOL) GetThemeSysBool(OPTIONAL HTHEME hTheme, int iBoolId)
  1577. {
  1578. APIHELPER(L"GetThemeSysBool", hTheme);
  1579. BOOL fValue;
  1580. CRenderObj *pRender = NULL;
  1581. if (hTheme)
  1582. {
  1583. VALIDATE_THEME_HANDLE(ApiHelper, hTheme, &pRender);
  1584. }
  1585. SetLastError(0);
  1586. //---- check bool index limits ----
  1587. if ((iBoolId < TMT_FIRSTBOOL) || (iBoolId > TMT_LASTBOOL))
  1588. {
  1589. fValue = FALSE;
  1590. goto exit;
  1591. }
  1592. if (! pRender)
  1593. {
  1594. int iSpIndex;
  1595. switch (iBoolId)
  1596. {
  1597. case TMT_FLATMENUS:
  1598. iSpIndex = SPI_GETFLATMENU;
  1599. break;
  1600. default:
  1601. Log(LOG_PARAMS, L"Unsupported system BOOL");
  1602. fValue = FALSE; // failed
  1603. goto exit;
  1604. }
  1605. BOOL fGet = ClassicSystemParametersInfo(iSpIndex, 0, &fValue, 0);
  1606. if (! fGet)
  1607. {
  1608. Log(LOG_ERROR, L"Error returned from ClassicSystemParametersInfo() getting a BOOL");
  1609. fValue = FALSE;
  1610. }
  1611. goto exit;
  1612. }
  1613. fValue = pRender->_ptm->fBools[iBoolId - TMT_FIRSTBOOL];
  1614. exit:
  1615. return fValue;
  1616. }
  1617. //---------------------------------------------------------------------------
  1618. #undef RETURN_VALIDATE_RETVAL
  1619. #define RETURN_VALIDATE_RETVAL { if (FAILED(hr)) { SET_LAST_ERROR(hr); return 0; } } // value functions
  1620. //---------------------------------------------------------------------------
  1621. THEMEAPI_(DWORD) QueryThemeServices()
  1622. {
  1623. APIHELPER(L"QueryThemeServices", NULL);
  1624. DWORD dwBits;
  1625. HRESULT hr = CThemeServices::GetStatusFlags(&dwBits);
  1626. if (FAILED(hr))
  1627. dwBits = 0;
  1628. SET_LAST_ERROR(hr);
  1629. return dwBits;
  1630. }
  1631. //---------------------------------------------------------------------------
  1632. THEMEAPI_(COLORREF) GetThemeSysColor(OPTIONAL HTHEME hTheme, int iSysColorId)
  1633. {
  1634. APIHELPER(L"GetThemeSysColor", hTheme);
  1635. COLORREF crValue;
  1636. CRenderObj *pRender = NULL;
  1637. if (hTheme)
  1638. {
  1639. VALIDATE_THEME_HANDLE(ApiHelper, hTheme, &pRender);
  1640. }
  1641. SetLastError(0);
  1642. //---- keep orig & make our own version of ColorId ----
  1643. int iThemeColorId = iSysColorId + TMT_FIRSTCOLOR;
  1644. if ((iThemeColorId < TMT_FIRSTCOLOR) || (iThemeColorId > TMT_LASTCOLOR))
  1645. iThemeColorId = TMT_FIRSTCOLOR;
  1646. //---- make index 0-relative ----
  1647. iThemeColorId -= TMT_FIRSTCOLOR;
  1648. if (! pRender)
  1649. {
  1650. crValue = GetSysColor(iSysColorId);
  1651. }
  1652. else
  1653. {
  1654. crValue = pRender->_ptm->crColors[iThemeColorId];
  1655. }
  1656. return crValue;
  1657. }
  1658. //---------------------------------------------------------------------------
  1659. THEMEAPI_(int) GetThemeSysSize96(HTHEME hTheme, int iSizeId)
  1660. {
  1661. APIHELPER(L"GetThemeSysSize96", hTheme);
  1662. SetLastError(0);
  1663. CRenderObj *pRender = NULL;
  1664. int iThemeSizeNum;
  1665. int iValue = 0;
  1666. VALIDATE_THEME_HANDLE(ApiHelper, hTheme, &pRender);
  1667. HRESULT hr = GetThemeSizeId(iSizeId, &iThemeSizeNum);
  1668. if (SUCCEEDED(hr))
  1669. {
  1670. //---- unscaled value ----
  1671. iValue = pRender->_ptm->iSizes[iThemeSizeNum - TMT_FIRSTSIZE];
  1672. }
  1673. else
  1674. {
  1675. SET_LAST_ERROR(MakeError32(E_INVALIDARG));
  1676. }
  1677. return iValue;
  1678. }
  1679. //---------------------------------------------------------------------------
  1680. THEMEAPI_(int) GetThemeSysSize(OPTIONAL HTHEME hTheme, int iSysSizeNum)
  1681. {
  1682. APIHELPER(L"GetThemeSysSize", hTheme);
  1683. SetLastError(0);
  1684. CRenderObj *pRender = NULL;
  1685. int iThemeSizeNum;
  1686. int iValue = 0;
  1687. if (hTheme)
  1688. {
  1689. VALIDATE_THEME_HANDLE(ApiHelper, hTheme, &pRender);
  1690. }
  1691. HRESULT hr = S_OK;
  1692. if (pRender)
  1693. {
  1694. hr = GetThemeSizeId(iSysSizeNum, &iThemeSizeNum);
  1695. if (SUCCEEDED(hr))
  1696. {
  1697. iValue = pRender->_ptm->iSizes[iThemeSizeNum - TMT_FIRSTSIZE];
  1698. //---- scale from 96 dpi to current screen dpi ----
  1699. iValue = ScaleSizeForScreenDpi(iValue);
  1700. }
  1701. else
  1702. {
  1703. SET_LAST_ERROR(hr);
  1704. }
  1705. }
  1706. else
  1707. {
  1708. iValue = ClassicGetSystemMetrics(iSysSizeNum);
  1709. }
  1710. return iValue;
  1711. }
  1712. //---------------------------------------------------------------------------
  1713. THEMEAPI_(DWORD) GetThemeAppProperties()
  1714. {
  1715. APIHELPER(L"GetThemeAppProperties", NULL);
  1716. SetLastError(0);
  1717. return g_pAppInfo->GetAppFlags();
  1718. }
  1719. //---------------------------------------------------------------------------
  1720. #undef RETURN_VALIDATE_RETVAL
  1721. #define RETURN_VALIDATE_RETVAL { if (FAILED(hr)) { SET_LAST_ERROR(hr); return; } } // null functions
  1722. //---------------------------------------------------------------------------
  1723. THEMEAPI_(void) SetThemeAppProperties(DWORD dwFlags)
  1724. {
  1725. APIHELPER(L"SetThemeAppProperties", NULL);
  1726. SetLastError(0);
  1727. g_pAppInfo->SetAppFlags(dwFlags);
  1728. }
  1729. //---------------------------------------------------------------------------
  1730. // --------------------------------------------------------------------------
  1731. // ::CheckThemeSignature
  1732. //
  1733. // Returns: HRESULT
  1734. //
  1735. // Purpose: Pass thru function.
  1736. //
  1737. // History: 2000-11-11 vtan created
  1738. // --------------------------------------------------------------------------
  1739. EXTERN_C HRESULT WINAPI CheckThemeSignature (LPCWSTR pszName)
  1740. {
  1741. return CheckThemeFileSignature(pszName);
  1742. }