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"
16 #include "wx/os2/region.h"
17 #include "wx/gdicmn.h"
19 #include "wx/window.h"
20 #include "wx/os2/private.h"
22 IMPLEMENT_DYNAMIC_CLASS(wxRegion
, wxGDIObject
)
23 IMPLEMENT_DYNAMIC_CLASS(wxRegionIterator
, wxObject
)
25 //-----------------------------------------------------------------------------
26 // wxRegionRefData implementation
27 //-----------------------------------------------------------------------------
29 class WXDLLEXPORT wxRegionRefData
: public wxGDIRefData
{
37 wxRegionRefData(const wxRegionRefData
& rData
)
42 vRgnData
.ulDirection
= RECTDIR_LFRT_TOPBOT
;
43 if (::GpiQueryRegionRects( rData
.m_hPS
// Pres space
44 ,rData
.m_hRegion
// Handle of region to query
45 ,NULL
// Return all RECTs
46 ,&vRgnData
// Will contain number or RECTs in region
47 ,NULL
// NULL to return number of RECTs
50 pRect
= new RECTL
[vRgnData
.crcReturned
];
51 vRgnData
.crc
= vRgnData
.crcReturned
;
52 vRgnData
.ircStart
= 1;
53 if (::GpiQueryRegionRects( rData
.m_hPS
// Pres space of source
54 ,rData
.m_hRegion
// Handle of source region
55 ,NULL
// Return all RECTs
56 ,&vRgnData
// Operations set to return rects
57 ,pRect
// Will contain the actual RECTS
60 m_hRegion
= ::GpiCreateRegion( rData
.m_hPS
72 ::GpiDestroyRegion(m_hPS
, m_hRegion
);
79 #define M_REGION (((wxRegionRefData*)m_refData)->m_hRegion)
80 #define M_REGION_OF(rgn) (((wxRegionRefData*)(rgn.m_refData))->m_hRegion)
82 //-----------------------------------------------------------------------------
84 //-----------------------------------------------------------------------------
87 * Create an empty region.
91 m_refData
= new wxRegionRefData
;
92 } // end of wxRegion::wxRegion
99 m_refData
= new wxRegionRefData
;
100 M_REGION
= (HRGN
) hRegion
;
101 (((wxRegionRefData
*)m_refData
)->m_hPS
) = hPS
;
102 } // end of wxRegion::wxRegion
112 SIZEL vSize
= {0, 0};
113 DEVOPENSTRUC vDop
= {0L, "DISPLAY", NULL
, 0L, 0L, 0L, 0L, 0L, 0L};
114 HDC hDC
= ::DevOpenDC( vHabmain
124 vRect
.xRight
= x
+ vWidth
;
126 vRect
.yTop
= y
+ vHeight
;
128 m_refData
= new wxRegionRefData
;
131 // Need a PS to create a Region
133 ((wxRegionRefData
*)m_refData
)->m_hPS
= ::GpiCreatePS( vHabmain
136 ,PU_PELS
| GPIT_MICRO
| GPIA_ASSOC
138 M_REGION
= ::GpiCreateRegion( ((wxRegionRefData
*)m_refData
)->m_hPS
142 } // end of wxRegion::wxRegion
145 const wxPoint
& rTopLeft
146 , const wxPoint
& rBottomRight
150 SIZEL vSize
= {0, 0};
151 DEVOPENSTRUC vDop
= {0L, "DISPLAY", NULL
, 0L, 0L, 0L, 0L, 0L, 0L};
152 HDC hDC
= ::DevOpenDC( vHabmain
160 vRect
.xLeft
= rTopLeft
.x
;
161 vRect
.xRight
= rBottomRight
.x
;
162 vRect
.yBottom
= rBottomRight
.y
;
163 vRect
.yTop
= rTopLeft
.y
;
165 m_refData
= new wxRegionRefData
;
168 // Need a PS to create a Region
170 ((wxRegionRefData
*)m_refData
)->m_hPS
= ::GpiCreatePS( vHabmain
173 ,PU_PELS
| GPIT_MICRO
| GPIA_ASSOC
175 M_REGION
= ::GpiCreateRegion( ((wxRegionRefData
*)m_refData
)->m_hPS
179 } // end of wxRegion::wxRegion
186 SIZEL vSize
= {0, 0};
187 DEVOPENSTRUC vDop
= {0L, "DISPLAY", NULL
, 0L, 0L, 0L, 0L, 0L, 0L};
188 HDC hDC
= ::DevOpenDC( vHabmain
197 vRect
.xLeft
= rRect
.x
;
198 vRect
.xRight
= rRect
.x
+ rRect
.width
;
199 vRect
.yBottom
= rRect
.y
;
200 vRect
.yTop
= rRect
.y
+ rRect
.height
;
202 m_refData
= new wxRegionRefData
;
205 // Need a PS to create a Region
207 ((wxRegionRefData
*)m_refData
)->m_hPS
= ::GpiCreatePS( vHabmain
210 ,PU_PELS
| GPIT_MICRO
| GPIA_ASSOC
212 M_REGION
= ::GpiCreateRegion( ((wxRegionRefData
*)m_refData
)->m_hPS
216 } // end of wxRegion::wxRegion
219 // Destroy the region.
221 wxRegion::~wxRegion()
223 } // end of wxRegion::~wxRegion
225 wxObjectRefData
*wxRegion::CreateData() const
227 return new wxRegionRefData
;
230 wxObjectRefData
*wxRegion::CloneData(const wxObjectRefData
*data
) const
232 return new wxRegionRefData(*(wxRegionRefData
*)data
);
235 //-----------------------------------------------------------------------------
237 //-----------------------------------------------------------------------------
239 bool wxRegion::Offset(
253 if ( ::OffsetRgn(GetHrgn(), x
, y
) == ERROR
)
255 wxLogLastError(_T("OffsetRgn"));
264 // Clear current region
266 void wxRegion::Clear()
269 } // end of wxRegion::Clear
272 // Combine rectangle (x, y, w, h) with this.
274 bool wxRegion::Combine(
282 return Combine(wxRegion(x
, y
, vWidth
, vHeight
), eOp
);
283 } // end of wxRegion::Combine
286 // Union region with this.
288 bool wxRegion::Combine(
289 const wxRegion
& rRegion
294 // We can't use the API functions if we don't have a valid region handle
298 // combining with an empty/invalid region works differently depending
309 wxFAIL_MSG( _T("unknown region operation") );
314 // leave empty/invalid
318 else // we have a valid region
346 return (::GpiCombineRegion( ((wxRegionRefData
*)rRegion
.m_refData
)->m_hPS
349 ,((wxRegionRefData
*)rRegion
.m_refData
)->m_hRegion
354 } // end of wxRegion::Combine
356 bool wxRegion::Combine(
361 return Combine( rRect
.GetLeft()
367 } // end of wxRegion::Combine
369 //-----------------------------------------------------------------------------
370 //# Information on region
371 //-----------------------------------------------------------------------------
374 // Outer bounds of region
376 void wxRegion::GetBox(
388 rc
= ::GpiQueryRegionBox( ((wxRegionRefData
*)m_refData
)->m_hPS
394 vWidth
= vRect
.xRight
- vRect
.xLeft
;
395 vHeight
= vRect
.yTop
- vRect
.yBottom
;
399 x
= y
= vWidth
= vHeight
= 0L;
401 } // end of wxRegion::GetBox
403 wxRect
wxRegion::GetBox() const
407 return wxRect(x
, y
, w
, h
);
413 bool wxRegion::Empty() const
428 return ((vWidth
== 0) && (vHeight
== 0));
429 } // end of wxRegion::Empty
431 //-----------------------------------------------------------------------------
433 //-----------------------------------------------------------------------------
436 // Does the region contain the point (x,y)?
437 wxRegionContain
wxRegion::Contains(
451 LONG lInside
= ::GpiPtInRegion( ((wxRegionRefData
*)m_refData
)->m_hPS
455 if (lInside
== PRGN_INSIDE
)
458 } // end of wxRegion::Contains
461 // Does the region contain the point pt?
463 wxRegionContain
wxRegion::Contains(
464 const wxPoint
& rPoint
467 POINTL vPoint
= { rPoint
.x
, rPoint
.y
};
472 LONG lInside
= ::GpiPtInRegion( ((wxRegionRefData
*)m_refData
)->m_hPS
476 if (lInside
== PRGN_INSIDE
)
480 } // end of wxRegion::Contains
483 // Does the region contain the rectangle (x, y, w, h)?
485 wxRegionContain
wxRegion::Contains(
499 vRect
.xRight
= x
+ vWidth
;
500 vRect
.yBottom
= y
+ vHeight
;
502 if (PRGN_INSIDE
== ::GpiRectInRegion( ((wxRegionRefData
*)m_refData
)->m_hPS
509 } // end of wxRegion::Contains
512 // Does the region contain the rectangle rect
514 wxRegionContain
wxRegion::Contains(
528 vWidth
= rRect
.GetWidth();
529 vHeight
= rRect
.GetHeight();
535 } // end of wxRegion::Contains
538 // Get internal region handle
540 WXHRGN
wxRegion::GetHRGN() const
544 return (WXHRGN
) M_REGION
;
548 // Set a new PS, this means we have to recreate the old region in the new
551 void wxRegion::SetPS(
558 vRgnData
.ulDirection
= RECTDIR_LFRT_TOPBOT
;
559 if (::GpiQueryRegionRects( ((wxRegionRefData
*)m_refData
)->m_hPS
560 ,((wxRegionRefData
*)m_refData
)->m_hRegion
566 pRect
= new RECTL
[vRgnData
.crcReturned
];
567 vRgnData
.crc
= vRgnData
.crcReturned
;
568 vRgnData
.ircStart
= 1;
569 if (::GpiQueryRegionRects( ((wxRegionRefData
*)m_refData
)->m_hPS
570 ,((wxRegionRefData
*)m_refData
)->m_hRegion
577 // First destroy the region out of the old PS
578 // and then create it in the new and set the new to current
580 ::GpiDestroyRegion( ((wxRegionRefData
*)m_refData
)->m_hPS
583 ((wxRegionRefData
*)m_refData
)->m_hRegion
= ::GpiCreateRegion( hPS
584 ,vRgnData
.crcReturned
587 ((wxRegionRefData
*)m_refData
)->m_hPS
= hPS
;
591 } // end of wxRegion::SetPS
593 ///////////////////////////////////////////////////////////////////////////////
595 // wxRegionIterator //
597 ///////////////////////////////////////////////////////////////////////////////
600 // Initialize empty iterator
602 wxRegionIterator::wxRegionIterator()
607 } // end of wxRegionIterator::wxRegionIterator
609 wxRegionIterator::~wxRegionIterator()
613 } // end of wxRegionIterator::~wxRegionIterator
616 // Initialize iterator for region
618 wxRegionIterator::wxRegionIterator(
619 const wxRegion
& rRegion
624 } // end of wxRegionIterator::wxRegionIterator
627 // Reset iterator for a new /e region.
629 void wxRegionIterator::Reset(
630 const wxRegion
& rRegion
642 if (m_vRegion
.Empty())
649 vRgnData
.ulDirection
= RECTDIR_LFRT_TOPBOT
;
650 if (::GpiQueryRegionRects( ((wxRegionRefData
*)rRegion
.m_refData
)->m_hPS
// Pres space
651 ,((wxRegionRefData
*)rRegion
.m_refData
)->m_hRegion
// Handle of region to query
652 ,NULL
// Return all RECTs
653 ,&vRgnData
// Will contain number or RECTs in region
654 ,NULL
// NULL to return number of RECTs
657 pRect
= new RECTL
[vRgnData
.crcReturned
];
658 m_pRects
= new wxRect
[vRgnData
.crcReturned
];
659 vRgnData
.crc
= vRgnData
.crcReturned
;
660 m_lNumRects
= vRgnData
.crcReturned
;
661 vRgnData
.ircStart
= 1;
662 if (::GpiQueryRegionRects( ((wxRegionRefData
*)rRegion
.m_refData
)->m_hPS
// Pres space of source
663 ,((wxRegionRefData
*)rRegion
.m_refData
)->m_hRegion
// Handle of source region
664 ,NULL
// Return all RECTs
665 ,&vRgnData
// Operations set to return rects
666 ,pRect
// Will contain the actual RECTS
670 M_REGION
= ::GpiCreateRegion( ((wxRegionRefData
*)rRegion
.m_refData
)->m_hPS
671 ,vRgnData
.crcReturned
675 for( LONG i
= 0; i
< m_lNumRects
; i
++)
677 m_pRects
[i
].x
= pRect
[i
].xLeft
;
678 m_pRects
[i
].width
= pRect
[i
].xRight
- pRect
[i
].xLeft
;
679 m_pRects
[i
].y
= pRect
[i
].yBottom
;
680 m_pRects
[i
].height
= pRect
[i
].yTop
- pRect
[i
].yBottom
;
683 ((wxRegionRefData
*)m_refData
)->m_hPS
= ((wxRegionRefData
*)rRegion
.m_refData
)->m_hPS
;
688 } // end of wxRegionIterator::Reset
691 // Increment iterator. The rectangle returned is the one after the
694 void wxRegionIterator::operator++ ()
696 if (m_lCurrent
< m_lNumRects
)
698 } // end of wxRegionIterator::operator ++
701 // Increment iterator. The rectangle returned is the one before the
704 void wxRegionIterator::operator++ (int)
706 if (m_lCurrent
< m_lNumRects
)
708 } // end of wxRegionIterator::operator++
710 wxCoord
wxRegionIterator::GetX() const
712 if (m_lCurrent
< m_lNumRects
)
713 return m_pRects
[m_lCurrent
].x
;
715 } // end of wxRegionIterator::GetX
717 wxCoord
wxRegionIterator::GetY() const
719 if (m_lCurrent
< m_lNumRects
)
720 return m_pRects
[m_lCurrent
].y
;
722 } // end of wxRegionIterator::GetY
724 wxCoord
wxRegionIterator::GetW() const
726 if (m_lCurrent
< m_lNumRects
)
727 return m_pRects
[m_lCurrent
].width
;
729 } // end of wxRegionIterator::GetW
731 wxCoord
wxRegionIterator::GetH() const
733 if (m_lCurrent
< m_lNumRects
)
734 return m_pRects
[m_lCurrent
].height
;
736 } // end of wxRegionIterator::GetH