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 #if !USE_SHARED_LIBRARY
27 IMPLEMENT_DYNAMIC_CLASS(wxRegion
, wxGDIObject
)
28 IMPLEMENT_DYNAMIC_CLASS(wxRegionIterator
, wxObject
)
31 //-----------------------------------------------------------------------------
32 // wxRegionRefData implementation
33 //-----------------------------------------------------------------------------
35 class WXDLLEXPORT wxRegionRefData
: public wxGDIRefData
{
41 wxRegionRefData(const wxRegionRefData
& data
)
55 //-----------------------------------------------------------------------------
57 //-----------------------------------------------------------------------------
60 * Create an empty region.
64 m_refData
= new wxRegionRefData
;
65 // TODO create empty region
68 wxRegion::wxRegion(long x
, long y
, long w
, long h
)
70 m_refData
= new wxRegionRefData
;
71 // TODO create rect region
74 wxRegion::wxRegion(const wxPoint
& topLeft
, const wxPoint
& bottomRight
)
76 m_refData
= new wxRegionRefData
;
77 // TODO create rect region
80 wxRegion::wxRegion(const wxRect
& rect
)
82 m_refData
= new wxRegionRefData
;
83 // TODO create rect region
91 // m_refData unrefed in ~wxObject
94 //-----------------------------------------------------------------------------
96 //-----------------------------------------------------------------------------
98 //! Clear current region
99 void wxRegion::Clear()
104 //! Combine rectangle (x, y, w, h) with this.
105 bool wxRegion::Combine(long x
, long y
, long width
, long height
, wxRegionOp op
)
107 // Don't change shared data
109 m_refData
= new wxRegionRefData();
110 } else if (m_refData
->GetRefCount() > 1) {
111 wxRegionRefData
* ref
= (wxRegionRefData
*)m_refData
;
113 m_refData
= new wxRegionRefData(*ref
);
115 // If ref count is 1, that means it's 'ours' anyway so no action.
117 // TODO create rect region
119 int mode
= 0; // TODO platform-specific code
140 // TODO do combine region
145 //! Union /e region with this.
146 bool wxRegion::Combine(const wxRegion
& region
, wxRegionOp op
)
151 // Don't change shared data
153 m_refData
= new wxRegionRefData();
154 } else if (m_refData
->GetRefCount() > 1) {
155 wxRegionRefData
* ref
= (wxRegionRefData
*)m_refData
;
157 m_refData
= new wxRegionRefData(*ref
);
160 int mode
= 0; // TODO platform-specific code
181 // TODO combine region
186 bool wxRegion::Combine(const wxRect
& rect
, wxRegionOp op
)
188 return Combine(rect
.GetLeft(), rect
.GetTop(), rect
.GetWidth(), rect
.GetHeight(), op
);
191 //-----------------------------------------------------------------------------
192 //# Information on region
193 //-----------------------------------------------------------------------------
195 // Outer bounds of region
196 void wxRegion::GetBox(long& x
, long& y
, long&w
, long &h
) const
205 wxRect
wxRegion::GetBox() const
209 return wxRect(x
, y
, w
, h
);
213 bool wxRegion::Empty() const
219 //-----------------------------------------------------------------------------
221 //-----------------------------------------------------------------------------
223 // Does the region contain the point (x,y)?
224 wxRegionContain
wxRegion::Contains(long x
, long y
) const
229 // TODO. Return wxInRegion if within region.
235 // Does the region contain the point pt?
236 wxRegionContain
wxRegion::Contains(const wxPoint
& pt
) const
241 // TODO. Return wxInRegion if within region.
248 // Does the region contain the rectangle (x, y, w, h)?
249 wxRegionContain
wxRegion::Contains(long x
, long y
, long w
, long h
) const
254 // TODO. Return wxInRegion if within region.
261 // Does the region contain the rectangle rect
262 wxRegionContain
wxRegion::Contains(const wxRect
& rect
) const
271 h
= rect
.GetHeight();
272 return Contains(x
, y
, w
, h
);
275 ///////////////////////////////////////////////////////////////////////////////
277 // wxRegionIterator //
279 ///////////////////////////////////////////////////////////////////////////////
282 * Initialize empty iterator
284 wxRegionIterator::wxRegionIterator() : m_current(0), m_numRects(0), m_rects(NULL
)
288 wxRegionIterator::~wxRegionIterator()
295 * Initialize iterator for region
297 wxRegionIterator::wxRegionIterator(const wxRegion
& region
)
305 * Reset iterator for a new /e region.
307 void wxRegionIterator::Reset(const wxRegion
& region
)
317 if (m_region
.Empty())
321 // TODO create m_rects and fill with rectangles for this region
327 * Increment iterator. The rectangle returned is the one after the
330 void wxRegionIterator::operator ++ ()
332 if (m_current
< m_numRects
)
337 * Increment iterator. The rectangle returned is the one before the
340 void wxRegionIterator::operator ++ (int)
342 if (m_current
< m_numRects
)
346 long wxRegionIterator::GetX() const
348 if (m_current
< m_numRects
)
349 return m_rects
[m_current
].x
;
353 long wxRegionIterator::GetY() const
355 if (m_current
< m_numRects
)
356 return m_rects
[m_current
].y
;
360 long wxRegionIterator::GetW() const
362 if (m_current
< m_numRects
)
363 return m_rects
[m_current
].width
;
367 long wxRegionIterator::GetH() const
369 if (m_current
< m_numRects
)
370 return m_rects
[m_current
].height
;