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 #if !USE_SHARED_LIBRARY
19 IMPLEMENT_DYNAMIC_CLASS(wxRegion
, wxGDIObject
)
20 IMPLEMENT_DYNAMIC_CLASS(wxRegionIterator
, wxObject
)
23 //-----------------------------------------------------------------------------
24 // wxRegionRefData implementation
25 //-----------------------------------------------------------------------------
27 class WXDLLEXPORT wxRegionRefData
: public wxGDIRefData
{
33 wxRegionRefData(const wxRegionRefData
& data
)
45 //-----------------------------------------------------------------------------
47 //-----------------------------------------------------------------------------
50 * Create an empty region.
54 m_refData
= new wxRegionRefData
;
55 // TODO create empty region
58 wxRegion::wxRegion(long x
, long y
, long w
, long h
)
60 m_refData
= new wxRegionRefData
;
61 // TODO create rect region
64 wxRegion::wxRegion(const wxPoint
& topLeft
, const wxPoint
& bottomRight
)
66 m_refData
= new wxRegionRefData
;
67 // TODO create rect region
70 wxRegion::wxRegion(const wxRect
& rect
)
72 m_refData
= new wxRegionRefData
;
73 // TODO create rect region
81 // m_refData unrefed in ~wxObject
84 //-----------------------------------------------------------------------------
86 //-----------------------------------------------------------------------------
88 //! Clear current region
89 void wxRegion::Clear()
94 //! Combine rectangle (x, y, w, h) with this.
95 bool wxRegion::Combine(long x
, long y
, long width
, long height
, wxRegionOp op
)
97 // Don't change shared data
99 m_refData
= new wxRegionRefData();
100 } else if (m_refData
->GetRefCount() > 1) {
101 wxRegionRefData
* ref
= (wxRegionRefData
*)m_refData
;
103 m_refData
= new wxRegionRefData(*ref
);
105 // If ref count is 1, that means it's 'ours' anyway so no action.
107 // TODO create rect region
109 int mode
= 0; // TODO platform-specific code
130 // TODO do combine region
135 //! Union /e region with this.
136 bool wxRegion::Combine(const wxRegion
& region
, wxRegionOp op
)
141 // Don't change shared data
143 m_refData
= new wxRegionRefData();
144 } else if (m_refData
->GetRefCount() > 1) {
145 wxRegionRefData
* ref
= (wxRegionRefData
*)m_refData
;
147 m_refData
= new wxRegionRefData(*ref
);
150 int mode
= 0; // TODO platform-specific code
171 // TODO combine region
176 bool wxRegion::Combine(const wxRect
& rect
, wxRegionOp op
)
178 return Combine(rect
.GetLeft(), rect
.GetTop(), rect
.GetWidth(), rect
.GetHeight(), op
);
181 //-----------------------------------------------------------------------------
182 //# Information on region
183 //-----------------------------------------------------------------------------
185 // Outer bounds of region
186 void wxRegion::GetBox(long& x
, long& y
, long&w
, long &h
) const
195 wxRect
wxRegion::GetBox() const
199 return wxRect(x
, y
, w
, h
);
203 bool wxRegion::Empty() const
209 //-----------------------------------------------------------------------------
211 //-----------------------------------------------------------------------------
213 // Does the region contain the point (x,y)?
214 wxRegionContain
wxRegion::Contains(long x
, long y
) const
219 // TODO. Return wxInRegion if within region.
225 // Does the region contain the point pt?
226 wxRegionContain
wxRegion::Contains(const wxPoint
& pt
) const
231 // TODO. Return wxInRegion if within region.
238 // Does the region contain the rectangle (x, y, w, h)?
239 wxRegionContain
wxRegion::Contains(long x
, long y
, long w
, long h
) const
244 // TODO. Return wxInRegion if within region.
251 // Does the region contain the rectangle rect
252 wxRegionContain
wxRegion::Contains(const wxRect
& rect
) const
261 h
= rect
.GetHeight();
262 return Contains(x
, y
, w
, h
);
265 ///////////////////////////////////////////////////////////////////////////////
267 // wxRegionIterator //
269 ///////////////////////////////////////////////////////////////////////////////
272 * Initialize empty iterator
274 wxRegionIterator::wxRegionIterator() : m_current(0), m_numRects(0), m_rects(NULL
)
278 wxRegionIterator::~wxRegionIterator()
285 * Initialize iterator for region
287 wxRegionIterator::wxRegionIterator(const wxRegion
& region
)
295 * Reset iterator for a new /e region.
297 void wxRegionIterator::Reset(const wxRegion
& region
)
307 if (m_region
.Empty())
311 // TODO create m_rects and fill with rectangles for this region
317 * Increment iterator. The rectangle returned is the one after the
320 void wxRegionIterator::operator ++ ()
322 if (m_current
< m_numRects
)
327 * Increment iterator. The rectangle returned is the one before the
330 void wxRegionIterator::operator ++ (int)
332 if (m_current
< m_numRects
)
336 long wxRegionIterator::GetX() const
338 if (m_current
< m_numRects
)
339 return m_rects
[m_current
].x
;
343 long wxRegionIterator::GetY() const
345 if (m_current
< m_numRects
)
346 return m_rects
[m_current
].y
;
350 long wxRegionIterator::GetW() const
352 if (m_current
< m_numRects
)
353 return m_rects
[m_current
].width
;
357 long wxRegionIterator::GetH() const
359 if (m_current
< m_numRects
)
360 return m_rects
[m_current
].height
;