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.

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