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