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/region.h"
16 #include "wx/gdicmn.h"
18 IMPLEMENT_DYNAMIC_CLASS(wxRegion
, wxGDIObject
)
19 IMPLEMENT_DYNAMIC_CLASS(wxRegionIterator
, wxObject
)
21 //-----------------------------------------------------------------------------
22 // wxRegionRefData implementation
23 //-----------------------------------------------------------------------------
25 class WXDLLEXPORT wxRegionRefData
: public wxGDIRefData
{
31 wxRegionRefData(const wxRegionRefData
& data
)
43 //-----------------------------------------------------------------------------
45 //-----------------------------------------------------------------------------
48 * Create an empty region.
52 m_refData
= new wxRegionRefData
;
53 // TODO create empty region
56 wxRegion::wxRegion(long x
, long y
, long w
, long h
)
58 m_refData
= new wxRegionRefData
;
59 // TODO create rect region
62 wxRegion::wxRegion(const wxPoint
& topLeft
, const wxPoint
& bottomRight
)
64 m_refData
= new wxRegionRefData
;
65 // TODO create rect region
68 wxRegion::wxRegion(const wxRect
& rect
)
70 m_refData
= new wxRegionRefData
;
71 // TODO create rect region
79 // m_refData unrefed in ~wxObject
82 //-----------------------------------------------------------------------------
84 //-----------------------------------------------------------------------------
86 //! Clear current region
87 void wxRegion::Clear()
92 //! Combine rectangle (x, y, w, h) with this.
93 bool wxRegion::Combine(long x
, long y
, long width
, long height
, wxRegionOp op
)
95 // Don't change shared data
97 m_refData
= new wxRegionRefData();
98 } else if (m_refData
->GetRefCount() > 1) {
99 wxRegionRefData
* ref
= (wxRegionRefData
*)m_refData
;
101 m_refData
= new wxRegionRefData(*ref
);
103 // If ref count is 1, that means it's 'ours' anyway so no action.
105 // TODO create rect region
107 int mode
= 0; // TODO platform-specific code
128 // TODO do combine region
133 //! Union /e region with this.
134 bool wxRegion::Combine(const wxRegion
& region
, wxRegionOp op
)
139 // Don't change shared data
141 m_refData
= new wxRegionRefData();
142 } else if (m_refData
->GetRefCount() > 1) {
143 wxRegionRefData
* ref
= (wxRegionRefData
*)m_refData
;
145 m_refData
= new wxRegionRefData(*ref
);
148 int mode
= 0; // TODO platform-specific code
169 // TODO combine region
174 bool wxRegion::Combine(const wxRect
& rect
, wxRegionOp op
)
176 return Combine(rect
.GetLeft(), rect
.GetTop(), rect
.GetWidth(), rect
.GetHeight(), op
);
179 //-----------------------------------------------------------------------------
180 //# Information on region
181 //-----------------------------------------------------------------------------
183 // Outer bounds of region
184 void wxRegion::GetBox(long& x
, long& y
, long&w
, long &h
) const
193 wxRect
wxRegion::GetBox() const
197 return wxRect(x
, y
, w
, h
);
201 bool wxRegion::Empty() const
207 //-----------------------------------------------------------------------------
209 //-----------------------------------------------------------------------------
211 // Does the region contain the point (x,y)?
212 wxRegionContain
wxRegion::Contains(long x
, long y
) const
217 // TODO. Return wxInRegion if within region.
223 // Does the region contain the point pt?
224 wxRegionContain
wxRegion::Contains(const wxPoint
& pt
) const
229 // TODO. Return wxInRegion if within region.
236 // Does the region contain the rectangle (x, y, w, h)?
237 wxRegionContain
wxRegion::Contains(long x
, long y
, long w
, long h
) const
242 // TODO. Return wxInRegion if within region.
249 // Does the region contain the rectangle rect
250 wxRegionContain
wxRegion::Contains(const wxRect
& rect
) const
259 h
= rect
.GetHeight();
260 return Contains(x
, y
, w
, h
);
263 ///////////////////////////////////////////////////////////////////////////////
265 // wxRegionIterator //
267 ///////////////////////////////////////////////////////////////////////////////
270 * Initialize empty iterator
272 wxRegionIterator::wxRegionIterator() : m_current(0), m_numRects(0), m_rects(NULL
)
276 wxRegionIterator::~wxRegionIterator()
283 * Initialize iterator for region
285 wxRegionIterator::wxRegionIterator(const wxRegion
& region
)
293 * Reset iterator for a new /e region.
295 void wxRegionIterator::Reset(const wxRegion
& region
)
305 if (m_region
.Empty())
309 // TODO create m_rects and fill with rectangles for this region
315 * Increment iterator. The rectangle returned is the one after the
318 void wxRegionIterator::operator ++ ()
320 if (m_current
< m_numRects
)
325 * Increment iterator. The rectangle returned is the one before the
328 void wxRegionIterator::operator ++ (int)
330 if (m_current
< m_numRects
)
334 long wxRegionIterator::GetX() const
336 if (m_current
< m_numRects
)
337 return m_rects
[m_current
].x
;
341 long wxRegionIterator::GetY() const
343 if (m_current
< m_numRects
)
344 return m_rects
[m_current
].y
;
348 long wxRegionIterator::GetW() const
350 if (m_current
< m_numRects
)
351 return m_rects
[m_current
].width
;
355 long wxRegionIterator::GetH() const
357 if (m_current
< m_numRects
)
358 return m_rects
[m_current
].height
;