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.

514 lines
14 KiB

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