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
)
51 #define M_REGION (((wxRegionRefData*)m_refData)->m_region)
53 //-----------------------------------------------------------------------------
55 //-----------------------------------------------------------------------------
58 * Create an empty region.
62 m_refData
= new wxRegionRefData
;
63 // TODO create empty region
66 wxRegion::wxRegion(WXHRGN hRegion
)
68 m_refData
= new wxRegionRefData
;
69 M_REGION
= (HRGN
) hRegion
;
72 wxRegion::wxRegion(long x
, long y
, long w
, long h
)
74 m_refData
= new wxRegionRefData
;
75 // TODO create rect region
78 wxRegion::wxRegion(const wxPoint
& topLeft
, const wxPoint
& bottomRight
)
80 m_refData
= new wxRegionRefData
;
81 // TODO create rect region
84 wxRegion::wxRegion(const wxRect
& rect
)
86 m_refData
= new wxRegionRefData
;
87 // TODO create rect region
95 // m_refData unrefed in ~wxObject
98 //-----------------------------------------------------------------------------
100 //-----------------------------------------------------------------------------
102 //! Clear current region
103 void wxRegion::Clear()
108 //! Combine rectangle (x, y, w, h) with this.
109 bool wxRegion::Combine(long x
, long y
, long width
, long height
, wxRegionOp op
)
111 // Don't change shared data
113 m_refData
= new wxRegionRefData();
114 } else if (m_refData
->GetRefCount() > 1) {
115 wxRegionRefData
* ref
= (wxRegionRefData
*)m_refData
;
117 m_refData
= new wxRegionRefData(*ref
);
119 // If ref count is 1, that means it's 'ours' anyway so no action.
121 // TODO create rect region
123 int mode
= 0; // TODO platform-specific code
144 // TODO do combine region
149 //! Union /e region with this.
150 bool wxRegion::Combine(const wxRegion
& region
, wxRegionOp op
)
155 // Don't change shared data
157 m_refData
= new wxRegionRefData();
158 } else if (m_refData
->GetRefCount() > 1) {
159 wxRegionRefData
* ref
= (wxRegionRefData
*)m_refData
;
161 m_refData
= new wxRegionRefData(*ref
);
164 int mode
= 0; // TODO platform-specific code
185 // TODO combine region
190 bool wxRegion::Combine(const wxRect
& rect
, wxRegionOp op
)
192 return Combine(rect
.GetLeft(), rect
.GetTop(), rect
.GetWidth(), rect
.GetHeight(), op
);
195 //-----------------------------------------------------------------------------
196 //# Information on region
197 //-----------------------------------------------------------------------------
199 // Outer bounds of region
200 void wxRegion::GetBox(long& x
, long& y
, long&w
, long &h
) const
209 wxRect
wxRegion::GetBox() const
213 return wxRect(x
, y
, w
, h
);
217 bool wxRegion::Empty() const
223 //-----------------------------------------------------------------------------
225 //-----------------------------------------------------------------------------
227 // Does the region contain the point (x,y)?
228 wxRegionContain
wxRegion::Contains(long x
, long y
) const
230 bool bOK
= FALSE
; // temporary
234 // TODO. Return wxInRegion if within region.
240 // Does the region contain the point pt?
241 wxRegionContain
wxRegion::Contains(const wxPoint
& pt
) const
243 bool bOK
= FALSE
; // temporary
247 // TODO. Return wxInRegion if within region.
254 // Does the region contain the rectangle (x, y, w, h)?
255 wxRegionContain
wxRegion::Contains(long x
, long y
, long w
, long h
) const
257 bool bOK
= FALSE
; // temporary
261 // TODO. Return wxInRegion if within region.
268 // Does the region contain the rectangle rect
269 wxRegionContain
wxRegion::Contains(const wxRect
& rect
) const
278 h
= rect
.GetHeight();
279 return Contains(x
, y
, w
, h
);
282 // Get internal region handle
283 WXHRGN
wxRegion::GetHRGN() const
287 return (WXHRGN
) M_REGION
;
290 ///////////////////////////////////////////////////////////////////////////////
292 // wxRegionIterator //
294 ///////////////////////////////////////////////////////////////////////////////
297 * Initialize empty iterator
299 wxRegionIterator::wxRegionIterator() : m_current(0), m_numRects(0), m_rects(NULL
)
303 wxRegionIterator::~wxRegionIterator()
310 * Initialize iterator for region
312 wxRegionIterator::wxRegionIterator(const wxRegion
& region
)
320 * Reset iterator for a new /e region.
322 void wxRegionIterator::Reset(const wxRegion
& region
)
332 if (m_region
.Empty())
336 // TODO create m_rects and fill with rectangles for this region
342 * Increment iterator. The rectangle returned is the one after the
345 void wxRegionIterator::operator ++ ()
347 if (m_current
< m_numRects
)
352 * Increment iterator. The rectangle returned is the one before the
355 void wxRegionIterator::operator ++ (int)
357 if (m_current
< m_numRects
)
361 long wxRegionIterator::GetX() const
363 if (m_current
< m_numRects
)
364 return m_rects
[m_current
].x
;
368 long wxRegionIterator::GetY() const
370 if (m_current
< m_numRects
)
371 return m_rects
[m_current
].y
;
375 long wxRegionIterator::GetW() const
377 if (m_current
< m_numRects
)
378 return m_rects
[m_current
].width
;
382 long wxRegionIterator::GetH() const
384 if (m_current
< m_numRects
)
385 return m_rects
[m_current
].height
;