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