]> git.saurik.com Git - wxWidgets.git/blame - src/os2/region.cpp
added wxGetMultiChoice() (which refuses to work for some reason - will fix
[wxWidgets.git] / src / os2 / region.cpp
CommitLineData
0e320a79
DW
1/////////////////////////////////////////////////////////////////////////////
2// File: region.cpp
3// Purpose: Region class
409c9842
DW
4// Author: David Webster
5// Modified by:
6// Created: 10/15/99
0e320a79 7// RCS-ID: $Id$
409c9842 8// Copyright: (c) Davdi Webster
0e320a79
DW
9// Licence: wxWindows licence
10/////////////////////////////////////////////////////////////////////////////
11
409c9842
DW
12// For compilers that support precompilation, includes "wx.h".
13#include "wx/wxprec.h"
0e320a79 14
409c9842 15#include "wx/os2/region.h"
0e320a79
DW
16#include "wx/gdicmn.h"
17
409c9842
DW
18#include "wx/window.h"
19#include "wx/os2/private.h"
20
0e320a79
DW
21 IMPLEMENT_DYNAMIC_CLASS(wxRegion, wxGDIObject)
22 IMPLEMENT_DYNAMIC_CLASS(wxRegionIterator, wxObject)
0e320a79
DW
23
24//-----------------------------------------------------------------------------
25// wxRegionRefData implementation
26//-----------------------------------------------------------------------------
27
28class WXDLLEXPORT wxRegionRefData : public wxGDIRefData {
29public:
409c9842
DW
30 wxRegionRefData()
31 {
32 m_region = 0;
33 }
0e320a79 34
409c9842
DW
35 wxRegionRefData(const wxRegionRefData& data)
36 {
0e320a79 37 // TODO
409c9842 38 }
0e320a79 39
409c9842
DW
40 ~wxRegionRefData()
41 {
0e320a79 42 // TODO
409c9842
DW
43
44 }
04701dd9
DW
45
46 HRGN m_region;
0e320a79
DW
47};
48
04701dd9 49#define M_REGION (((wxRegionRefData*)m_refData)->m_region)
0e320a79
DW
50
51//-----------------------------------------------------------------------------
52// wxRegion
53//-----------------------------------------------------------------------------
54
55/*!
56 * Create an empty region.
57 */
58wxRegion::wxRegion()
59{
60 m_refData = new wxRegionRefData;
61 // TODO create empty region
62}
63
409c9842
DW
64wxRegion::wxRegion(WXHRGN hRegion)
65{
66 m_refData = new wxRegionRefData;
67 M_REGION = (HRGN) hRegion;
68}
69
0b7e7739 70wxRegion::wxRegion(wxCoord x, wxCoord y, wxCoord w, wxCoord h)
0e320a79
DW
71{
72 m_refData = new wxRegionRefData;
73 // TODO create rect region
74}
75
76wxRegion::wxRegion(const wxPoint& topLeft, const wxPoint& bottomRight)
77{
78 m_refData = new wxRegionRefData;
79 // TODO create rect region
80}
81
82wxRegion::wxRegion(const wxRect& rect)
83{
84 m_refData = new wxRegionRefData;
85 // TODO create rect region
86}
87
88/*!
89 * Destroy the region.
90 */
91wxRegion::~wxRegion()
92{
93 // m_refData unrefed in ~wxObject
94}
95
96//-----------------------------------------------------------------------------
97//# Modify region
98//-----------------------------------------------------------------------------
99
100//! Clear current region
101void wxRegion::Clear()
102{
103 UnRef();
104}
105
106//! Combine rectangle (x, y, w, h) with this.
0b7e7739 107bool wxRegion::Combine(wxCoord x, wxCoord y, wxCoord width, wxCoord height, wxRegionOp op)
0e320a79 108{
409c9842
DW
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 }
0e320a79
DW
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.
148bool wxRegion::Combine(const wxRegion& region, wxRegionOp op)
149{
409c9842
DW
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 }
0e320a79
DW
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
409c9842 185 return FALSE;
0e320a79
DW
186}
187
188bool 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
0b7e7739 198void wxRegion::GetBox(wxCoord& x, wxCoord& y, wxCoord&w, wxCoord &h) const
0e320a79 199{
409c9842 200 if (m_refData) {
0e320a79 201 // TODO get box
409c9842
DW
202 } else {
203 x = y = w = h = 0;
204 }
0e320a79
DW
205}
206
207wxRect wxRegion::GetBox() const
208{
0b7e7739 209 wxCoord x, y, w, h;
0e320a79
DW
210 GetBox(x, y, w, h);
211 return wxRect(x, y, w, h);
212}
213
214// Is region empty?
215bool 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)?
0b7e7739 226wxRegionContain wxRegion::Contains(wxCoord x, wxCoord y) const
0e320a79 227{
04701dd9 228 bool bOK = FALSE; // temporary
409c9842
DW
229 if (!m_refData)
230 return wxOutRegion;
0e320a79
DW
231
232 // TODO. Return wxInRegion if within region.
04701dd9 233 if (bOK)
0e320a79
DW
234 return wxInRegion;
235 return wxOutRegion;
236}
237
238// Does the region contain the point pt?
239wxRegionContain wxRegion::Contains(const wxPoint& pt) const
240{
04701dd9 241 bool bOK = FALSE; // temporary
409c9842
DW
242 if (!m_refData)
243 return wxOutRegion;
0e320a79
DW
244
245 // TODO. Return wxInRegion if within region.
04701dd9 246 if (bOK)
0e320a79
DW
247 return wxInRegion;
248 else
249 return wxOutRegion;
250}
251
252// Does the region contain the rectangle (x, y, w, h)?
0b7e7739 253wxRegionContain wxRegion::Contains(wxCoord x, wxCoord y, wxCoord w, wxCoord h) const
0e320a79 254{
04701dd9 255 bool bOK = FALSE; // temporary
409c9842
DW
256 if (!m_refData)
257 return wxOutRegion;
0e320a79
DW
258
259 // TODO. Return wxInRegion if within region.
04701dd9 260 if (bOK)
0e320a79
DW
261 return wxInRegion;
262 else
263 return wxOutRegion;
264}
265
266// Does the region contain the rectangle rect
267wxRegionContain wxRegion::Contains(const wxRect& rect) const
268{
409c9842
DW
269 if (!m_refData)
270 return wxOutRegion;
0e320a79 271
0b7e7739 272 wxCoord x, y, w, h;
0e320a79
DW
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
409c9842
DW
280// Get internal region handle
281WXHRGN wxRegion::GetHRGN() const
282{
283 if (!m_refData)
284 return (WXHRGN) 0;
285 return (WXHRGN) M_REGION;
286}
287
0e320a79 288///////////////////////////////////////////////////////////////////////////////
409c9842
DW
289// //
290// wxRegionIterator //
291// //
0e320a79
DW
292///////////////////////////////////////////////////////////////////////////////
293
294/*!
295 * Initialize empty iterator
296 */
297wxRegionIterator::wxRegionIterator() : m_current(0), m_numRects(0), m_rects(NULL)
298{
299}
300
301wxRegionIterator::~wxRegionIterator()
302{
303 if (m_rects)
304 delete[] m_rects;
305}
306
307/*!
308 * Initialize iterator for region
309 */
310wxRegionIterator::wxRegionIterator(const wxRegion& region)
311{
312 m_rects = NULL;
313
409c9842 314 Reset(region);
0e320a79
DW
315}
316
317/*!
318 * Reset iterator for a new /e region.
319 */
320void wxRegionIterator::Reset(const wxRegion& region)
321{
409c9842
DW
322 m_current = 0;
323 m_region = region;
0e320a79
DW
324
325 if (m_rects)
326 delete[] m_rects;
327
328 m_rects = NULL;
329
409c9842
DW
330 if (m_region.Empty())
331 m_numRects = 0;
332 else
0e320a79
DW
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 */
343void wxRegionIterator::operator ++ ()
344{
409c9842
DW
345 if (m_current < m_numRects)
346 ++m_current;
0e320a79
DW
347}
348
349/*!
350 * Increment iterator. The rectangle returned is the one before the
351 * incrementation.
352 */
353void wxRegionIterator::operator ++ (int)
354{
409c9842
DW
355 if (m_current < m_numRects)
356 ++m_current;
0e320a79
DW
357}
358
0b7e7739 359wxCoord wxRegionIterator::GetX() const
0e320a79 360{
409c9842
DW
361 if (m_current < m_numRects)
362 return m_rects[m_current].x;
363 return 0;
0e320a79
DW
364}
365
0b7e7739 366wxCoord wxRegionIterator::GetY() const
0e320a79 367{
409c9842
DW
368 if (m_current < m_numRects)
369 return m_rects[m_current].y;
370 return 0;
0e320a79
DW
371}
372
0b7e7739 373wxCoord wxRegionIterator::GetW() const
0e320a79 374{
409c9842
DW
375 if (m_current < m_numRects)
376 return m_rects[m_current].width ;
377 return 0;
0e320a79
DW
378}
379
0b7e7739 380wxCoord wxRegionIterator::GetH() const
0e320a79 381{
409c9842
DW
382 if (m_current < m_numRects)
383 return m_rects[m_current].height;
384 return 0;
0e320a79
DW
385}
386