]> git.saurik.com Git - wxWidgets.git/blob - include/wx/region.h
Add wxActivateEvent::GetActivationReason().
[wxWidgets.git] / include / wx / region.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/region.h
3 // Purpose: Base header for wxRegion
4 // Author: Julian Smart
5 // Modified by:
6 // Created:
7 // Copyright: (c) Julian Smart
8 // Licence: wxWindows Licence
9 /////////////////////////////////////////////////////////////////////////////
10
11 #ifndef _WX_REGION_H_BASE_
12 #define _WX_REGION_H_BASE_
13
14 #include "wx/gdiobj.h"
15 #include "wx/gdicmn.h"
16
17 class WXDLLIMPEXP_FWD_CORE wxBitmap;
18 class WXDLLIMPEXP_FWD_CORE wxColour;
19 class WXDLLIMPEXP_FWD_CORE wxRegion;
20
21 // ----------------------------------------------------------------------------
22 // constants
23 // ----------------------------------------------------------------------------
24
25 // result of wxRegion::Contains() call
26 enum wxRegionContain
27 {
28 wxOutRegion = 0,
29 wxPartRegion = 1,
30 wxInRegion = 2
31 };
32
33 // these constants are used with wxRegion::Combine() in the ports which have
34 // this method
35 enum wxRegionOp
36 {
37 // Creates the intersection of the two combined regions.
38 wxRGN_AND,
39
40 // Creates a copy of the region
41 wxRGN_COPY,
42
43 // Combines the parts of first region that are not in the second one
44 wxRGN_DIFF,
45
46 // Creates the union of two combined regions.
47 wxRGN_OR,
48
49 // Creates the union of two regions except for any overlapping areas.
50 wxRGN_XOR
51 };
52
53 // ----------------------------------------------------------------------------
54 // wxRegionBase defines wxRegion API
55 // ----------------------------------------------------------------------------
56
57 class WXDLLIMPEXP_CORE wxRegionBase : public wxGDIObject
58 {
59 public:
60 // ctors
61 // -----
62
63 // none are defined here but the following should be available:
64 #if 0
65 wxRegion();
66 wxRegion(wxCoord x, wxCoord y, wxCoord w, wxCoord h);
67 wxRegion(const wxPoint& topLeft, const wxPoint& bottomRight);
68 wxRegion(const wxRect& rect);
69 wxRegion(size_t n, const wxPoint *points, wxPolygonFillMode fillStyle = wxODDEVEN_RULE);
70 wxRegion(const wxBitmap& bmp);
71 wxRegion(const wxBitmap& bmp, const wxColour& transp, int tolerance = 0);
72 #endif // 0
73
74 // operators
75 // ---------
76
77 bool operator==(const wxRegion& region) const { return IsEqual(region); }
78 bool operator!=(const wxRegion& region) const { return !(*this == region); }
79
80
81 // accessors
82 // ---------
83
84 // Is region empty?
85 virtual bool IsEmpty() const = 0;
86 bool Empty() const { return IsEmpty(); }
87
88 // Is region equal (i.e. covers the same area as another one)?
89 bool IsEqual(const wxRegion& region) const;
90
91 // Get the bounding box
92 bool GetBox(wxCoord& x, wxCoord& y, wxCoord& w, wxCoord& h) const
93 { return DoGetBox(x, y, w, h); }
94 wxRect GetBox() const
95 {
96 wxCoord x, y, w, h;
97 return DoGetBox(x, y, w, h) ? wxRect(x, y, w, h) : wxRect();
98 }
99
100 // Test if the given point or rectangle is inside this region
101 wxRegionContain Contains(wxCoord x, wxCoord y) const
102 { return DoContainsPoint(x, y); }
103 wxRegionContain Contains(const wxPoint& pt) const
104 { return DoContainsPoint(pt.x, pt.y); }
105 wxRegionContain Contains(wxCoord x, wxCoord y, wxCoord w, wxCoord h) const
106 { return DoContainsRect(wxRect(x, y, w, h)); }
107 wxRegionContain Contains(const wxRect& rect) const
108 { return DoContainsRect(rect); }
109
110
111 // operations
112 // ----------
113
114 virtual void Clear() = 0;
115
116 // Move the region
117 bool Offset(wxCoord x, wxCoord y)
118 { return DoOffset(x, y); }
119 bool Offset(const wxPoint& pt)
120 { return DoOffset(pt.x, pt.y); }
121
122 // Union rectangle or region with this region.
123 bool Union(wxCoord x, wxCoord y, wxCoord w, wxCoord h)
124 { return DoUnionWithRect(wxRect(x, y, w, h)); }
125 bool Union(const wxRect& rect)
126 { return DoUnionWithRect(rect); }
127 bool Union(const wxRegion& region)
128 { return DoUnionWithRegion(region); }
129
130 #if wxUSE_IMAGE
131 // Use the non-transparent pixels of a wxBitmap for the region to combine
132 // with this region. First version takes transparency from bitmap's mask,
133 // second lets the user specify the colour to be treated as transparent
134 // along with an optional tolerance value.
135 // NOTE: implemented in common/rgncmn.cpp
136 bool Union(const wxBitmap& bmp);
137 bool Union(const wxBitmap& bmp, const wxColour& transp, int tolerance = 0);
138 #endif // wxUSE_IMAGE
139
140 // Intersect rectangle or region with this one.
141 bool Intersect(wxCoord x, wxCoord y, wxCoord w, wxCoord h);
142 bool Intersect(const wxRect& rect);
143 bool Intersect(const wxRegion& region)
144 { return DoIntersect(region); }
145
146 // Subtract rectangle or region from this:
147 // Combines the parts of 'this' that are not part of the second region.
148 bool Subtract(wxCoord x, wxCoord y, wxCoord w, wxCoord h);
149 bool Subtract(const wxRect& rect);
150 bool Subtract(const wxRegion& region)
151 { return DoSubtract(region); }
152
153 // XOR: the union of two combined regions except for any overlapping areas.
154 bool Xor(wxCoord x, wxCoord y, wxCoord w, wxCoord h);
155 bool Xor(const wxRect& rect);
156 bool Xor(const wxRegion& region)
157 { return DoXor(region); }
158
159
160 // Convert the region to a B&W bitmap with the white pixels being inside
161 // the region.
162 wxBitmap ConvertToBitmap() const;
163
164 protected:
165 virtual bool DoIsEqual(const wxRegion& region) const = 0;
166 virtual bool DoGetBox(wxCoord& x, wxCoord& y, wxCoord& w, wxCoord& h) const = 0;
167 virtual wxRegionContain DoContainsPoint(wxCoord x, wxCoord y) const = 0;
168 virtual wxRegionContain DoContainsRect(const wxRect& rect) const = 0;
169
170 virtual bool DoOffset(wxCoord x, wxCoord y) = 0;
171
172 virtual bool DoUnionWithRect(const wxRect& rect) = 0;
173 virtual bool DoUnionWithRegion(const wxRegion& region) = 0;
174
175 virtual bool DoIntersect(const wxRegion& region) = 0;
176 virtual bool DoSubtract(const wxRegion& region) = 0;
177 virtual bool DoXor(const wxRegion& region) = 0;
178 };
179
180 // some ports implement a generic Combine() function while others only
181 // implement individual wxRegion operations, factor out the common code for the
182 // ports with Combine() in this class
183 #if defined(__WXMSW__) || \
184 ( defined(__WXMAC__) && wxOSX_USE_COCOA_OR_CARBON ) || \
185 defined(__WXPM__)
186
187 #define wxHAS_REGION_COMBINE
188
189 class WXDLLIMPEXP_CORE wxRegionWithCombine : public wxRegionBase
190 {
191 public:
192 // these methods are not part of public API as they're not implemented on
193 // all ports
194 bool Combine(wxCoord x, wxCoord y, wxCoord w, wxCoord h, wxRegionOp op);
195 bool Combine(const wxRect& rect, wxRegionOp op);
196 bool Combine(const wxRegion& region, wxRegionOp op)
197 { return DoCombine(region, op); }
198
199
200 protected:
201 // the real Combine() method, to be defined in the derived class
202 virtual bool DoCombine(const wxRegion& region, wxRegionOp op) = 0;
203
204 // implement some wxRegionBase pure virtuals in terms of Combine()
205 virtual bool DoUnionWithRect(const wxRect& rect);
206 virtual bool DoUnionWithRegion(const wxRegion& region);
207 virtual bool DoIntersect(const wxRegion& region);
208 virtual bool DoSubtract(const wxRegion& region);
209 virtual bool DoXor(const wxRegion& region);
210 };
211
212 #endif // ports with wxRegion::Combine()
213
214 #if defined(__WXMSW__)
215 #include "wx/msw/region.h"
216 #elif defined(__WXGTK20__)
217 #include "wx/gtk/region.h"
218 #elif defined(__WXGTK__)
219 #include "wx/gtk1/region.h"
220 #elif defined(__WXMOTIF__) || defined(__WXX11__)
221 #include "wx/x11/region.h"
222 #elif defined(__WXDFB__)
223 #include "wx/dfb/region.h"
224 #elif defined(__WXMAC__)
225 #include "wx/osx/region.h"
226 #elif defined(__WXCOCOA__)
227 #include "wx/cocoa/region.h"
228 #elif defined(__WXPM__)
229 #include "wx/os2/region.h"
230 #endif
231
232 // ----------------------------------------------------------------------------
233 // inline functions implementation
234 // ----------------------------------------------------------------------------
235
236 // NB: these functions couldn't be defined in the class declaration as they use
237 // wxRegion and so can be only defined after including the header declaring
238 // the real class
239
240 inline bool wxRegionBase::Intersect(const wxRect& rect)
241 {
242 return DoIntersect(wxRegion(rect));
243 }
244
245 inline bool wxRegionBase::Subtract(const wxRect& rect)
246 {
247 return DoSubtract(wxRegion(rect));
248 }
249
250 inline bool wxRegionBase::Xor(const wxRect& rect)
251 {
252 return DoXor(wxRegion(rect));
253 }
254
255 // ...and these functions are here because they call the ones above, and its
256 // not really proper to call an inline function before its defined inline.
257
258 inline bool wxRegionBase::Intersect(wxCoord x, wxCoord y, wxCoord w, wxCoord h)
259 {
260 return Intersect(wxRect(x, y, w, h));
261 }
262
263 inline bool wxRegionBase::Subtract(wxCoord x, wxCoord y, wxCoord w, wxCoord h)
264 {
265 return Subtract(wxRect(x, y, w, h));
266 }
267
268 inline bool wxRegionBase::Xor(wxCoord x, wxCoord y, wxCoord w, wxCoord h)
269 {
270 return Xor(wxRect(x, y, w, h));
271 }
272
273 #ifdef wxHAS_REGION_COMBINE
274
275 inline bool wxRegionWithCombine::Combine(wxCoord x,
276 wxCoord y,
277 wxCoord w,
278 wxCoord h,
279 wxRegionOp op)
280 {
281 return DoCombine(wxRegion(x, y, w, h), op);
282 }
283
284 inline bool wxRegionWithCombine::Combine(const wxRect& rect, wxRegionOp op)
285 {
286 return DoCombine(wxRegion(rect), op);
287 }
288
289 #endif // wxHAS_REGION_COMBINE
290
291 #endif // _WX_REGION_H_BASE_