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         IMPLEMENT_DYNAMIC_CLASS(wxRegion
, wxGDIObject
) 
  22         IMPLEMENT_DYNAMIC_CLASS(wxRegionIterator
, wxObject
) 
  24 //----------------------------------------------------------------------------- 
  25 // wxRegionRefData implementation 
  26 //----------------------------------------------------------------------------- 
  28 class WXDLLEXPORT wxRegionRefData 
: public wxGDIRefData 
{ 
  35     wxRegionRefData(const wxRegionRefData
& data
) 
  49 #define M_REGION (((wxRegionRefData*)m_refData)->m_region) 
  51 //----------------------------------------------------------------------------- 
  53 //----------------------------------------------------------------------------- 
  56  * Create an empty region. 
  60     m_refData 
= new wxRegionRefData
; 
  61     // TODO create empty region 
  64 wxRegion::wxRegion(WXHRGN hRegion
) 
  66     m_refData 
= new wxRegionRefData
; 
  67     M_REGION 
= (HRGN
) hRegion
; 
  70 wxRegion::wxRegion(long x
, long y
, long w
, long h
) 
  72     m_refData 
= new wxRegionRefData
; 
  73     // TODO create rect region 
  76 wxRegion::wxRegion(const wxPoint
& topLeft
, const wxPoint
& bottomRight
) 
  78     m_refData 
= new wxRegionRefData
; 
  79     // TODO create rect region 
  82 wxRegion::wxRegion(const wxRect
& rect
) 
  84     m_refData 
= new wxRegionRefData
; 
  85     // TODO create rect region 
  93     // m_refData unrefed in ~wxObject 
  96 //----------------------------------------------------------------------------- 
  98 //----------------------------------------------------------------------------- 
 100 //! Clear current region 
 101 void wxRegion::Clear() 
 106 //! Combine rectangle (x, y, w, h) with this. 
 107 bool wxRegion::Combine(long x
, long y
, long width
, long height
, wxRegionOp op
) 
 109     // Don't change shared data 
 111         m_refData 
= new wxRegionRefData(); 
 112     } else if (m_refData
->GetRefCount() > 1) { 
 113         wxRegionRefData
* ref 
= (wxRegionRefData
*)m_refData
; 
 115         m_refData 
= new wxRegionRefData(*ref
); 
 117     // If ref count is 1, that means it's 'ours' anyway so no action. 
 119     // TODO create rect region 
 121     int mode 
= 0; // TODO platform-specific code 
 142     // TODO do combine region 
 147 //! Union /e region with this. 
 148 bool wxRegion::Combine(const wxRegion
& region
, wxRegionOp op
) 
 153     // Don't change shared data 
 155         m_refData 
= new wxRegionRefData(); 
 156     } else  if (m_refData
->GetRefCount() > 1) { 
 157         wxRegionRefData
* ref 
= (wxRegionRefData
*)m_refData
; 
 159         m_refData 
= new wxRegionRefData(*ref
); 
 162     int mode 
= 0; // TODO platform-specific code 
 183     // TODO combine region 
 188 bool wxRegion::Combine(const wxRect
& rect
, wxRegionOp op
) 
 190     return Combine(rect
.GetLeft(), rect
.GetTop(), rect
.GetWidth(), rect
.GetHeight(), op
); 
 193 //----------------------------------------------------------------------------- 
 194 //# Information on region 
 195 //----------------------------------------------------------------------------- 
 197 // Outer bounds of region 
 198 void wxRegion::GetBox(long& x
, long& y
, long&w
, long &h
) const 
 207 wxRect 
wxRegion::GetBox() const 
 211     return wxRect(x
, y
, w
, h
); 
 215 bool wxRegion::Empty() const 
 221 //----------------------------------------------------------------------------- 
 223 //----------------------------------------------------------------------------- 
 225 // Does the region contain the point (x,y)? 
 226 wxRegionContain 
wxRegion::Contains(long x
, long y
) const 
 228     bool    bOK 
= FALSE
; // temporary 
 232     // TODO. Return wxInRegion if within region. 
 238 // Does the region contain the point pt? 
 239 wxRegionContain 
wxRegion::Contains(const wxPoint
& pt
) const 
 241     bool    bOK 
= FALSE
; // temporary 
 245     // TODO. Return wxInRegion if within region. 
 252 // Does the region contain the rectangle (x, y, w, h)? 
 253 wxRegionContain 
wxRegion::Contains(long x
, long y
, long w
, long h
) const 
 255     bool    bOK 
= FALSE
; // temporary 
 259     // TODO. Return wxInRegion if within region. 
 266 // Does the region contain the rectangle rect 
 267 wxRegionContain 
wxRegion::Contains(const wxRect
& rect
) const 
 276     h 
= rect
.GetHeight(); 
 277     return Contains(x
, y
, w
, h
); 
 280 // Get internal region handle 
 281 WXHRGN 
wxRegion::GetHRGN() const 
 285     return (WXHRGN
) M_REGION
; 
 288 /////////////////////////////////////////////////////////////////////////////// 
 290 //                             wxRegionIterator                              // 
 292 /////////////////////////////////////////////////////////////////////////////// 
 295  * Initialize empty iterator 
 297 wxRegionIterator::wxRegionIterator() : m_current(0), m_numRects(0), m_rects(NULL
) 
 301 wxRegionIterator::~wxRegionIterator() 
 308  * Initialize iterator for region 
 310 wxRegionIterator::wxRegionIterator(const wxRegion
& region
) 
 318  * Reset iterator for a new /e region. 
 320 void wxRegionIterator::Reset(const wxRegion
& region
) 
 330     if (m_region
.Empty()) 
 334         // TODO create m_rects and fill with rectangles for this region 
 340  * Increment iterator. The rectangle returned is the one after the 
 343 void wxRegionIterator::operator ++ () 
 345     if (m_current 
< m_numRects
) 
 350  * Increment iterator. The rectangle returned is the one before the 
 353 void wxRegionIterator::operator ++ (int) 
 355     if (m_current 
< m_numRects
) 
 359 long wxRegionIterator::GetX() const 
 361     if (m_current 
< m_numRects
) 
 362         return m_rects
[m_current
].x
; 
 366 long wxRegionIterator::GetY() const 
 368     if (m_current 
< m_numRects
) 
 369         return m_rects
[m_current
].y
; 
 373 long wxRegionIterator::GetW() const 
 375     if (m_current 
< m_numRects
) 
 376         return m_rects
[m_current
].width 
; 
 380 long wxRegionIterator::GetH() const 
 382     if (m_current 
< m_numRects
) 
 383         return m_rects
[m_current
].height
;