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