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.

502 lines
12 KiB

  1. /**************************************************************************\
  2. *
  3. * Copyright (c) 1998-2000, Microsoft Corp. All Rights Reserved.
  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 _GDIPLUSREGION_H
  19. #define _GDIPLUSREGION_H
  20. /**
  21. * Construct a new region object
  22. */
  23. inline
  24. Region::Region()
  25. {
  26. GpRegion *region = NULL;
  27. lastResult = DllExports::GdipCreateRegion(&region);
  28. SetNativeRegion(region);
  29. }
  30. inline
  31. Region::Region(IN const RectF& rect)
  32. {
  33. GpRegion *region = NULL;
  34. lastResult = DllExports::GdipCreateRegionRect(&rect, &region);
  35. SetNativeRegion(region);
  36. }
  37. inline
  38. Region::Region(IN const Rect& rect)
  39. {
  40. GpRegion *region = NULL;
  41. lastResult = DllExports::GdipCreateRegionRectI(&rect, &region);
  42. SetNativeRegion(region);
  43. }
  44. inline
  45. Region::Region(IN const GraphicsPath* path)
  46. {
  47. GpRegion *region = NULL;
  48. lastResult = DllExports::GdipCreateRegionPath(path->nativePath, &region);
  49. SetNativeRegion(region);
  50. }
  51. inline
  52. Region::Region(IN const BYTE* regionData, IN INT size)
  53. {
  54. GpRegion *region = NULL;
  55. lastResult = DllExports::GdipCreateRegionRgnData(regionData, size, &region);
  56. SetNativeRegion(region);
  57. }
  58. inline
  59. Region::Region(IN HRGN hRgn)
  60. {
  61. GpRegion *region = NULL;
  62. lastResult = DllExports::GdipCreateRegionHrgn(hRgn, &region);
  63. SetNativeRegion(region);
  64. }
  65. inline
  66. Region* Region::FromHRGN(IN HRGN hRgn)
  67. {
  68. GpRegion *region = NULL;
  69. if (DllExports::GdipCreateRegionHrgn(hRgn, &region) == Ok)
  70. {
  71. Region* newRegion = new Region(region);
  72. if (newRegion == NULL)
  73. {
  74. DllExports::GdipDeleteRegion(region);
  75. }
  76. return newRegion;
  77. }
  78. else
  79. return NULL;
  80. }
  81. inline
  82. Region::~Region()
  83. {
  84. DllExports::GdipDeleteRegion(nativeRegion);
  85. }
  86. /**
  87. * Make a copy of the region object
  88. */
  89. inline Region*
  90. Region::Clone() const
  91. {
  92. GpRegion *region = NULL;
  93. SetStatus(DllExports::GdipCloneRegion(nativeRegion, &region));
  94. return new Region(region);
  95. }
  96. inline Status
  97. Region::MakeInfinite()
  98. {
  99. return SetStatus(DllExports::GdipSetInfinite(nativeRegion));
  100. }
  101. inline Status
  102. Region::MakeEmpty()
  103. {
  104. return SetStatus(DllExports::GdipSetEmpty(nativeRegion));
  105. }
  106. /**
  107. * Region operations
  108. */
  109. inline Status
  110. Region::Intersect(IN const RectF& rect)
  111. {
  112. return SetStatus(DllExports::GdipCombineRegionRect(nativeRegion, &rect, CombineModeIntersect));
  113. }
  114. inline Status
  115. Region::Intersect(IN const Rect& rect)
  116. {
  117. return SetStatus(DllExports::GdipCombineRegionRectI(nativeRegion, &rect, CombineModeIntersect));
  118. }
  119. inline Status
  120. Region::Intersect(IN const GraphicsPath* path)
  121. {
  122. return SetStatus(DllExports::GdipCombineRegionPath(nativeRegion, path->nativePath, CombineModeIntersect));
  123. }
  124. inline Status
  125. Region::Intersect(IN const Region* region)
  126. {
  127. return SetStatus(DllExports::GdipCombineRegionRegion(nativeRegion, region->nativeRegion, CombineModeIntersect));
  128. }
  129. inline Status
  130. Region::Union(IN const RectF& rect)
  131. {
  132. return SetStatus(DllExports::GdipCombineRegionRect(nativeRegion, &rect, CombineModeUnion));
  133. }
  134. inline Status
  135. Region::Union(IN const Rect& rect)
  136. {
  137. return SetStatus(DllExports::GdipCombineRegionRectI(nativeRegion, &rect, CombineModeUnion));
  138. }
  139. inline Status
  140. Region::Union(IN const GraphicsPath* path)
  141. {
  142. return SetStatus(DllExports::GdipCombineRegionPath(nativeRegion, path->nativePath, CombineModeUnion));
  143. }
  144. inline Status
  145. Region::Union(IN const Region* region)
  146. {
  147. return SetStatus(DllExports::GdipCombineRegionRegion(nativeRegion, region->nativeRegion, CombineModeUnion));
  148. }
  149. inline Status
  150. Region::Xor(IN const RectF& rect)
  151. {
  152. return SetStatus(DllExports::GdipCombineRegionRect(nativeRegion, &rect, CombineModeXor));
  153. }
  154. inline Status
  155. Region::Xor(IN const Rect& rect)
  156. {
  157. return SetStatus(DllExports::GdipCombineRegionRectI(nativeRegion, &rect, CombineModeXor));
  158. }
  159. inline Status
  160. Region::Xor(IN const GraphicsPath* path)
  161. {
  162. return SetStatus(DllExports::GdipCombineRegionPath(nativeRegion, path->nativePath, CombineModeXor));
  163. }
  164. inline Status
  165. Region::Xor(IN const Region* region)
  166. {
  167. return SetStatus(DllExports::GdipCombineRegionRegion(nativeRegion, region->nativeRegion, CombineModeXor));
  168. }
  169. inline Status
  170. Region::Exclude(IN const RectF& rect)
  171. {
  172. return SetStatus(DllExports::GdipCombineRegionRect(nativeRegion, &rect, CombineModeExclude));
  173. }
  174. inline Status
  175. Region::Exclude(IN const Rect& rect)
  176. {
  177. return SetStatus(DllExports::GdipCombineRegionRectI(nativeRegion, &rect, CombineModeExclude));
  178. }
  179. inline Status
  180. Region::Exclude(IN const GraphicsPath* path)
  181. {
  182. return SetStatus(DllExports::GdipCombineRegionPath(nativeRegion, path->nativePath, CombineModeExclude));
  183. }
  184. inline Status
  185. Region::Exclude(IN const Region* region)
  186. {
  187. return SetStatus(DllExports::GdipCombineRegionRegion(nativeRegion,
  188. region->nativeRegion, CombineModeExclude));
  189. }
  190. inline Status
  191. Region::Complement(IN const RectF& rect)
  192. {
  193. return SetStatus(DllExports::GdipCombineRegionRect(nativeRegion, &rect, CombineModeComplement));
  194. }
  195. inline Status
  196. Region::Complement(IN const Rect& rect)
  197. {
  198. return SetStatus(DllExports::GdipCombineRegionRectI(nativeRegion, &rect, CombineModeComplement));
  199. }
  200. inline Status
  201. Region::Complement(IN const GraphicsPath* path)
  202. {
  203. return SetStatus(DllExports::GdipCombineRegionPath(nativeRegion,
  204. path->nativePath, CombineModeComplement));
  205. }
  206. inline Status
  207. Region::Complement(IN const Region* region)
  208. {
  209. return SetStatus(DllExports::GdipCombineRegionRegion(nativeRegion,
  210. region->nativeRegion, CombineModeComplement));
  211. }
  212. /**
  213. * Transform operations
  214. */
  215. inline Status
  216. Region::Translate(IN REAL dx,
  217. IN REAL dy)
  218. {
  219. return SetStatus(DllExports::GdipTranslateRegion(nativeRegion, dx, dy));
  220. }
  221. inline Status
  222. Region::Translate(IN INT dx,
  223. IN INT dy)
  224. {
  225. return SetStatus(DllExports::GdipTranslateRegionI(nativeRegion, dx, dy));
  226. }
  227. inline Status
  228. Region::Transform(IN const Matrix* matrix)
  229. {
  230. return SetStatus(DllExports::GdipTransformRegion(nativeRegion, matrix->nativeMatrix));
  231. }
  232. /**
  233. * Get region attributes
  234. */
  235. inline Status
  236. Region::GetBounds(OUT RectF* rect,
  237. IN const Graphics* g) const
  238. {
  239. return SetStatus(DllExports::GdipGetRegionBounds(nativeRegion,
  240. g->nativeGraphics,
  241. rect));
  242. }
  243. inline Status
  244. Region::GetBounds(OUT Rect* rect,
  245. IN const Graphics* g) const
  246. {
  247. return SetStatus(DllExports::GdipGetRegionBoundsI(nativeRegion,
  248. g->nativeGraphics,
  249. rect));
  250. }
  251. inline HRGN
  252. Region::GetHRGN(IN const Graphics* g) const
  253. {
  254. HRGN hrgn;
  255. SetStatus(DllExports::GdipGetRegionHRgn(nativeRegion,
  256. g->nativeGraphics,
  257. &hrgn));
  258. return hrgn;
  259. }
  260. inline BOOL
  261. Region::IsEmpty(IN const Graphics *g) const
  262. {
  263. BOOL booln = FALSE;
  264. SetStatus(DllExports::GdipIsEmptyRegion(nativeRegion,
  265. g->nativeGraphics,
  266. &booln));
  267. return booln;
  268. }
  269. inline BOOL
  270. Region::IsInfinite(IN const Graphics *g) const
  271. {
  272. BOOL booln = FALSE;
  273. SetStatus(DllExports::GdipIsInfiniteRegion(nativeRegion,
  274. g->nativeGraphics,
  275. &booln));
  276. return booln;
  277. }
  278. inline BOOL
  279. Region::Equals(IN const Region* region,
  280. IN const Graphics* g) const
  281. {
  282. BOOL booln = FALSE;
  283. SetStatus(DllExports::GdipIsEqualRegion(nativeRegion,
  284. region->nativeRegion,
  285. g->nativeGraphics,
  286. &booln));
  287. return booln;
  288. }
  289. // Get the size of the buffer needed for the GetData method
  290. inline UINT
  291. Region::GetDataSize() const
  292. {
  293. UINT bufferSize = 0;
  294. SetStatus(DllExports::GdipGetRegionDataSize(nativeRegion, &bufferSize));
  295. return bufferSize;
  296. }
  297. // buffer - where to put the data
  298. // bufferSize - how big the buffer is (should be at least as big as GetDataSize())
  299. // sizeFilled - if not NULL, this is an OUT param that says how many bytes
  300. // of data were written to the buffer.
  301. inline Status
  302. Region::GetData(OUT BYTE* buffer,
  303. IN UINT bufferSize,
  304. OUT UINT* sizeFilled) const
  305. {
  306. return SetStatus(DllExports::GdipGetRegionData(nativeRegion, buffer, bufferSize, sizeFilled));
  307. }
  308. /**
  309. * Hit testing operations
  310. */
  311. inline BOOL
  312. Region::IsVisible(IN const PointF& point,
  313. IN const Graphics* g) const
  314. {
  315. BOOL booln = FALSE;
  316. SetStatus(DllExports::GdipIsVisibleRegionPoint(nativeRegion,
  317. point.X, point.Y,
  318. (g == NULL) ? NULL : g->nativeGraphics,
  319. &booln));
  320. return booln;
  321. }
  322. inline BOOL
  323. Region::IsVisible(IN const RectF& rect,
  324. IN const Graphics* g) const
  325. {
  326. BOOL booln = FALSE;
  327. SetStatus(DllExports::GdipIsVisibleRegionRect(nativeRegion, rect.X,
  328. rect.Y, rect.Width,
  329. rect.Height,
  330. (g == NULL) ? NULL : g->nativeGraphics,
  331. &booln));
  332. return booln;
  333. }
  334. inline BOOL
  335. Region::IsVisible(IN const Point& point,
  336. IN const Graphics* g) const
  337. {
  338. BOOL booln = FALSE;
  339. SetStatus(DllExports::GdipIsVisibleRegionPointI(nativeRegion,
  340. point.X,
  341. point.Y,
  342. (g == NULL) ? NULL : g->nativeGraphics,
  343. &booln));
  344. return booln;
  345. }
  346. inline BOOL
  347. Region::IsVisible(IN const Rect& rect,
  348. IN const Graphics* g) const
  349. {
  350. BOOL booln = FALSE;
  351. SetStatus(DllExports::GdipIsVisibleRegionRectI(nativeRegion,
  352. rect.X,
  353. rect.Y,
  354. rect.Width,
  355. rect.Height,
  356. (g == NULL) ? NULL : g->nativeGraphics,
  357. &booln));
  358. return booln;
  359. }
  360. inline UINT
  361. Region::GetRegionScansCount(IN const Matrix* matrix) const
  362. {
  363. UINT count = 0;
  364. SetStatus(DllExports::GdipGetRegionScansCount(nativeRegion,
  365. &count,
  366. matrix->nativeMatrix));
  367. return count;
  368. }
  369. inline Status
  370. Region::GetRegionScans(
  371. IN const Matrix* matrix,
  372. OUT RectF* rects,
  373. IN OUT INT* count) const
  374. {
  375. return SetStatus(DllExports::GdipGetRegionScans(nativeRegion,
  376. rects,
  377. count,
  378. matrix->nativeMatrix));
  379. }
  380. // If rects is NULL, return the count of rects in the region.
  381. // Otherwise, assume rects is big enough to hold all the region rects
  382. // and fill them in and return the number of rects filled in.
  383. // The rects are returned in the units specified by the matrix
  384. // (which is typically a world-to-device transform).
  385. // Note that the number of rects returned can vary, depending on the
  386. // matrix that is used.
  387. inline Status
  388. Region::GetRegionScans(
  389. IN const Matrix* matrix,
  390. OUT Rect* rects, // NULL to just get the count
  391. IN OUT INT* count) const
  392. {
  393. return SetStatus(DllExports::GdipGetRegionScansI(nativeRegion,
  394. rects,
  395. count,
  396. matrix->nativeMatrix));
  397. }
  398. // protected method
  399. inline Region::Region(GpRegion* nativeRegion)
  400. {
  401. SetNativeRegion(nativeRegion);
  402. }
  403. // protected method
  404. inline VOID Region::SetNativeRegion(GpRegion* nativeRegion)
  405. {
  406. this->nativeRegion = nativeRegion;
  407. }
  408. inline Status Region::GetLastStatus() const
  409. {
  410. Status lastStatus = lastResult;
  411. lastResult = Ok;
  412. return lastStatus;
  413. }
  414. #endif // !_GDIPLUSREGION_H