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.

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