]> git.saurik.com Git - wxWidgets.git/blob - src/stubs/region.cpp
maintaining 8.1 compat (defining 8.5 calls)
[wxWidgets.git] / src / stubs / region.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // File: region.cpp
3 // Purpose: Region class
4 // Author: Markus Holzem/Julian Smart/AUTHOR
5 // Created: Fri Oct 24 10:46:34 MET 1997
6 // RCS-ID: $Id$
7 // Copyright: (c) 1997 Markus Holzem/Julian Smart/AUTHOR
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
10
11 #ifdef __GNUG__
12 #pragma implementation "region.h"
13 #endif
14
15 #include "wx/region.h"
16 #include "wx/gdicmn.h"
17
18 IMPLEMENT_DYNAMIC_CLASS(wxRegion, wxGDIObject)
19 IMPLEMENT_DYNAMIC_CLASS(wxRegionIterator, wxObject)
20
21 //-----------------------------------------------------------------------------
22 // wxRegionRefData implementation
23 //-----------------------------------------------------------------------------
24
25 class WXDLLEXPORT wxRegionRefData : public wxGDIRefData {
26 public:
27 wxRegionRefData()
28 {
29 }
30
31 wxRegionRefData(const wxRegionRefData& data)
32 {
33 // TODO
34 }
35
36 ~wxRegionRefData()
37 {
38 // TODO
39 }
40 };
41
42
43 //-----------------------------------------------------------------------------
44 // wxRegion
45 //-----------------------------------------------------------------------------
46
47 /*!
48 * Create an empty region.
49 */
50 wxRegion::wxRegion()
51 {
52 m_refData = new wxRegionRefData;
53 // TODO create empty region
54 }
55
56 wxRegion::wxRegion(long x, long y, long w, long h)
57 {
58 m_refData = new wxRegionRefData;
59 // TODO create rect region
60 }
61
62 wxRegion::wxRegion(const wxPoint& topLeft, const wxPoint& bottomRight)
63 {
64 m_refData = new wxRegionRefData;
65 // TODO create rect region
66 }
67
68 wxRegion::wxRegion(const wxRect& rect)
69 {
70 m_refData = new wxRegionRefData;
71 // TODO create rect region
72 }
73
74 /*!
75 * Destroy the region.
76 */
77 wxRegion::~wxRegion()
78 {
79 // m_refData unrefed in ~wxObject
80 }
81
82 //-----------------------------------------------------------------------------
83 //# Modify region
84 //-----------------------------------------------------------------------------
85
86 //! Clear current region
87 void wxRegion::Clear()
88 {
89 UnRef();
90 }
91
92 //! Combine rectangle (x, y, w, h) with this.
93 bool wxRegion::Combine(long x, long y, long width, long height, wxRegionOp op)
94 {
95 // Don't change shared data
96 if (!m_refData) {
97 m_refData = new wxRegionRefData();
98 } else if (m_refData->GetRefCount() > 1) {
99 wxRegionRefData* ref = (wxRegionRefData*)m_refData;
100 UnRef();
101 m_refData = new wxRegionRefData(*ref);
102 }
103 // If ref count is 1, that means it's 'ours' anyway so no action.
104
105 // TODO create rect region
106
107 int mode = 0; // TODO platform-specific code
108 switch (op)
109 {
110 case wxRGN_AND:
111 // TODO
112 break ;
113 case wxRGN_OR:
114 // TODO
115 break ;
116 case wxRGN_XOR:
117 // TODO
118 break ;
119 case wxRGN_DIFF:
120 // TODO
121 break ;
122 case wxRGN_COPY:
123 default:
124 // TODO
125 break ;
126 }
127
128 // TODO do combine region
129
130 return FALSE;
131 }
132
133 //! Union /e region with this.
134 bool wxRegion::Combine(const wxRegion& region, wxRegionOp op)
135 {
136 if (region.Empty())
137 return FALSE;
138
139 // Don't change shared data
140 if (!m_refData) {
141 m_refData = new wxRegionRefData();
142 } else if (m_refData->GetRefCount() > 1) {
143 wxRegionRefData* ref = (wxRegionRefData*)m_refData;
144 UnRef();
145 m_refData = new wxRegionRefData(*ref);
146 }
147
148 int mode = 0; // TODO platform-specific code
149 switch (op)
150 {
151 case wxRGN_AND:
152 // TODO
153 break ;
154 case wxRGN_OR:
155 // TODO
156 break ;
157 case wxRGN_XOR:
158 // TODO
159 break ;
160 case wxRGN_DIFF:
161 // TODO
162 break ;
163 case wxRGN_COPY:
164 default:
165 // TODO
166 break ;
167 }
168
169 // TODO combine region
170
171 return FALSE;
172 }
173
174 bool wxRegion::Combine(const wxRect& rect, wxRegionOp op)
175 {
176 return Combine(rect.GetLeft(), rect.GetTop(), rect.GetWidth(), rect.GetHeight(), op);
177 }
178
179 //-----------------------------------------------------------------------------
180 //# Information on region
181 //-----------------------------------------------------------------------------
182
183 // Outer bounds of region
184 void wxRegion::GetBox(long& x, long& y, long&w, long &h) const
185 {
186 if (m_refData) {
187 // TODO get box
188 } else {
189 x = y = w = h = 0;
190 }
191 }
192
193 wxRect wxRegion::GetBox() const
194 {
195 long x, y, w, h;
196 GetBox(x, y, w, h);
197 return wxRect(x, y, w, h);
198 }
199
200 // Is region empty?
201 bool wxRegion::Empty() const
202 {
203 // TODO
204 return FALSE;
205 }
206
207 //-----------------------------------------------------------------------------
208 //# Tests
209 //-----------------------------------------------------------------------------
210
211 // Does the region contain the point (x,y)?
212 wxRegionContain wxRegion::Contains(long x, long y) const
213 {
214 if (!m_refData)
215 return wxOutRegion;
216
217 // TODO. Return wxInRegion if within region.
218 if (0)
219 return wxInRegion;
220 return wxOutRegion;
221 }
222
223 // Does the region contain the point pt?
224 wxRegionContain wxRegion::Contains(const wxPoint& pt) const
225 {
226 if (!m_refData)
227 return wxOutRegion;
228
229 // TODO. Return wxInRegion if within region.
230 if (0)
231 return wxInRegion;
232 else
233 return wxOutRegion;
234 }
235
236 // Does the region contain the rectangle (x, y, w, h)?
237 wxRegionContain wxRegion::Contains(long x, long y, long w, long h) const
238 {
239 if (!m_refData)
240 return wxOutRegion;
241
242 // TODO. Return wxInRegion if within region.
243 if (0)
244 return wxInRegion;
245 else
246 return wxOutRegion;
247 }
248
249 // Does the region contain the rectangle rect
250 wxRegionContain wxRegion::Contains(const wxRect& rect) const
251 {
252 if (!m_refData)
253 return wxOutRegion;
254
255 long x, y, w, h;
256 x = rect.x;
257 y = rect.y;
258 w = rect.GetWidth();
259 h = rect.GetHeight();
260 return Contains(x, y, w, h);
261 }
262
263 ///////////////////////////////////////////////////////////////////////////////
264 // //
265 // wxRegionIterator //
266 // //
267 ///////////////////////////////////////////////////////////////////////////////
268
269 /*!
270 * Initialize empty iterator
271 */
272 wxRegionIterator::wxRegionIterator() : m_current(0), m_numRects(0), m_rects(NULL)
273 {
274 }
275
276 wxRegionIterator::~wxRegionIterator()
277 {
278 if (m_rects)
279 delete[] m_rects;
280 }
281
282 /*!
283 * Initialize iterator for region
284 */
285 wxRegionIterator::wxRegionIterator(const wxRegion& region)
286 {
287 m_rects = NULL;
288
289 Reset(region);
290 }
291
292 /*!
293 * Reset iterator for a new /e region.
294 */
295 void wxRegionIterator::Reset(const wxRegion& region)
296 {
297 m_current = 0;
298 m_region = region;
299
300 if (m_rects)
301 delete[] m_rects;
302
303 m_rects = NULL;
304
305 if (m_region.Empty())
306 m_numRects = 0;
307 else
308 {
309 // TODO create m_rects and fill with rectangles for this region
310 m_numRects = 0;
311 }
312 }
313
314 /*!
315 * Increment iterator. The rectangle returned is the one after the
316 * incrementation.
317 */
318 void wxRegionIterator::operator ++ ()
319 {
320 if (m_current < m_numRects)
321 ++m_current;
322 }
323
324 /*!
325 * Increment iterator. The rectangle returned is the one before the
326 * incrementation.
327 */
328 void wxRegionIterator::operator ++ (int)
329 {
330 if (m_current < m_numRects)
331 ++m_current;
332 }
333
334 long wxRegionIterator::GetX() const
335 {
336 if (m_current < m_numRects)
337 return m_rects[m_current].x;
338 return 0;
339 }
340
341 long wxRegionIterator::GetY() const
342 {
343 if (m_current < m_numRects)
344 return m_rects[m_current].y;
345 return 0;
346 }
347
348 long wxRegionIterator::GetW() const
349 {
350 if (m_current < m_numRects)
351 return m_rects[m_current].width ;
352 return 0;
353 }
354
355 long wxRegionIterator::GetH() const
356 {
357 if (m_current < m_numRects)
358 return m_rects[m_current].height;
359 return 0;
360 }
361