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