1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Region class
4 // Author: David Webster
8 // Copyright: (c) Davdi Webster
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
15 #include "wx/os2/region.h"
16 #include "wx/gdicmn.h"
18 #include "wx/window.h"
19 #include "wx/os2/private.h"
21 #if !USE_SHARED_LIBRARY
22 IMPLEMENT_DYNAMIC_CLASS(wxRegion
, wxGDIObject
)
23 IMPLEMENT_DYNAMIC_CLASS(wxRegionIterator
, wxObject
)
26 //-----------------------------------------------------------------------------
27 // wxRegionRefData implementation
28 //-----------------------------------------------------------------------------
30 class WXDLLEXPORT wxRegionRefData
: public wxGDIRefData
{
37 wxRegionRefData(const wxRegionRefData
& data
)
50 //-----------------------------------------------------------------------------
52 //-----------------------------------------------------------------------------
55 * Create an empty region.
59 m_refData
= new wxRegionRefData
;
60 // TODO create empty region
63 wxRegion::wxRegion(WXHRGN hRegion
)
65 m_refData
= new wxRegionRefData
;
66 M_REGION
= (HRGN
) hRegion
;
69 wxRegion::wxRegion(long x
, long y
, long w
, long h
)
71 m_refData
= new wxRegionRefData
;
72 // TODO create rect region
75 wxRegion::wxRegion(const wxPoint
& topLeft
, const wxPoint
& bottomRight
)
77 m_refData
= new wxRegionRefData
;
78 // TODO create rect region
81 wxRegion::wxRegion(const wxRect
& rect
)
83 m_refData
= new wxRegionRefData
;
84 // TODO create rect region
92 // m_refData unrefed in ~wxObject
95 //-----------------------------------------------------------------------------
97 //-----------------------------------------------------------------------------
99 //! Clear current region
100 void wxRegion::Clear()
105 //! Combine rectangle (x, y, w, h) with this.
106 bool wxRegion::Combine(long x
, long y
, long width
, long height
, wxRegionOp op
)
108 // Don't change shared data
110 m_refData
= new wxRegionRefData();
111 } else if (m_refData
->GetRefCount() > 1) {
112 wxRegionRefData
* ref
= (wxRegionRefData
*)m_refData
;
114 m_refData
= new wxRegionRefData(*ref
);
116 // If ref count is 1, that means it's 'ours' anyway so no action.
118 // TODO create rect region
120 int mode
= 0; // TODO platform-specific code
141 // TODO do combine region
146 //! Union /e region with this.
147 bool wxRegion::Combine(const wxRegion
& region
, wxRegionOp op
)
152 // Don't change shared data
154 m_refData
= new wxRegionRefData();
155 } else if (m_refData
->GetRefCount() > 1) {
156 wxRegionRefData
* ref
= (wxRegionRefData
*)m_refData
;
158 m_refData
= new wxRegionRefData(*ref
);
161 int mode
= 0; // TODO platform-specific code
182 // TODO combine region
187 bool wxRegion::Combine(const wxRect
& rect
, wxRegionOp op
)
189 return Combine(rect
.GetLeft(), rect
.GetTop(), rect
.GetWidth(), rect
.GetHeight(), op
);
192 //-----------------------------------------------------------------------------
193 //# Information on region
194 //-----------------------------------------------------------------------------
196 // Outer bounds of region
197 void wxRegion::GetBox(long& x
, long& y
, long&w
, long &h
) const
206 wxRect
wxRegion::GetBox() const
210 return wxRect(x
, y
, w
, h
);
214 bool wxRegion::Empty() const
220 //-----------------------------------------------------------------------------
222 //-----------------------------------------------------------------------------
224 // Does the region contain the point (x,y)?
225 wxRegionContain
wxRegion::Contains(long x
, long y
) const
230 // TODO. Return wxInRegion if within region.
236 // Does the region contain the point pt?
237 wxRegionContain
wxRegion::Contains(const wxPoint
& pt
) const
242 // TODO. Return wxInRegion if within region.
249 // Does the region contain the rectangle (x, y, w, h)?
250 wxRegionContain
wxRegion::Contains(long x
, long y
, long w
, long h
) const
255 // TODO. Return wxInRegion if within region.
262 // Does the region contain the rectangle rect
263 wxRegionContain
wxRegion::Contains(const wxRect
& rect
) const
272 h
= rect
.GetHeight();
273 return Contains(x
, y
, w
, h
);
276 // Get internal region handle
277 WXHRGN
wxRegion::GetHRGN() const
281 return (WXHRGN
) M_REGION
;
284 ///////////////////////////////////////////////////////////////////////////////
286 // wxRegionIterator //
288 ///////////////////////////////////////////////////////////////////////////////
291 * Initialize empty iterator
293 wxRegionIterator::wxRegionIterator() : m_current(0), m_numRects(0), m_rects(NULL
)
297 wxRegionIterator::~wxRegionIterator()
304 * Initialize iterator for region
306 wxRegionIterator::wxRegionIterator(const wxRegion
& region
)
314 * Reset iterator for a new /e region.
316 void wxRegionIterator::Reset(const wxRegion
& region
)
326 if (m_region
.Empty())
330 // TODO create m_rects and fill with rectangles for this region
336 * Increment iterator. The rectangle returned is the one after the
339 void wxRegionIterator::operator ++ ()
341 if (m_current
< m_numRects
)
346 * Increment iterator. The rectangle returned is the one before the
349 void wxRegionIterator::operator ++ (int)
351 if (m_current
< m_numRects
)
355 long wxRegionIterator::GetX() const
357 if (m_current
< m_numRects
)
358 return m_rects
[m_current
].x
;
362 long wxRegionIterator::GetY() const
364 if (m_current
< m_numRects
)
365 return m_rects
[m_current
].y
;
369 long wxRegionIterator::GetW() const
371 if (m_current
< m_numRects
)
372 return m_rects
[m_current
].width
;
376 long wxRegionIterator::GetH() const
378 if (m_current
< m_numRects
)
379 return m_rects
[m_current
].height
;