1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Region class
4 // Author: Markus Holzem/Julian Smart/AUTHOR
5 // Created: Fri Oct 24 10:46:34 MET 1997
7 // Copyright: (c) 1997 Markus Holzem/Julian Smart/AUTHOR
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
12 #pragma implementation "region.h"
15 #include "wx/wxprec.h"
21 #include "wx/msw/region.h"
22 #include "wx/gdicmn.h"
26 IMPLEMENT_DYNAMIC_CLASS(wxRegion
, wxGDIObject
)
27 IMPLEMENT_DYNAMIC_CLASS(wxRegionIterator
, wxObject
)
29 //-----------------------------------------------------------------------------
30 // wxRegionRefData implementation
31 //-----------------------------------------------------------------------------
33 class WXDLLEXPORT wxRegionRefData
: public wxGDIRefData
{
39 wxRegionRefData(const wxRegionRefData
& data
)
53 //-----------------------------------------------------------------------------
55 //-----------------------------------------------------------------------------
58 * Create an empty region.
62 m_refData
= new wxRegionRefData
;
63 // TODO create empty region
66 wxRegion::wxRegion(long x
, long y
, long w
, long h
)
68 m_refData
= new wxRegionRefData
;
69 // TODO create rect region
72 wxRegion::wxRegion(const wxPoint
& topLeft
, const wxPoint
& bottomRight
)
74 m_refData
= new wxRegionRefData
;
75 // TODO create rect region
78 wxRegion::wxRegion(const wxRect
& rect
)
80 m_refData
= new wxRegionRefData
;
81 // TODO create rect region
89 // m_refData unrefed in ~wxObject
92 //-----------------------------------------------------------------------------
94 //-----------------------------------------------------------------------------
96 //! Clear current region
97 void wxRegion::Clear()
102 //! Combine rectangle (x, y, w, h) with this.
103 bool wxRegion::Combine(long x
, long y
, long width
, long height
, wxRegionOp op
)
105 // Don't change shared data
107 m_refData
= new wxRegionRefData();
108 } else if (m_refData
->GetRefCount() > 1) {
109 wxRegionRefData
* ref
= (wxRegionRefData
*)m_refData
;
111 m_refData
= new wxRegionRefData(*ref
);
113 // If ref count is 1, that means it's 'ours' anyway so no action.
115 // TODO create rect region
117 int mode
= 0; // TODO platform-specific code
138 // TODO do combine region
143 //! Union /e region with this.
144 bool wxRegion::Combine(const wxRegion
& region
, wxRegionOp op
)
149 // Don't change shared data
151 m_refData
= new wxRegionRefData();
152 } else if (m_refData
->GetRefCount() > 1) {
153 wxRegionRefData
* ref
= (wxRegionRefData
*)m_refData
;
155 m_refData
= new wxRegionRefData(*ref
);
158 int mode
= 0; // TODO platform-specific code
179 // TODO combine region
184 bool wxRegion::Combine(const wxRect
& rect
, wxRegionOp op
)
186 return Combine(rect
.GetLeft(), rect
.GetTop(), rect
.GetWidth(), rect
.GetHeight(), op
);
189 //-----------------------------------------------------------------------------
190 //# Information on region
191 //-----------------------------------------------------------------------------
193 // Outer bounds of region
194 void wxRegion::GetBox(long& x
, long& y
, long&w
, long &h
) const
203 wxRect
wxRegion::GetBox() const
207 return wxRect(x
, y
, w
, h
);
211 bool wxRegion::Empty() const
217 //-----------------------------------------------------------------------------
219 //-----------------------------------------------------------------------------
221 // Does the region contain the point (x,y)?
222 wxRegionContain
wxRegion::Contains(long x
, long y
) const
227 // TODO. Return wxInRegion if within region.
233 // Does the region contain the point pt?
234 wxRegionContain
wxRegion::Contains(const wxPoint
& pt
) const
239 // TODO. Return wxInRegion if within region.
246 // Does the region contain the rectangle (x, y, w, h)?
247 wxRegionContain
wxRegion::Contains(long x
, long y
, long w
, long h
) const
252 // TODO. Return wxInRegion if within region.
259 // Does the region contain the rectangle rect
260 wxRegionContain
wxRegion::Contains(const wxRect
& rect
) const
269 h
= rect
.GetHeight();
270 return Contains(x
, y
, w
, h
);
273 ///////////////////////////////////////////////////////////////////////////////
275 // wxRegionIterator //
277 ///////////////////////////////////////////////////////////////////////////////
280 * Initialize empty iterator
282 wxRegionIterator::wxRegionIterator() : m_current(0), m_numRects(0), m_rects(NULL
)
286 wxRegionIterator::~wxRegionIterator()
293 * Initialize iterator for region
295 wxRegionIterator::wxRegionIterator(const wxRegion
& region
)
303 * Reset iterator for a new /e region.
305 void wxRegionIterator::Reset(const wxRegion
& region
)
315 if (m_region
.Empty())
319 // TODO create m_rects and fill with rectangles for this region
325 * Increment iterator. The rectangle returned is the one after the
328 void wxRegionIterator::operator ++ ()
330 if (m_current
< m_numRects
)
335 * Increment iterator. The rectangle returned is the one before the
338 void wxRegionIterator::operator ++ (int)
340 if (m_current
< m_numRects
)
344 long wxRegionIterator::GetX() const
346 if (m_current
< m_numRects
)
347 return m_rects
[m_current
].x
;
351 long wxRegionIterator::GetY() const
353 if (m_current
< m_numRects
)
354 return m_rects
[m_current
].y
;
358 long wxRegionIterator::GetW() const
360 if (m_current
< m_numRects
)
361 return m_rects
[m_current
].width
;
365 long wxRegionIterator::GetH() const
367 if (m_current
< m_numRects
)
368 return m_rects
[m_current
].height
;