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.

219 lines
8.0 KiB

  1. //---------------------------------------------------------------------------
  2. // Render.h - implements the themed drawing services
  3. //---------------------------------------------------------------------------
  4. #pragma once
  5. //---------------------------------------------------------------------------
  6. #include "SimpStr.h"
  7. #include "loader.h"
  8. #include "ThemeFile.h"
  9. #include "NtlEng.h"
  10. //---------------------------------------------------------------------------
  11. #define FONTCOMPARE(f1, f2) ((memcmp(&(f1), &(f2), sizeof(LOGFONT)-LF_FACESIZE)==0) \
  12. && (lstrcmpi((f1).lfFaceName, (f2).lfFaceName)==0))
  13. //---------------------------------------------------------------------------
  14. #define DEFAULT_TRANSPARENT_COLOR RGB(255, 0, 255)
  15. //---------------------------------------------------------------------------
  16. class CRenderCache; // forward
  17. class CDrawBase; // forward
  18. class CTextDraw; // forward
  19. struct BRUSHBUFF; // forward
  20. //---------------------------------------------------------------------------
  21. struct PARTINFO
  22. {
  23. int iMaxState;
  24. CDrawBase *pDrawObj; // DrawObj[0]
  25. CTextDraw *pTextObj; // TextObj[0]
  26. CDrawBase **pStateDrawObjs; // DrawObjs[1..iMaxState]
  27. CTextDraw **pStateTextObjs; // TextObjs[1..iMaxState]
  28. };
  29. //---------------------------------------------------------------------------
  30. class CRenderObj : public INtlEngCallBack
  31. {
  32. public:
  33. CRenderObj(CUxThemeFile *pThemeFile, int iCacheSlot, int iThemeOffset, int iClassNameOffset,
  34. __int64 iUniqueId, BOOL fEnableCache, DWORD dwOtdFlags);
  35. ~CRenderObj();
  36. HRESULT Init(CDrawBase *pBaseObj, CTextDraw *pTextObj); // must be called after constructor
  37. HRESULT CreateImageBrush(HDC hdc, int IPartId, int iStateId, int iImageIndex, HBRUSH *phbr);
  38. BOOL ValidateObj();
  39. public:
  40. //---- information methods ----
  41. HRESULT WINAPI GetColor(int iPartId, int iStateId, int iPropId, COLORREF *pColor);
  42. HRESULT WINAPI GetMetric(OPTIONAL HDC hdc, int iPartId, int iStateId, int iPropId, int *piVal);
  43. HRESULT WINAPI GetString(int iPartId, int iStateId, int iPropId, LPWSTR pszBuff, DWORD dwMaxBuffChars);
  44. HRESULT WINAPI GetBool(int iPartId, int iStateId, int iPropId, BOOL *pfVal);
  45. HRESULT WINAPI GetInt(int iPartId, int iStateId, int iPropId, int *piVal);
  46. HRESULT WINAPI GetEnumValue(int iPartId, int iStateId, int iPropId, int *piVal);
  47. HRESULT WINAPI GetPosition(int iPartId, int iStateId, int iPropId, POINT *pPoint);
  48. HRESULT WINAPI GetFont(OPTIONAL HDC hdc, int iPartId, int iStateId, int iPropId, BOOL fWantHdcScaling,
  49. LOGFONT *pFont);
  50. HRESULT WINAPI GetMargins(OPTIONAL HDC hdc, int iPartId, int iStateId, int iPropId,
  51. OPTIONAL RECT *prc, MARGINS *pMargins);
  52. HRESULT WINAPI GetIntList(int iPartId, int iStateId, int iPropId, INTLIST *pIntList);
  53. HRESULT WINAPI GetRect(int iPartId, int iStateId, int iPropId, RECT *pRect);
  54. HRESULT WINAPI GetFilename(int iPartId, int iStateId, int iPropId, LPWSTR pszBuff, DWORD dwMaxBuffChars);
  55. HRESULT WINAPI GetPropertyOrigin(int iPartId, int iStateId, int iPropId, PROPERTYORIGIN *pOrigin);
  56. BOOL WINAPI IsPartDefined(int iPartId, int iStateId);
  57. HRESULT GetFilenameOffset(int iPartId, int iStateId, int iPropId, int *piFileNameOffset);
  58. HRESULT GetBitmap(HDC hdc, int iDibOffset, OUT HBITMAP *pBitmap);
  59. HRESULT GetScaledFontHandle(HDC hdc, LOGFONT *plf, HFONT *phFont);
  60. void ReturnBitmap(HBITMAP hBitmap);
  61. void ReturnFontHandle(HFONT hFont);
  62. HRESULT FindGlobalDrawObj(BYTE *pb, int iPartId, int iStateId, CDrawBase **ppObj);
  63. HRESULT GetGlobalDrawObj(int iPartId, int iStateId, CDrawBase **ppObj);
  64. HRESULT SetDpiOverride(int iDpiOverride);
  65. int GetDpiOverride();
  66. //---------------------------------------------------------------------------
  67. inline HRESULT GetDrawObj(int iPartId, int iStateId, CDrawBase **ppObj)
  68. {
  69. HRESULT hr = S_OK;
  70. if (! _pParts)
  71. {
  72. hr = MakeError32(E_FAIL);
  73. }
  74. else
  75. {
  76. if ((iPartId < 0) || (iPartId > _iMaxPart))
  77. iPartId = 0;
  78. PARTINFO *ppi = &_pParts[iPartId];
  79. if (! ppi->pStateDrawObjs) // good to go
  80. {
  81. *ppObj = ppi->pDrawObj;
  82. }
  83. else
  84. {
  85. if ((iStateId < 0) || (iStateId > ppi->iMaxState))
  86. iStateId = 0;
  87. if (! iStateId)
  88. *ppObj = ppi->pDrawObj;
  89. else
  90. *ppObj = ppi->pStateDrawObjs[iStateId-1];
  91. }
  92. if (! *ppObj)
  93. {
  94. Log(LOG_ERROR, L"GetDrawObj() returned NULL");
  95. hr = MakeError32(E_FAIL);
  96. }
  97. }
  98. return hr;
  99. }
  100. //---------------------------------------------------------------------------
  101. inline HRESULT GetTextObj(int iPartId, int iStateId, CTextDraw **ppObj)
  102. {
  103. HRESULT hr = S_OK;
  104. if (! _pParts)
  105. {
  106. hr = MakeError32(E_FAIL);
  107. }
  108. else
  109. {
  110. if ((iPartId < 0) || (iPartId > _iMaxPart))
  111. iPartId = 0;
  112. PARTINFO *ppi = &_pParts[iPartId];
  113. if (! ppi->pStateTextObjs) // good to go
  114. {
  115. *ppObj = ppi->pTextObj;
  116. }
  117. else
  118. {
  119. if ((iStateId < 0) || (iStateId > ppi->iMaxState))
  120. iStateId = 0;
  121. if (! iStateId)
  122. *ppObj = ppi->pTextObj;
  123. else
  124. *ppObj = ppi->pStateTextObjs[iStateId-1];
  125. }
  126. if (! *ppObj)
  127. {
  128. Log(LOG_ERROR, L"GetTextObj() returned NULL");
  129. hr = MakeError32(E_FAIL);
  130. }
  131. }
  132. return hr;
  133. }
  134. //---------------------------------------------------------------------------
  135. inline bool IsReady()
  136. {
  137. if (_pThemeFile)
  138. {
  139. return _pThemeFile->IsReady();
  140. }
  141. return true;
  142. }
  143. //---------------------------------------------------------------------------
  144. int GetValueIndex(int iPartId, int iStateId, int iTarget);
  145. HRESULT PrepareRegionDataForScaling(RGNDATA *pRgnData, LPCRECT prcImage, MARGINS *pMargins);
  146. protected:
  147. //---- helpers ----
  148. HRESULT GetData(int iPartId, int iStateId, int iPropId, BYTE **ppDibData,
  149. OPTIONAL int *piDibSize=NULL);
  150. CRenderCache *GetTlsCacheObj();
  151. HRESULT WalkDrawObjects(MIXEDPTRS &u, int *iPartOffsets);
  152. HRESULT WalkTextObjects(MIXEDPTRS &u, int *iPartOffsets);
  153. HRESULT CreateBitmapFromData(HDC hdc, int iDibOffset, OUT HBITMAP *phBitmap);
  154. HRESULT BuildPackedPtrs(CDrawBase *pBaseObj, CTextDraw *pTextObj);
  155. HRESULT PrepareAlphaBitmap(HBITMAP hBitmap);
  156. public:
  157. //---- data ----
  158. char _szHead[8];
  159. //---- object id ----
  160. CUxThemeFile *_pThemeFile; // holds a refcnt on the binary theme file
  161. int _iCacheSlot; // our index into thread local cache list
  162. __int64 _iUniqueId; // used to validate cache objects against render objects
  163. //---- cached info from theme ----
  164. BYTE *_pbThemeData; // ptr to start of binary theme data
  165. BYTE *_pbSectionData; // ptr to our section of binary theme data
  166. BOOL _fCacheEnabled;
  167. BOOL _fCloseThemeFile;
  168. THEMEMETRICS *_ptm; // ptr to theme metrics
  169. LPCWSTR _pszClassName; // ptr to class name we matched to create this obj
  170. //---- direct ptrs to packed structs ----
  171. int _iMaxPart;
  172. PARTINFO *_pParts; // [0.._MaxPart]
  173. //---- OpenThemeData override flags ----
  174. DWORD _dwOtdFlags;
  175. int _iDpiOverride;
  176. char _szTail[4];
  177. };
  178. //---------------------------------------------------------------------------
  179. HRESULT CreateRenderObj(CUxThemeFile *pThemeFile, int iCacheSlot, int iThemeOffset,
  180. int iClassNameOffset, __int64 iUniqueId, BOOL fEnableCache, CDrawBase *pBaseObj,
  181. CTextDraw *pTextObj, DWORD dwOtdFlags, CRenderObj **ppObj);
  182. //---------------------------------------------------------------------------