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