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