X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/77ffb5937e89927b621128789401db8921fe580f..a766986f6d443ba1d50e3af25f3306fa56e4518e:/src/x11/region.cpp diff --git a/src/x11/region.cpp b/src/x11/region.cpp index ff48e00ac8..f912e633ba 100644 --- a/src/x11/region.cpp +++ b/src/x11/region.cpp @@ -1,20 +1,22 @@ ///////////////////////////////////////////////////////////////////////////// -// File: region.cpp +// File: src/x11/region.cpp // Purpose: Region class // Author: Julian Smart, Robert Roebling // Created: Fri Oct 24 10:46:34 MET 1997 // RCS-ID: $Id$ // Copyright: (c) 1997 Julian Smart, Robert Roebling -// Licence: wxWidgets licence +// Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// -#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) -#pragma implementation "region.h" -#endif +// for compilers that support precompilation, includes "wx.h". +#include "wx/wxprec.h" #include "wx/region.h" -#include "wx/gdicmn.h" -#include "wx/log.h" + +#ifndef WX_PRECOMP + #include "wx/log.h" + #include "wx/gdicmn.h" +#endif #ifdef __VMS__ #pragma message disable nosimpint @@ -29,21 +31,21 @@ // wxRegionRefData: private class containing the information about the region // ---------------------------------------------------------------------------- -class wxRegionRefData : public wxObjectRefData +class wxRegionRefData : public wxGDIRefData { public: wxRegionRefData() { m_region = NULL; } - + wxRegionRefData(const wxRegionRefData& refData) { m_region = XCreateRegion(); XUnionRegion( refData.m_region, m_region, m_region ); } - - ~wxRegionRefData() + + virtual ~wxRegionRefData() { if (m_region) XDestroyRegion( m_region ); @@ -59,8 +61,8 @@ public: #define M_REGIONDATA ((wxRegionRefData *)m_refData) #define M_REGIONDATA_OF(rgn) ((wxRegionRefData *)(rgn.m_refData)) -IMPLEMENT_DYNAMIC_CLASS(wxRegion, wxGDIObject); -IMPLEMENT_DYNAMIC_CLASS(wxRegionIterator,wxObject); +IMPLEMENT_DYNAMIC_CLASS(wxRegion, wxGDIObject) +IMPLEMENT_DYNAMIC_CLASS(wxRegionIterator,wxObject) // ---------------------------------------------------------------------------- // wxRegion construction @@ -71,18 +73,18 @@ IMPLEMENT_DYNAMIC_CLASS(wxRegionIterator,wxObject); void wxRegion::InitRect(wxCoord x, wxCoord y, wxCoord w, wxCoord h) { XRectangle rect; - rect.x = x; - rect.y = y; - rect.width = w; - rect.height = h; - + rect.x = (short)x; + rect.y = (short)y; + rect.width = (unsigned short)w; + rect.height = (unsigned short)h; + m_refData = new wxRegionRefData(); - + M_REGIONDATA->m_region = XCreateRegion(); XUnionRectWithRegion( &rect, M_REGIONDATA->m_region, M_REGIONDATA->m_region ); } -wxRegion::wxRegion( size_t n, const wxPoint *points, int fillStyle ) +wxRegion::wxRegion( size_t WXUNUSED(n), const wxPoint *WXUNUSED(points), int WXUNUSED(fillStyle) ) { #if 0 XPoint *xpoints = new XPoint[n]; @@ -113,12 +115,12 @@ wxRegion::~wxRegion() // m_refData unrefed in ~wxObject } -wxObjectRefData *wxRegion::CreateRefData() const +wxGDIRefData *wxRegion::CreateGDIRefData() const { return new wxRegionRefData; } -wxObjectRefData *wxRegion::CloneRefData(const wxObjectRefData *data) const +wxGDIRefData *wxRegion::CloneGDIRefData(const wxGDIRefData *data) const { return new wxRegionRefData(*(wxRegionRefData *)data); } @@ -127,15 +129,10 @@ wxObjectRefData *wxRegion::CloneRefData(const wxObjectRefData *data) const // wxRegion comparison // ---------------------------------------------------------------------------- -bool wxRegion::operator==( const wxRegion& region ) +bool wxRegion::DoIsEqual(const wxRegion& region) const { - if (m_refData == region.m_refData) return TRUE; - - if (!m_refData || !region.m_refData) return FALSE; - - // compare the regions themselves, not the pointers to ref data! return XEqualRegion( M_REGIONDATA->m_region, - M_REGIONDATA_OF(region)->m_region ); + M_REGIONDATA_OF(region)->m_region ) == True; } // ---------------------------------------------------------------------------- @@ -147,45 +144,38 @@ void wxRegion::Clear() UnRef(); } -bool wxRegion::Union( wxCoord x, wxCoord y, wxCoord width, wxCoord height ) +bool wxRegion::DoUnionWithRect(const wxRect& r) { // work around for XUnionRectWithRegion() bug: taking a union with an empty // rect results in an empty region (at least XFree 3.3.6 and 4.0 have this // problem) - if ( !width || !height ) - return TRUE; + if ( r.IsEmpty() ) + return true; XRectangle rect; - rect.x = x; - rect.y = y; - rect.width = width; - rect.height = height; - + rect.x = (short)r.x; + rect.y = (short)r.y; + rect.width = (unsigned short)r.width; + rect.height = (unsigned short)r.height; + if (!m_refData) { m_refData = new wxRegionRefData(); M_REGIONDATA->m_region = XCreateRegion(); - XUnionRectWithRegion( &rect, M_REGIONDATA->m_region, M_REGIONDATA->m_region ); } else { AllocExclusive(); - - XUnionRectWithRegion( &rect, M_REGIONDATA->m_region, M_REGIONDATA->m_region ); } - return TRUE; -} + XUnionRectWithRegion( &rect, M_REGIONDATA->m_region, M_REGIONDATA->m_region ); -bool wxRegion::Union( const wxRect& rect ) -{ - return Union( rect.x, rect.y, rect.width, rect.height ); + return true; } -bool wxRegion::Union( const wxRegion& region ) +bool wxRegion::DoUnionWithRegion( const wxRegion& region ) { - if (region.IsNull()) - return FALSE; + wxCHECK_MSG( region.Ok(), false, _T("invalid region") ); if (!m_refData) { @@ -196,40 +186,25 @@ bool wxRegion::Union( const wxRegion& region ) { AllocExclusive(); } - + XUnionRegion( M_REGIONDATA->m_region, M_REGIONDATA_OF(region)->m_region, M_REGIONDATA->m_region ); - return TRUE; -} - -bool wxRegion::Intersect( wxCoord x, wxCoord y, wxCoord width, wxCoord height ) -{ - wxRegion reg( x, y, width, height ); - - return Intersect( reg ); -} - -bool wxRegion::Intersect( const wxRect& rect ) -{ - wxRegion reg( rect ); - - return Intersect( reg ); + return true; } -bool wxRegion::Intersect( const wxRegion& region ) +bool wxRegion::DoIntersect( const wxRegion& region ) { - if (region.IsNull()) - return FALSE; + wxCHECK_MSG( region.Ok(), false, _T("invalid region") ); if (!m_refData) { m_refData = new wxRegionRefData(); M_REGIONDATA->m_region = XCreateRegion(); - - // leave here - return TRUE; + + // leave here + return true; } else { @@ -240,25 +215,12 @@ bool wxRegion::Intersect( const wxRegion& region ) M_REGIONDATA_OF(region)->m_region, M_REGIONDATA->m_region ); - return TRUE; + return true; } -bool wxRegion::Subtract( wxCoord x, wxCoord y, wxCoord width, wxCoord height ) +bool wxRegion::DoSubtract( const wxRegion& region ) { - wxRegion reg( x, y, width, height ); - return Subtract( reg ); -} - -bool wxRegion::Subtract( const wxRect& rect ) -{ - wxRegion reg( rect ); - return Subtract( reg ); -} - -bool wxRegion::Subtract( const wxRegion& region ) -{ - if (region.IsNull()) - return FALSE; + wxCHECK_MSG( region.Ok(), false, _T("invalid region") ); if (!m_refData) { @@ -274,25 +236,12 @@ bool wxRegion::Subtract( const wxRegion& region ) M_REGIONDATA_OF(region)->m_region, M_REGIONDATA->m_region ); - return TRUE; -} - -bool wxRegion::Xor( wxCoord x, wxCoord y, wxCoord width, wxCoord height ) -{ - wxRegion reg( x, y, width, height ); - return Xor( reg ); -} - -bool wxRegion::Xor( const wxRect& rect ) -{ - wxRegion reg( rect ); - return Xor( reg ); + return true; } -bool wxRegion::Xor( const wxRegion& region ) +bool wxRegion::DoXor( const wxRegion& region ) { - if (region.IsNull()) - return FALSE; + wxCHECK_MSG( region.Ok(), false, _T("invalid region") ); if (!m_refData) { @@ -307,15 +256,15 @@ bool wxRegion::Xor( const wxRegion& region ) XXorRegion( M_REGIONDATA->m_region, M_REGIONDATA_OF(region)->m_region, M_REGIONDATA->m_region ); - - return TRUE; + + return true; } // ---------------------------------------------------------------------------- // wxRegion tests // ---------------------------------------------------------------------------- -void wxRegion::GetBox( wxCoord &x, wxCoord &y, wxCoord &w, wxCoord &h ) const +bool wxRegion::DoGetBox( wxCoord &x, wxCoord &y, wxCoord &w, wxCoord &h ) const { if (m_refData) { @@ -325,6 +274,8 @@ void wxRegion::GetBox( wxCoord &x, wxCoord &y, wxCoord &w, wxCoord &h ) const y = rect.y; w = rect.width; h = rect.height; + + return true; } else { @@ -332,37 +283,32 @@ void wxRegion::GetBox( wxCoord &x, wxCoord &y, wxCoord &w, wxCoord &h ) const y = 0; w = -1; h = -1; - } -} -wxRect wxRegion::GetBox() const -{ - wxCoord x, y, w, h; - GetBox( x, y, w, h ); - return wxRect( x, y, w, h ); + return false; + } } -bool wxRegion::Offset( wxCoord x, wxCoord y ) +bool wxRegion::DoOffset( wxCoord x, wxCoord y ) { if (!m_refData) - return FALSE; + return false; AllocExclusive(); XOffsetRegion( M_REGIONDATA->m_region, x, y ); - return TRUE; + return true; } -bool wxRegion::Empty() const +bool wxRegion::IsEmpty() const { if (!m_refData) - return TRUE; + return true; - return XEmptyRegion( M_REGIONDATA->m_region ); + return XEmptyRegion( M_REGIONDATA->m_region ) == True; } -wxRegionContain wxRegion::Contains( wxCoord x, wxCoord y ) const +wxRegionContain wxRegion::DoContainsPoint( wxCoord x, wxCoord y ) const { if (!m_refData) return wxOutRegion; @@ -373,12 +319,12 @@ wxRegionContain wxRegion::Contains( wxCoord x, wxCoord y ) const return wxOutRegion; } -wxRegionContain wxRegion::Contains( wxCoord x, wxCoord y, wxCoord w, wxCoord h ) const +wxRegionContain wxRegion::DoContainsRect(const wxRect& r) const { if (!m_refData) return wxOutRegion; - int res = XRectInRegion( M_REGIONDATA->m_region, x, y, w, h ); + int res = XRectInRegion(M_REGIONDATA->m_region, r.x, r.y, r.width, r.height); switch (res) { case RectangleIn: return wxInRegion; @@ -388,16 +334,6 @@ wxRegionContain wxRegion::Contains( wxCoord x, wxCoord y, wxCoord w, wxCoord h ) return wxOutRegion; } -wxRegionContain wxRegion::Contains(const wxPoint& pt) const -{ - return Contains( pt.x, pt.y ); -} - -wxRegionContain wxRegion::Contains(const wxRect& rect) const -{ - return Contains( rect.x, rect.y, rect.width, rect.height ); -} - WXRegion *wxRegion::GetX11Region() const { if (!m_refData) @@ -425,12 +361,12 @@ struct _XRegion { _XBox *rects, extents; }; -class wxRIRefData: public wxObjectRefData +class wxRIRefData: public wxGDIRefData { public: wxRIRefData() : m_rects(0), m_numRects(0){} - ~wxRIRefData(); + virtual ~wxRIRefData(); wxRect *m_rects; size_t m_numRects; @@ -450,9 +386,9 @@ void wxRIRefData::CreateRects( const wxRegion& region ) m_rects = 0; m_numRects = 0; - + if (region.IsEmpty()) return; - + Region r = (Region) region.GetX11Region(); if (r) { @@ -555,4 +491,3 @@ wxRect wxRegionIterator::GetRect() const return r; } -