]> git.saurik.com Git - wxWidgets.git/blame - src/qt/region.cpp
wxUpdateUIEvent derives from wxCommandEvent now
[wxWidgets.git] / src / qt / region.cpp
CommitLineData
7c78e7c7 1/////////////////////////////////////////////////////////////////////////////
01b2eeec
KB
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
7c78e7c7
RR
9/////////////////////////////////////////////////////////////////////////////
10
7c78e7c7
RR
11#ifdef __GNUG__
12#pragma implementation "region.h"
13#endif
14
01b2eeec
KB
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
7c78e7c7
RR
30
31//-----------------------------------------------------------------------------
01b2eeec 32// wxRegionRefData implementation
7c78e7c7
RR
33//-----------------------------------------------------------------------------
34
01b2eeec
KB
35class WXDLLEXPORT wxRegionRefData : public wxGDIRefData {
36public:
37 wxRegionRefData()
38 {
39 }
7c78e7c7 40
01b2eeec
KB
41 wxRegionRefData(const wxRegionRefData& data)
42 {
43 // TODO
44 }
7c78e7c7 45
01b2eeec
KB
46 ~wxRegionRefData()
47 {
48 // TODO
49 }
7c78e7c7 50
01b2eeec 51 HRGN m_region;
7c78e7c7
RR
52};
53
7c78e7c7 54
01b2eeec
KB
55//-----------------------------------------------------------------------------
56// wxRegion
57//-----------------------------------------------------------------------------
7c78e7c7 58
01b2eeec
KB
59/*!
60 * Create an empty region.
61 */
62wxRegion::wxRegion()
7c78e7c7 63{
01b2eeec
KB
64 m_refData = new wxRegionRefData;
65 // TODO create empty region
66}
7c78e7c7 67
01b2eeec 68wxRegion::wxRegion(long x, long y, long w, long h)
7c78e7c7 69{
01b2eeec
KB
70 m_refData = new wxRegionRefData;
71 // TODO create rect region
72}
7c78e7c7 73
01b2eeec 74wxRegion::wxRegion(const wxPoint& topLeft, const wxPoint& bottomRight)
7c78e7c7 75{
01b2eeec
KB
76 m_refData = new wxRegionRefData;
77 // TODO create rect region
78}
7c78e7c7 79
01b2eeec 80wxRegion::wxRegion(const wxRect& rect)
7c78e7c7 81{
01b2eeec
KB
82 m_refData = new wxRegionRefData;
83 // TODO create rect region
84}
85
86/*!
87 * Destroy the region.
88 */
89wxRegion::~wxRegion()
7c78e7c7 90{
01b2eeec
KB
91 // m_refData unrefed in ~wxObject
92}
7c78e7c7 93
01b2eeec
KB
94//-----------------------------------------------------------------------------
95//# Modify region
96//-----------------------------------------------------------------------------
7c78e7c7 97
01b2eeec
KB
98//! Clear current region
99void wxRegion::Clear()
7c78e7c7 100{
01b2eeec
KB
101 UnRef();
102}
7c78e7c7 103
01b2eeec
KB
104//! Combine rectangle (x, y, w, h) with this.
105bool wxRegion::Combine(long x, long y, long width, long height, wxRegionOp op)
7c78e7c7 106{
01b2eeec
KB
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.
146bool wxRegion::Combine(const wxRegion& region, wxRegionOp op)
7c78e7c7 147{
01b2eeec
KB
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
186bool wxRegion::Combine(const wxRect& rect, wxRegionOp op)
7c78e7c7 187{
01b2eeec
KB
188 return Combine(rect.GetLeft(), rect.GetTop(), rect.GetWidth(), rect.GetHeight(), op);
189}
7c78e7c7 190
01b2eeec
KB
191//-----------------------------------------------------------------------------
192//# Information on region
193//-----------------------------------------------------------------------------
7c78e7c7 194
01b2eeec
KB
195// Outer bounds of region
196void wxRegion::GetBox(long& x, long& y, long&w, long &h) const
7c78e7c7 197{
01b2eeec
KB
198 if (m_refData) {
199 // TODO get box
200 } else {
201 x = y = w = h = 0;
202 }
203}
204
205wxRect wxRegion::GetBox() const
7c78e7c7 206{
01b2eeec
KB
207 long x, y, w, h;
208 GetBox(x, y, w, h);
209 return wxRect(x, y, w, h);
210}
7c78e7c7 211
01b2eeec
KB
212// Is region empty?
213bool wxRegion::Empty() const
7c78e7c7 214{
01b2eeec
KB
215 // TODO
216 return FALSE;
217}
7c78e7c7 218
01b2eeec
KB
219//-----------------------------------------------------------------------------
220//# Tests
221//-----------------------------------------------------------------------------
7c78e7c7 222
01b2eeec
KB
223// Does the region contain the point (x,y)?
224wxRegionContain wxRegion::Contains(long x, long y) const
7c78e7c7 225{
01b2eeec
KB
226 if (!m_refData)
227 return wxOutRegion;
7c78e7c7 228
01b2eeec
KB
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?
236wxRegionContain wxRegion::Contains(const wxPoint& pt) const
7c78e7c7 237{
01b2eeec
KB
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)?
249wxRegionContain 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
262wxRegionContain 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 */
284wxRegionIterator::wxRegionIterator() : m_current(0), m_numRects(0), m_rects(NULL)
285{
286}
7c78e7c7 287
01b2eeec 288wxRegionIterator::~wxRegionIterator()
7c78e7c7 289{
01b2eeec
KB
290 if (m_rects)
291 delete[] m_rects;
292}
293
294/*!
295 * Initialize iterator for region
296 */
297wxRegionIterator::wxRegionIterator(const wxRegion& region)
298{
299 m_rects = NULL;
300
301 Reset(region);
302}
7c78e7c7 303
01b2eeec
KB
304/*!
305 * Reset iterator for a new /e region.
306 */
307void wxRegionIterator::Reset(const wxRegion& region)
7c78e7c7 308{
01b2eeec
KB
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 */
330void 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 */
340void wxRegionIterator::operator ++ (int)
341{
342 if (m_current < m_numRects)
343 ++m_current;
344}
7c78e7c7 345
01b2eeec 346long wxRegionIterator::GetX() const
7c78e7c7 347{
01b2eeec
KB
348 if (m_current < m_numRects)
349 return m_rects[m_current].x;
350 return 0;
351}
7c78e7c7 352
01b2eeec 353long wxRegionIterator::GetY() const
7c78e7c7 354{
01b2eeec
KB
355 if (m_current < m_numRects)
356 return m_rects[m_current].y;
357 return 0;
358}
7c78e7c7 359
01b2eeec 360long wxRegionIterator::GetW() const
7c78e7c7 361{
01b2eeec
KB
362 if (m_current < m_numRects)
363 return m_rects[m_current].width ;
364 return 0;
365}
7c78e7c7 366
01b2eeec 367long wxRegionIterator::GetH() const
7c78e7c7 368{
01b2eeec
KB
369 if (m_current < m_numRects)
370 return m_rects[m_current].height;
371 return 0;
372}
7c78e7c7 373