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