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.

311 lines
8.3 KiB

  1. /**************************************************************************\
  2. *
  3. * Copyright (c) 1999 Microsoft Corporation
  4. *
  5. * Module Name:
  6. *
  7. * Region.hpp
  8. *
  9. * Abstract:
  10. *
  11. * Region API related declarations
  12. *
  13. * Created:
  14. *
  15. * 2/3/1999 DCurtis
  16. *
  17. \**************************************************************************/
  18. #ifndef _REGION_HPP
  19. #define _REGION_HPP
  20. // Specifies that a RegionData node is a leaf node, rather than a node that
  21. // combines 2 children nodes.
  22. #define REGIONTYPE_LEAF 0x10000000
  23. // A RegionData node can be empty or infinite or it can contain a rect,
  24. // a path, or two children nodes (left and right) that are combined with a
  25. // boolean operator. Children nodes are specified by their index into the
  26. // dynamic array called CombineData of GpRegion.
  27. struct RegionData
  28. {
  29. friend class GpRegion;
  30. public:
  31. enum NodeType
  32. {
  33. TypeAnd = CombineModeIntersect,
  34. TypeOr = CombineModeUnion,
  35. TypeXor = CombineModeXor,
  36. TypeExclude = CombineModeExclude,
  37. TypeComplement = CombineModeComplement,
  38. TypeRect = REGIONTYPE_LEAF | 0,
  39. TypePath = REGIONTYPE_LEAF | 1,
  40. TypeEmpty = REGIONTYPE_LEAF | 2,
  41. TypeInfinite = REGIONTYPE_LEAF | 3,
  42. TypeNotValid = 0xFFFFFFFF,
  43. };
  44. protected:
  45. NodeType Type;
  46. union
  47. {
  48. struct // rect data (can't be GpRectF cause of constructor)
  49. {
  50. REAL X;
  51. REAL Y;
  52. REAL Width;
  53. REAL Height;
  54. };
  55. struct
  56. {
  57. GpPath * Path; // copy of path
  58. BOOL Lazy; // if the path is a lazy copy or not
  59. };
  60. struct
  61. {
  62. INT Left; // index of left child
  63. INT Right; // index of right child
  64. };
  65. };
  66. };
  67. typedef DynArray<RegionData> DynRegionDataArray;
  68. class GpRegion : public GpObject, public RegionData
  69. {
  70. friend class GpGraphics;
  71. protected:
  72. mutable GpLockable Lockable;
  73. mutable BOOL RegionOk; // if DeviceRegion is valid
  74. mutable DpRegion DeviceRegion; // region coverage, in device units
  75. mutable GpMatrix Matrix; // last matrix used for DeviceRegion
  76. DynRegionDataArray CombineData; // combined region data, if any
  77. protected:
  78. VOID SetValid(BOOL valid)
  79. {
  80. GpObject::SetValid(valid ? ObjectTagRegion : ObjectTagInvalid);
  81. }
  82. protected:
  83. // doesn't change the region itself, just the device region
  84. GpStatus
  85. UpdateDeviceRegion(
  86. GpMatrix * matrix
  87. ) const;
  88. // doesn't change the region itself, just the device region
  89. GpStatus
  90. CreateLeafDeviceRegion(
  91. const RegionData * regionData,
  92. DpRegion * region
  93. ) const;
  94. // doesn't change the region itself, just the device region
  95. GpStatus
  96. CreateDeviceRegion(
  97. const RegionData * regionData,
  98. DpRegion * region
  99. ) const;
  100. GpStatus
  101. TransformLeaf(
  102. GpMatrix * matrix,
  103. RegionData * data
  104. );
  105. INT
  106. GetRegionDataSize(
  107. const RegionData * regionData
  108. ) const;
  109. GpStatus
  110. GetRegionData(
  111. IStream * stream,
  112. const RegionData * regionData
  113. ) const;
  114. GpStatus
  115. SetRegionData(
  116. const BYTE * & regionDataBuffer,
  117. UINT & regionDataSize,
  118. RegionData * regionData,
  119. RegionData * regionDataArray,
  120. INT & nextArrayIndex,
  121. INT arraySize
  122. );
  123. public:
  124. GpRegion();
  125. GpRegion(const GpRectF * rect);
  126. GpRegion(const GpPath * path);
  127. GpRegion(const GpRegion * region, BOOL lazy = FALSE);
  128. GpRegion(const BYTE * regionDataBuffer, UINT size);
  129. GpRegion(HRGN hRgn);
  130. ~GpRegion();
  131. virtual BOOL IsValid() const
  132. {
  133. // If the region came from a different version of GDI+, its tag
  134. // will not match, and it won't be considered valid.
  135. return ((Type != TypeNotValid) && GpObject::IsValid(ObjectTagRegion));
  136. }
  137. VOID FreePathData();
  138. GpLockable *GetObjectLock() // Get the lock object
  139. {
  140. return &Lockable;
  141. }
  142. virtual ObjectType GetObjectType() const { return ObjectTypeRegion; }
  143. virtual UINT GetDataSize() const;
  144. virtual GpStatus GetData(IStream * stream) const;
  145. virtual GpStatus SetData(const BYTE * dataBuffer, UINT size);
  146. VOID Set(const GpRectF * rect)
  147. {
  148. Set(rect->X, rect->Y, rect->Width, rect->Height);
  149. }
  150. VOID Set(REAL x, REAL y, REAL width, REAL height);
  151. GpStatus Set(const GpPath * path);
  152. GpStatus Set(const GpRegion * region, BOOL lazy = FALSE);
  153. GpStatus Set(
  154. const BYTE * regionDataBuffer, // NULL means set to empty
  155. UINT regionDataSize
  156. );
  157. VOID SetInfinite();
  158. VOID SetEmpty();
  159. GpStatus GetBounds(GpGraphics * graphics, GpRectF * bounds,
  160. BOOL device = FALSE) const;
  161. GpStatus GetBounds(GpMatrix * matrix, GpRect * bounds) const;
  162. GpStatus GetHRgn(GpGraphics * graphics, HRGN * hRgn) const;
  163. GpStatus GetRegionScans(GpRect *rects, INT *count, const GpMatrix *matrix) const;
  164. GpStatus GetRegionScans(GpRectF *rects, INT *count, const GpMatrix *matrix) const;
  165. GpStatus IsVisible(GpPointF * point, GpMatrix * matrix, BOOL * isVisible) const;
  166. GpStatus IsVisible(GpRectF * rect, GpMatrix * matrix, BOOL * isVisible) const;
  167. GpStatus IsVisible(GpRegion * region, GpMatrix * matrix, BOOL * isVisible) const;
  168. GpStatus IsEmpty (GpMatrix * matrix, BOOL * isEmpty) const;
  169. GpStatus IsInfinite(GpMatrix * matrix, BOOL * isInfinite) const;
  170. GpStatus IsEqual (GpRegion * region, GpMatrix * matrix, BOOL * isEqual) const;
  171. BOOL IsOnePath () const
  172. {
  173. ASSERT(IsValid());
  174. return ((Type & REGIONTYPE_LEAF) != 0);
  175. }
  176. BOOL IsRect () const
  177. {
  178. return (IsOnePath() && (Type != TypePath));
  179. }
  180. const GpPath * GetPath() const
  181. {
  182. ASSERT(Type == TypePath);
  183. return Path;
  184. }
  185. GpStatus Transform(GpMatrix * matrix);
  186. GpStatus Offset (REAL xOffset, REAL yOffset);
  187. GpStatus Combine(
  188. const GpRectF * rect,
  189. CombineMode combineMode
  190. );
  191. GpStatus Combine(
  192. const GpPath * path,
  193. CombineMode combineMode
  194. );
  195. GpStatus Combine(
  196. GpRegion * region,
  197. CombineMode combineMode
  198. );
  199. GpStatus And (GpRectF * rect)
  200. {
  201. return Combine (rect, CombineModeIntersect);
  202. }
  203. GpStatus And (GpPath * path)
  204. {
  205. return Combine (path, CombineModeIntersect);
  206. }
  207. GpStatus And (GpRegion * region)
  208. {
  209. return Combine (region, CombineModeIntersect);
  210. }
  211. GpStatus Or (GpRectF * rect)
  212. {
  213. return Combine (rect, CombineModeUnion);
  214. }
  215. GpStatus Or (GpPath * path)
  216. {
  217. return Combine (path, CombineModeUnion);
  218. }
  219. GpStatus Or (GpRegion * region)
  220. {
  221. return Combine (region, CombineModeUnion);
  222. }
  223. GpStatus Xor (GpRectF * rect)
  224. {
  225. return Combine (rect, CombineModeXor);
  226. }
  227. GpStatus Xor (GpPath * path)
  228. {
  229. return Combine (path, CombineModeXor);
  230. }
  231. GpStatus Xor (GpRegion * region)
  232. {
  233. return Combine (region, CombineModeXor);
  234. }
  235. GpStatus Exclude (GpRectF * rect)
  236. {
  237. return Combine (rect, CombineModeExclude);
  238. }
  239. GpStatus Exclude (GpPath * path)
  240. {
  241. return Combine (path, CombineModeExclude);
  242. }
  243. GpStatus Exclude (GpRegion * region)
  244. {
  245. return Combine (region, CombineModeExclude);
  246. }
  247. GpStatus Complement (GpRectF * rect)
  248. {
  249. return Combine (rect, CombineModeComplement);
  250. }
  251. GpStatus Complement (GpPath * path)
  252. {
  253. return Combine (path, CombineModeComplement);
  254. }
  255. GpStatus Complement (GpRegion * region)
  256. {
  257. return Combine (region, CombineModeComplement);
  258. }
  259. };
  260. #endif _REGION_HPP