great copy ctor/assignment operators cleanup by Paul Cornett (patch 1307665)
[wxWidgets.git] / include / wx / os2 / region.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: region.h
3 // Purpose: wxRegion class
4 // Author: David Webster
5 // Modified by:
6 // Created: 10/15/99
7 // RCS-ID: $Id$
8 // Copyright: (c) David Webster
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_REGION_H_
13 #define _WX_REGION_H_
14
15 #include "wx/list.h"
16 #include "wx/gdiobj.h"
17 #include "wx/gdicmn.h"
18 #include "wx/bitmap.h"
19 #include "wx/os2/private.h"
20
21 class WXDLLEXPORT wxRect;
22 class WXDLLEXPORT wxPoint;
23
24 enum wxRegionContain {
25 wxOutRegion = 0, wxPartRegion = 1, wxInRegion = 2
26 };
27
28 // So far, for internal use only
29 enum wxRegionOp { wxRGN_AND // Creates the intersection of the two combined regions.
30 ,wxRGN_COPY // Creates a copy of the region identified by hrgnSrc1.
31 ,wxRGN_DIFF // Combines the parts of hrgnSrc1 that are not part of hrgnSrc2.
32 ,wxRGN_OR // Creates the union of two combined regions.
33 ,wxRGN_XOR // Creates the union of two combined regions except for any overlapping areas.
34 };
35
36 class WXDLLEXPORT wxRegion : public wxGDIObject
37 {
38 public:
39 wxRegion( wxCoord x
40 ,wxCoord y
41 ,wxCoord vWidth
42 ,wxCoord vHeight
43 );
44 wxRegion( const wxPoint& rTopLeft
45 ,const wxPoint& rBottomRight
46 );
47 wxRegion(const wxRect& rRect);
48 wxRegion(WXHRGN hRegion, WXHDC hPS); // Hangs on to this region
49 wxRegion( const wxBitmap& bmp)
50 {
51 Union(bmp);
52 }
53 wxRegion( const wxBitmap& bmp,
54 const wxColour& transColour, int tolerance = 0)
55 {
56 Union(bmp, transColour, tolerance);
57 }
58
59 wxRegion();
60 ~wxRegion();
61
62 //
63 // Modify region
64 //
65
66 //
67 // Clear current region
68 //
69 void Clear(void);
70
71 bool Offset( wxCoord x
72 ,wxCoord y
73 );
74
75 //
76 // Union rectangle or region with this.
77 //
78 inline bool Union( wxCoord x
79 ,wxCoord y
80 ,wxCoord vWidth
81 ,wxCoord vHeight
82 )
83 {
84 return Combine( x
85 ,y
86 ,vWidth
87 ,vHeight
88 ,wxRGN_OR
89 );
90 }
91 inline bool Union( const wxRect& rRect) { return Combine(rRect, wxRGN_OR); }
92 inline bool Union(const wxRegion& rRegion) { return Combine(rRegion, wxRGN_OR); }
93
94 //
95 // Intersect rectangle or region with this.
96 //
97 inline bool Intersect( wxCoord x
98 ,wxCoord y
99 ,wxCoord vWidth
100 ,wxCoord vHeight
101 )
102 {
103 return Combine( x
104 ,y
105 ,vWidth
106 ,vHeight
107 ,wxRGN_AND
108 );
109 }
110 inline bool Intersect(const wxRect& rRect) { return Combine(rRect, wxRGN_AND); }
111 inline bool Intersect(const wxRegion& rRegion) { return Combine(rRegion, wxRGN_AND); }
112
113 //
114 // Subtract rectangle or region from this:
115 // Combines the parts of 'this' that are not part of the second region.
116 //
117 inline bool Subtract( wxCoord x
118 ,wxCoord y
119 ,wxCoord vWidth
120 ,wxCoord vHeight
121 )
122 {
123 return Combine( x
124 ,y
125 ,vWidth
126 ,vHeight
127 ,wxRGN_DIFF
128 );
129 }
130 inline bool Subtract(const wxRect& rRect) { return Combine(rRect, wxRGN_DIFF); }
131 inline bool Subtract(const wxRegion& rRegion) { return Combine(rRegion, wxRGN_DIFF); }
132
133 //
134 // XOR: the union of two combined regions except for any overlapping areas.
135 //
136 inline bool Xor( wxCoord x
137 ,wxCoord y
138 ,wxCoord vWidth
139 ,wxCoord vHeight
140 )
141 {
142 return Combine( x
143 ,y
144 ,vWidth
145 ,vHeight
146 ,wxRGN_XOR
147 );
148 }
149 inline bool Xor(const wxRect& rRect) { return Combine(rRect, wxRGN_XOR); }
150 inline bool Xor(const wxRegion& rRegion) { return Combine(rRegion, wxRGN_XOR); }
151
152 //
153 // Information on region
154 // Outer bounds of region
155 //
156 void GetBox( wxCoord& rX
157 ,wxCoord& rY
158 ,wxCoord& rWidth
159 ,wxCoord& rHeight
160 ) const;
161 wxRect GetBox(void) const;
162
163 //
164 // Is region empty?
165 //
166 bool Empty(void) const;
167 inline bool IsEmpty() const { return Empty(); }
168
169 //
170 // Tests
171 // Does the region contain the point (x,y)?
172 //
173 wxRegionContain Contains( wxCoord lX
174 ,wxCoord lY
175 ) const;
176
177 //
178 // Convert the region to a B&W bitmap with the black pixels being inside
179 // the region.
180 //
181 wxBitmap ConvertToBitmap(void) const;
182
183 // Use the non-transparent pixels of a wxBitmap for the region to combine
184 // with this region. First version takes transparency from bitmap's mask,
185 // second lets the user specify the colour to be treated as transparent
186 // along with an optional tolerance value.
187 // NOTE: implemented in common/rgncmn.cpp
188 bool Union(const wxBitmap& bmp);
189 bool Union(const wxBitmap& bmp,
190 const wxColour& transColour, int tolerance = 0);
191
192 //
193 // Does the region contain the point pt?
194 //
195 wxRegionContain Contains(const wxPoint& rPoint) const;
196
197 //
198 // Does the region contain the rectangle (x, y, w, h)?
199 //
200 wxRegionContain Contains( wxCoord x
201 ,wxCoord y
202 ,wxCoord lWidth
203 ,wxCoord lHeight
204 ) const;
205
206 //
207 // Does the region contain the rectangle rect?
208 //
209 wxRegionContain Contains(const wxRect& rRect) const;
210
211 //
212 // Internal
213 //
214 bool Combine( wxCoord x
215 ,wxCoord y
216 ,wxCoord vWidth
217 ,wxCoord vHeight
218 ,wxRegionOp eOp
219 );
220 bool Combine( const wxRegion& rRegion
221 ,wxRegionOp eOp
222 );
223 bool Combine( const wxRect& rRect
224 ,wxRegionOp eOp
225 );
226
227 //
228 // Get internal region handle
229 //
230 WXHRGN GetHRGN(void) const;
231 void SetPS(HPS hPS);
232
233 protected:
234 virtual wxObjectRefData* CreateData(void) const;
235 virtual wxObjectRefData* CloneData(const wxObjectRefData* pData) const;
236
237 friend class WXDLLEXPORT wxRegionIterator;
238 DECLARE_DYNAMIC_CLASS(wxRegion);
239
240 }; // end of CLASS wxRegion
241
242 class WXDLLEXPORT wxRegionIterator : public wxObject
243 {
244 DECLARE_DYNAMIC_CLASS(wxRegionIterator);
245 public:
246 wxRegionIterator();
247 wxRegionIterator(const wxRegion& rRegion);
248 ~wxRegionIterator();
249
250 void Reset(void) { m_lCurrent = 0; }
251 void Reset(const wxRegion& rRegion);
252
253 operator bool (void) const { return m_lCurrent < m_lNumRects; }
254 bool HaveRects(void) const { return m_lCurrent < m_lNumRects; }
255
256 void operator ++ (void);
257 void operator ++ (int);
258
259 wxCoord GetX(void) const;
260 wxCoord GetY(void) const;
261 wxCoord GetW(void) const;
262 wxCoord GetWidth(void) const { return GetW(); }
263 wxCoord GetH(void) const;
264 wxCoord GetHeight(void) const { return GetH(); }
265 wxRect GetRect(void) const { return wxRect(GetX(), GetY(), GetWidth(), GetHeight()); }
266
267 private:
268 long m_lCurrent;
269 long m_lNumRects;
270 wxRegion m_vRegion;
271 wxRect* m_pRects;
272 }; // end of wxRegionIterator
273
274 #endif
275 // _WX_REGION_H_