From 8a16d7370e3cdc7d583a6f14ab11b3a1d27b73df Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Mon, 25 Sep 2006 11:47:23 +0000 Subject: [PATCH] The Great wxRegion Refactoring: 1. added wxRegionBase class and derive all wxRegions from it 2. also added wxRegionWithCombine for the ports providing Combine() method (MSW, OS2 and Mac) to reduce code duplication further 3. made sure region comparison works the same way in all ports (except those not implementing it) and added IsEqual() method git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@41429 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- docs/latex/wx/region.tex | 40 +++++- include/wx/cocoa/region.h | 24 +--- include/wx/dfb/region.h | 102 +++----------- include/wx/generic/region.h | 98 +++---------- include/wx/gtk/region.h | 84 +++-------- include/wx/gtk1/region.h | 89 +++--------- include/wx/mac/carbon/region.h | 121 ++++------------ include/wx/mgl/region.h | 102 ++++---------- include/wx/msw/region.h | 106 ++------------ include/wx/os2/region.h | 191 +++---------------------- include/wx/palmos/region.h | 106 ++------------ include/wx/region.h | 249 ++++++++++++++++++++++++++++++++- include/wx/x11/region.h | 93 +++--------- src/common/rgncmn.cpp | 73 +++++----- src/dfb/region.cpp | 76 ++++------ src/generic/regiong.cpp | 92 ++++-------- src/gtk/region.cpp | 123 ++++------------ src/gtk1/region.cpp | 126 ++++------------- src/mac/carbon/region.cpp | 121 +++------------- src/mgl/region.cpp | 88 ++++-------- src/msw/region.cpp | 64 +++------ src/os2/region.cpp | 70 +++------ src/palmos/region.cpp | 47 ++----- src/x11/region.cpp | 120 ++++------------ 24 files changed, 751 insertions(+), 1654 deletions(-) diff --git a/docs/latex/wx/region.tex b/docs/latex/wx/region.tex index fed642106c..4cc3310907 100644 --- a/docs/latex/wx/region.tex +++ b/docs/latex/wx/region.tex @@ -18,6 +18,7 @@ reference counting, so copying and assignment operations are fast. \latexignore{\rtfignore{\wxheading{Members}}} + \membersection{wxRegion::wxRegion}\label{wxregionctor} \func{}{wxRegion}{\void} @@ -52,24 +53,27 @@ provided array. {\it fillStyle} parameter may have values \func{}{wxRegion}{\param{const wxBitmap\&}{ bmp}, \param{const wxColour\&}{ transColour}, - \param{int}{ tolerance = 0}} + \param{int}{ tolerance = 0}} Constructs a region using the non-transparent pixels of a bitmap. See \helpref{Union}{wxregionunion} for more details. + \membersection{wxRegion::\destruct{wxRegion}}\label{wxregiondtor} \func{}{\destruct{wxRegion}}{\void} Destructor. + \membersection{wxRegion::Clear}\label{wxregionclear} \func{void}{Clear}{\void} Clears the current region. + \membersection{wxRegion::Contains}\label{wxregioncontains} \constfunc{wxRegionContain}{Contains}{\param{long\& }{x}, \param{long\& }{y}} @@ -95,6 +99,7 @@ The return value is one of wxOutRegion, wxPartRegion and wxInRegion. On Windows, only wxOutRegion and wxInRegion are returned; a value wxInRegion then indicates that all or some part of the region is contained in this region. + \membersection{wxRegion::ConvertToBitmap}\label{wxregionconverttobitmap} \constfunc{wxBitmap}{ConvertToBitmap}{} @@ -102,6 +107,7 @@ all or some part of the region is contained in this region. Convert the region to a black and white bitmap with the white pixels being inside the region. + \membersection{wxRegion::GetBox}\label{wxregiongetbox} \constfunc{void}{GetBox}{\param{wxCoord\& }{x}, \param{wxCoord\& }{y}, \param{wxCoord\& }{width}, \param{wxCoord\& }{height}} @@ -112,6 +118,7 @@ Returns the outer bounds of the region. Returns the outer bounds of the region. + \membersection{wxRegion::Intersect}\label{wxregionintersect} \func{bool}{Intersect}{\param{wxCoord}{ x}, \param{wxCoord}{ y}, \param{wxCoord}{ width}, \param{wxCoord}{ height}} @@ -135,12 +142,23 @@ Finds the intersection of this region and another region. Creates the intersection of the two regions, that is, the parts which are in both regions. The result is stored in this region. + \membersection{wxRegion::IsEmpty}\label{wxregionisempty} \constfunc{bool}{IsEmpty}{\void} Returns {\tt true} if the region is empty, {\tt false} otherwise. + +\membersection{wxRegion::IsEqual}\label{wxregionisequal} + +\constfunc{bool}{IsEqual}{\param{const wxRegion\& }{region}} + +Returns {\tt true} if the region is equal to, i.e. covers the same area as, +another one. Note that if both this region and \arg{region} are invalid, they +are considered to be equal. + + \membersection{wxRegion::Subtract}\label{wxregionsubtract} \func{bool}{Subtract}{\param{const wxRect\&}{ rect}} @@ -160,10 +178,13 @@ Subtracts a region from this region. This operation combines the parts of 'this' region that are not part of the second region. The result is stored in this region. + \membersection{wxRegion::Offset}\label{wxregionoffset} \func{bool}{Offset}{\param{wxCoord}{ x}, \param{wxCoord}{ y}} +\func{bool}{Offset}{\param{const wxPoint\& }{ pt}} + Moves the region by the specified offsets in horizontal and vertical directions. @@ -171,6 +192,7 @@ directions. {\tt true} if successful, {\tt false} otherwise (the region is unchanged then). + \membersection{wxRegion::Union}\label{wxregionunion} \func{bool}{Union}{\param{wxCoord}{ x}, \param{wxCoord}{ y}, \param{wxCoord}{ width}, \param{wxCoord}{ height}} @@ -193,7 +215,7 @@ have a mask, solid rectangle of bitmap's dimensions is used. \func{bool}{Union}{\param{const wxBitmap\&}{ bmp}, \param{const wxColour\&}{ transColour}, - \param{int}{ tolerance = 0}} + \param{int}{ tolerance = 0}} Finds the union of this region and the non-transparent pixels of a bitmap. Colour to be treated as transparent is specified in the @@ -209,6 +231,7 @@ optional colour tolerance value. This operation creates a region that combines all of this region and the second region. The result is stored in this region. + \membersection{wxRegion::Xor}\label{wxregionxor} \func{bool}{Xor}{\param{wxCoord}{ x}, \param{wxCoord}{ y}, \param{wxCoord}{ width}, \param{wxCoord}{ height}} @@ -232,6 +255,7 @@ Finds the Xor of this region and another region. This operation creates a region that combines all of this region and the second region, except for any overlapping areas. The result is stored in this region. + \membersection{wxRegion::operator $=$}\label{wxregionassign} \func{void}{operator $=$}{\param{const wxRegion\&}{ region}} @@ -262,6 +286,7 @@ See \helpref{wxPaintEvent}{wxpaintevent} for an example of use. \latexignore{\rtfignore{\wxheading{Members}}} + \membersection{wxRegionIterator::wxRegionIterator}\label{wxregioniteratorctor} \func{}{wxRegionIterator}{\void} @@ -272,54 +297,63 @@ Default constructor. Creates an iterator object given a region. + \membersection{wxRegionIterator::GetX}\label{wxregioniteratorgetx} \constfunc{wxCoord}{GetX}{\void} Returns the x value for the current region. + \membersection{wxRegionIterator::GetY}\label{wxregioniteratorgety} \constfunc{wxCoord}{GetY}{\void} Returns the y value for the current region. + \membersection{wxRegionIterator::GetW}\label{wxregioniteratorgetw} \constfunc{wxCoord}{GetW}{\void} An alias for GetWidth. + \membersection{wxRegionIterator::GetHeight}\label{wxregioniteratorgetheight} \constfunc{wxCoord}{GetHeight}{\void} Returns the height value for the current region. + \membersection{wxRegionIterator::GetH}\label{wxregioniteratorgeth} \constfunc{wxCoord}{GetH}{\void} An alias for GetHeight. + \membersection{wxRegionIterator::GetRect}\label{wxregioniteratorgetrect} \constfunc{wxRect}{GetRect}{\void} Returns the current rectangle. + \membersection{wxRegionIterator::GetWidth}\label{wxregioniteratorgetwidth} \constfunc{wxCoord}{GetWidth}{\void} Returns the width value for the current region. + \membersection{wxRegionIterator::HaveRects}\label{wxregioniteratorhaverects} \constfunc{bool}{HaveRects}{\void} Returns {\tt true} if there are still some rectangles; otherwise returns {\tt false}. + \membersection{wxRegionIterator::Reset}\label{wxregioniteratorreset} \func{void}{Reset}{\void} @@ -330,6 +364,7 @@ Resets the iterator to the beginning of the rectangles. Resets the iterator to the given region. + \membersection{wxRegionIterator::operator $++$}\label{wxregioniteratorinc} \func{void}{operator $++$}{\void} @@ -338,6 +373,7 @@ Increment operator. Increments the iterator to the next region. \pythonnote{A wxPython alias for this operator is called {\tt Next}.} + \membersection{wxRegionIterator::operator bool}\label{wxregioniteratorbool} \constfunc{}{operator bool}{\void} diff --git a/include/wx/cocoa/region.h b/include/wx/cocoa/region.h index c658eaf49a..c7d48a92a7 100644 --- a/include/wx/cocoa/region.h +++ b/include/wx/cocoa/region.h @@ -18,7 +18,6 @@ typedef struct _NSRect NSRect; class WXDLLEXPORT wxRegion : public wxRegionGeneric { - DECLARE_DYNAMIC_CLASS(wxRegion); public: wxRegion(wxCoord x, wxCoord y, wxCoord w, wxCoord h) : wxRegionGeneric(x,y,w,h) @@ -48,27 +47,8 @@ public: wxRegion(const NSRect& rect); wxRegion(const NSRect *rects, int count); - // Use the non-transparent pixels of a wxBitmap for the region to combine - // with this region. First version takes transparency from bitmap's mask, - // second lets the user specify the colour to be treated as transparent - // along with an optional tolerance value. - // NOTE: implemented in common/rgncmn.cpp - bool Union(const wxBitmap& bmp); - bool Union(const wxBitmap& bmp, - const wxColour& transColour, int tolerance = 0); - /* And because of function hiding: */ - bool Union(long x, long y, long width, long height) - { return wxRegionGeneric::Union(x,y,width,height); } - bool Union(const wxRect& rect) - { return wxRegionGeneric::Union(rect); } - bool Union(const wxRegion& region) - { return wxRegionGeneric::Union(region); } - - // Convert the region to a B&W bitmap with the black pixels being inside - // the region. - // NOTE: implemented in common/rgncmn.cpp - wxBitmap ConvertToBitmap() const; - +private: + DECLARE_DYNAMIC_CLASS(wxRegion); }; class WXDLLEXPORT wxRegionIterator : public wxRegionIteratorGeneric diff --git a/include/wx/dfb/region.h b/include/wx/dfb/region.h index edb6525f60..d25f4d72c5 100644 --- a/include/wx/dfb/region.h +++ b/include/wx/dfb/region.h @@ -11,17 +11,10 @@ #ifndef _WX_DFB_REGION_H_ #define _WX_DFB_REGION_H_ -#include "wx/gdiobj.h" -#include "wx/gdicmn.h" - -#warning "Move these to wx/region.h when common code is moved there" -class WXDLLIMPEXP_CORE wxBitmap; -class WXDLLIMPEXP_CORE wxColour; - -class WXDLLIMPEXP_CORE wxRegion : public wxGDIObject +class WXDLLIMPEXP_CORE wxRegion : public wxRegionBase { - public: + wxRegion(); wxRegion(wxCoord x, wxCoord y, wxCoord w, wxCoord h); wxRegion(const wxPoint& topLeft, const wxPoint& bottomRight); wxRegion(const wxRect& rect); @@ -35,78 +28,11 @@ public: Union(bmp, transColour, tolerance); } - wxRegion(); - ~wxRegion(); - - #warning "FIXME: move this to common code? at least Ok()" - bool Ok() const { return m_refData != NULL; } - - bool operator==(const wxRegion& region) const; - bool operator!=(const wxRegion& region) const { return !(*this == region); } - - // Clear current region - void Clear(); - - bool Offset(wxCoord x, wxCoord y); - - // Union rectangle or region with this. - bool Union(wxCoord x, wxCoord y, wxCoord width, wxCoord height) - { return Union(wxRect(x, y, width, height)); } - bool Union(const wxRect& rect); - bool Union(const wxRegion& region); - - // Intersect rectangle or region with this. - bool Intersect(wxCoord x, wxCoord y, wxCoord width, wxCoord height) - { return Intersect(wxRect(x, y, width, height)); } - bool Intersect(const wxRect& rect); - bool Intersect(const wxRegion& region); - - // Subtract rectangle or region from this: - // Combines the parts of 'this' that are not part of the second region. - bool Subtract(wxCoord x, wxCoord y, wxCoord width, wxCoord height) - { return Subtract(wxRect(x, y, width, height)); } - bool Subtract(const wxRect& rect); - bool Subtract(const wxRegion& region); - - // XOR: the union of two combined regions except for any overlapping areas. - bool Xor(wxCoord x, wxCoord y, wxCoord width, wxCoord height) - { return Xor(wxRect(x, y, width, height)); } - bool Xor(const wxRect& rect); - bool Xor(const wxRegion& region); - - // Outer bounds of region - void GetBox(wxCoord& x, wxCoord& y, wxCoord&w, wxCoord &h) const; - wxRect GetBox() const; - - // Is region empty? - bool Empty() const; - bool IsEmpty() const { return Empty(); } - - // Does the region contain the point (x,y)? - wxRegionContain Contains(wxCoord x, wxCoord y) const; - // Does the region contain the point pt? - wxRegionContain Contains(const wxPoint& pt) const - { return Contains(pt.x, pt.y); } - // Does the region contain the rectangle rect? - wxRegionContain Contains(const wxRect& rect) const; - // Does the region contain the rectangle (x, y, w, h)? - wxRegionContain Contains(wxCoord x, wxCoord y, wxCoord w, wxCoord h) const - { return Contains(wxRect(x, y, w, h)); } - - - #warning "Move these union versions + ConvertToBitmap to wxRegionBase" - // Convert the region to a B&W bitmap with the white pixels being inside - // the region. - wxBitmap ConvertToBitmap() const; - - // Use the non-transparent pixels of a wxBitmap for the region to combine - // with this region. First version takes transparency from bitmap's mask, - // second lets the user specify the colour to be treated as transparent - // along with an optional tolerance value. - // NOTE: implemented in common/rgncmn.cpp - bool Union(const wxBitmap& bmp); - bool Union(const wxBitmap& bmp, - const wxColour& transColour, int tolerance = 0); + virtual ~wxRegion(); + + // wxRegionBase methods + virtual void Clear(); + virtual bool IsEmpty() const; // NB: implementation detail of DirectFB, should be removed if full // (i.e. not rect-only version is implemented) so that all code that @@ -118,6 +44,20 @@ protected: virtual wxObjectRefData *CreateRefData() const; virtual wxObjectRefData *CloneRefData(const wxObjectRefData *data) const; + // wxRegionBase pure virtuals + virtual bool DoIsEqual(const wxRegion& region) const; + virtual bool DoGetBox(wxCoord& x, wxCoord& y, wxCoord& w, wxCoord& h) const; + virtual wxRegionContain DoContainsPoint(wxCoord x, wxCoord y) const; + virtual wxRegionContain DoContainsRect(const wxRect& rect) const; + + virtual bool DoOffset(wxCoord x, wxCoord y); + virtual bool DoUnionWithRect(const wxRect& rect); + virtual bool DoUnionWithRegion(const wxRegion& region); + virtual bool DoIntersect(const wxRegion& region); + virtual bool DoSubtract(const wxRegion& region); + virtual bool DoXor(const wxRegion& region); + + friend class WXDLLIMPEXP_CORE wxRegionIterator; DECLARE_DYNAMIC_CLASS(wxRegion); diff --git a/include/wx/generic/region.h b/include/wx/generic/region.h index 7580f863e3..ea6830e167 100644 --- a/include/wx/generic/region.h +++ b/include/wx/generic/region.h @@ -12,16 +12,8 @@ #ifndef _WX_GENERIC_REGION_H__ #define _WX_GENERIC_REGION_H__ -#include "wx/gdiobj.h" -#include "wx/gdicmn.h" - -class WXDLLEXPORT wxRect; -class WXDLLEXPORT wxPoint; - -class WXDLLEXPORT wxRegionGeneric : public wxGDIObject +class WXDLLEXPORT wxRegionGeneric : public wxRegionBase { -// DECLARE_DYNAMIC_CLASS(wxRegionGeneric); - friend class WXDLLEXPORT wxRegionIteratorGeneric; public: wxRegionGeneric(wxCoord x, wxCoord y, wxCoord w, wxCoord h); wxRegionGeneric(const wxPoint& topLeft, const wxPoint& bottomRight); @@ -29,82 +21,32 @@ public: wxRegionGeneric(); virtual ~wxRegionGeneric(); - bool Ok() const { return m_refData != NULL; } - - bool operator == ( const wxRegionGeneric& region ) const; - bool operator != ( const wxRegionGeneric& region ) const { return !(*this == region); } - - //# Modify region - // Clear current region - void Clear(); - - // Move the region - bool Offset(wxCoord x, wxCoord y); - - // Union rectangle or region with this. - bool Union(long x, long y, long width, long height) - { return Union(wxRect(x,y,width,height)); } - bool Union(const wxRect& rect); - bool Union(const wxRegionGeneric& region); - - // Intersect rectangle or region with this. - bool Intersect(long x, long y, long width, long height) - { return Intersect(wxRect(x,y,width,height)); } - bool Intersect(const wxRect& rect); - bool Intersect(const wxRegionGeneric& region); - - // Subtract rectangle or region from this: - // Combines the parts of 'this' that are not part of the second region. - bool Subtract(long x, long y, long width, long height) - { return Subtract(wxRect(x,y,width,height)); } - bool Subtract(const wxRect& rect); - bool Subtract(const wxRegionGeneric& region); - - // XOR: the union of two combined regions except for any overlapping areas. - bool Xor(long x, long y, long width, long height); - bool Xor(const wxRect& rect); - bool Xor(const wxRegionGeneric& region); - - //# Information on region - // Outer bounds of region - void GetBox(wxCoord& x, wxCoord& y, wxCoord&w, wxCoord &h) const; - wxRect GetBox() const; - - // Is region empty? - bool Empty() const; - inline bool IsEmpty() const { return Empty(); } - - //# Tests - // Does the region contain the point (x,y)? - wxRegionContain Contains(long x, long y) const; - // Does the region contain the point pt? - wxRegionContain Contains(const wxPoint& pt) const; - // Does the region contain the rectangle (x, y, w, h)? - wxRegionContain Contains(long x, long y, long w, long h) const; - // Does the region contain the rectangle rect? - wxRegionContain Contains(const wxRect& rect) const; - - // Use the non-transparent pixels of a wxBitmap for the region to combine - // with this region. First version takes transparency from bitmap's mask, - // second lets the user specify the colour to be treated as transparent - // along with an optional tolerance value. - // NOTE: implemented in common/rgncmn.cpp - bool Union(const wxBitmap& bmp); - bool Union(const wxBitmap& bmp, - const wxColour& transColour, int tolerance = 0); - - // Convert the region to a B&W bitmap with the white pixels being inside - // the region. - wxBitmap ConvertToBitmap() const; + // wxRegionBase pure virtuals + virtual void Clear(); + virtual bool IsEmpty() const; protected: virtual wxObjectRefData *CreateRefData() const; virtual wxObjectRefData *CloneRefData(const wxObjectRefData *data) const; + + // wxRegionBase pure virtuals + virtual bool DoIsEqual(const wxRegion& region) const; + virtual bool DoGetBox(wxCoord& x, wxCoord& y, wxCoord& w, wxCoord& h) const; + virtual wxRegionContain DoContainsPoint(wxCoord x, wxCoord y) const; + virtual wxRegionContain DoContainsRect(const wxRect& rect) const; + + virtual bool DoOffset(wxCoord x, wxCoord y); + virtual bool DoUnionWithRect(const wxRect& rect); + virtual bool DoUnionWithRegion(const wxRegion& region); + virtual bool DoIntersect(const wxRegion& region); + virtual bool DoSubtract(const wxRegion& region); + virtual bool DoXor(const wxRegion& region); + + friend class WXDLLEXPORT wxRegionIteratorGeneric; }; class WXDLLEXPORT wxRegionIteratorGeneric : public wxObject { -// DECLARE_DYNAMIC_CLASS(wxRegionIteratorGeneric); public: wxRegionIteratorGeneric(); wxRegionIteratorGeneric(const wxRegionGeneric& region); @@ -134,4 +76,4 @@ private: wxRegionGeneric m_region; }; -#endif //ndef _WX_GENERIC_REGION_H__ +#endif // _WX_GENERIC_REGION_H__ diff --git a/include/wx/gtk/region.h b/include/wx/gtk/region.h index 50aa865bd3..3aae6270c4 100644 --- a/include/wx/gtk/region.h +++ b/include/wx/gtk/region.h @@ -10,28 +10,11 @@ #ifndef _WX_GTK_REGION_H_ #define _WX_GTK_REGION_H_ -#include "wx/gdiobj.h" -#include "wx/gdicmn.h" - -//----------------------------------------------------------------------------- -// constants -//----------------------------------------------------------------------------- - -// So far, for internal use only -enum wxRegionOp -{ - wxRGN_AND, // Creates the intersection of the two combined regions. - wxRGN_COPY, // Creates a copy of the region identified by hrgnSrc1. - wxRGN_DIFF, // Combines the parts of hrgnSrc1 that are not part of hrgnSrc2. - wxRGN_OR, // Creates the union of two combined regions. - wxRGN_XOR // Creates the union of two combined regions except for any overlapping areas. -}; - // ---------------------------------------------------------------------------- // wxRegion // ---------------------------------------------------------------------------- -class WXDLLIMPEXP_CORE wxRegion : public wxGDIObject +class WXDLLIMPEXP_CORE wxRegion : public wxRegionBase { public: wxRegion() { } @@ -66,55 +49,9 @@ public: virtual ~wxRegion(); - bool Ok() const { return m_refData != NULL; } - - bool operator == ( const wxRegion& region ) const; - bool operator != ( const wxRegion& region ) const { return !(*this == region); } - - void Clear(); - - bool Offset( wxCoord x, wxCoord y ); - - bool Union( wxCoord x, wxCoord y, wxCoord width, wxCoord height ); - bool Union( const wxRect& rect ); - bool Union( const wxRegion& region ); - - bool Intersect( wxCoord x, wxCoord y, wxCoord width, wxCoord height ); - bool Intersect( const wxRect& rect ); - bool Intersect( const wxRegion& region ); - - bool Subtract( wxCoord x, wxCoord y, wxCoord width, wxCoord height ); - bool Subtract( const wxRect& rect ); - bool Subtract( const wxRegion& region ); - - bool Xor( wxCoord x, wxCoord y, wxCoord width, wxCoord height ); - bool Xor( const wxRect& rect ); - bool Xor( const wxRegion& region ); - - void GetBox( wxCoord& x, wxCoord& y, wxCoord&w, wxCoord &h ) const; - wxRect GetBox() const ; - - bool Empty() const; - bool IsEmpty() const { return Empty(); } - - wxRegionContain Contains( wxCoord x, wxCoord y ) const; - wxRegionContain Contains( wxCoord x, wxCoord y, wxCoord w, wxCoord h ) const; - wxRegionContain Contains(const wxPoint& pt) const; - wxRegionContain Contains(const wxRect& rect) const; - - // Convert the region to a B&W bitmap with the white pixels being inside - // the region. - wxBitmap ConvertToBitmap() const; - - // Use the non-transparent pixels of a wxBitmap for the region to combine - // with this region. First version takes transparency from bitmap's mask, - // second lets the user specify the colour to be treated as transparent - // along with an optional tolerance value. - // NOTE: implemented in common/rgncmn.cpp - bool Union(const wxBitmap& bmp); - bool Union(const wxBitmap& bmp, - const wxColour& transColour, int tolerance = 0); - + // wxRegionBase methods + virtual void Clear(); + virtual bool IsEmpty() const; public: // Init with GdkRegion, set ref count to 2 so that @@ -128,6 +65,19 @@ protected: virtual wxObjectRefData *CreateRefData() const; virtual wxObjectRefData *CloneRefData(const wxObjectRefData *data) const; + // wxRegionBase pure virtuals + virtual bool DoIsEqual(const wxRegion& region) const; + virtual bool DoGetBox(wxCoord& x, wxCoord& y, wxCoord& w, wxCoord& h) const; + virtual wxRegionContain DoContainsPoint(wxCoord x, wxCoord y) const; + virtual wxRegionContain DoContainsRect(const wxRect& rect) const; + + virtual bool DoOffset(wxCoord x, wxCoord y); + virtual bool DoUnionWithRect(const wxRect& rect); + virtual bool DoUnionWithRegion(const wxRegion& region); + virtual bool DoIntersect(const wxRegion& region); + virtual bool DoSubtract(const wxRegion& region); + virtual bool DoXor(const wxRegion& region); + // common part of ctors for a rectangle region void InitRect(wxCoord x, wxCoord y, wxCoord w, wxCoord h); diff --git a/include/wx/gtk1/region.h b/include/wx/gtk1/region.h index fb1697fc32..17166be6bf 100644 --- a/include/wx/gtk1/region.h +++ b/include/wx/gtk1/region.h @@ -11,34 +11,12 @@ #define _WX_GTK_REGION_H_ #include "wx/list.h" -#include "wx/gdiobj.h" -#include "wx/gdicmn.h" - -//----------------------------------------------------------------------------- -// classes -//----------------------------------------------------------------------------- - -class WXDLLIMPEXP_CORE wxRegion; - -//----------------------------------------------------------------------------- -// constants -//----------------------------------------------------------------------------- - -// So far, for internal use only -enum wxRegionOp -{ - wxRGN_AND, // Creates the intersection of the two combined regions. - wxRGN_COPY, // Creates a copy of the region identified by hrgnSrc1. - wxRGN_DIFF, // Combines the parts of hrgnSrc1 that are not part of hrgnSrc2. - wxRGN_OR, // Creates the union of two combined regions. - wxRGN_XOR // Creates the union of two combined regions except for any overlapping areas. -}; // ---------------------------------------------------------------------------- // wxRegion // ---------------------------------------------------------------------------- -class WXDLLIMPEXP_CORE wxRegion : public wxGDIObject +class WXDLLIMPEXP_CORE wxRegion : public wxRegionBase { public: wxRegion() { } @@ -73,55 +51,9 @@ public: virtual ~wxRegion(); - bool Ok() const { return m_refData != NULL; } - - bool operator == ( const wxRegion& region ) const; - bool operator != ( const wxRegion& region ) const { return !(*this == region); } - - void Clear(); - - bool Offset( wxCoord x, wxCoord y ); - - bool Union( wxCoord x, wxCoord y, wxCoord width, wxCoord height ); - bool Union( const wxRect& rect ); - bool Union( const wxRegion& region ); - - bool Intersect( wxCoord x, wxCoord y, wxCoord width, wxCoord height ); - bool Intersect( const wxRect& rect ); - bool Intersect( const wxRegion& region ); - - bool Subtract( wxCoord x, wxCoord y, wxCoord width, wxCoord height ); - bool Subtract( const wxRect& rect ); - bool Subtract( const wxRegion& region ); - - bool Xor( wxCoord x, wxCoord y, wxCoord width, wxCoord height ); - bool Xor( const wxRect& rect ); - bool Xor( const wxRegion& region ); - - void GetBox( wxCoord& x, wxCoord& y, wxCoord&w, wxCoord &h ) const; - wxRect GetBox() const ; - - bool Empty() const; - bool IsEmpty() const { return Empty(); } - - wxRegionContain Contains( wxCoord x, wxCoord y ) const; - wxRegionContain Contains( wxCoord x, wxCoord y, wxCoord w, wxCoord h ) const; - wxRegionContain Contains(const wxPoint& pt) const; - wxRegionContain Contains(const wxRect& rect) const; - - // Convert the region to a B&W bitmap with the white pixels being inside - // the region. - wxBitmap ConvertToBitmap() const; - - // Use the non-transparent pixels of a wxBitmap for the region to combine - // with this region. First version takes transparency from bitmap's mask, - // second lets the user specify the colour to be treated as transparent - // along with an optional tolerance value. - // NOTE: implemented in common/rgncmn.cpp - bool Union(const wxBitmap& bmp); - bool Union(const wxBitmap& bmp, - const wxColour& transColour, int tolerance = 0); - + // wxRegionBase methods + virtual void Clear(); + virtual bool IsEmpty() const; public: // Init with GdkRegion, set ref count to 2 so that @@ -135,6 +67,19 @@ protected: virtual wxObjectRefData *CreateRefData() const; virtual wxObjectRefData *CloneRefData(const wxObjectRefData *data) const; + // wxRegionBase pure virtuals + virtual bool DoIsEqual(const wxRegion& region) const; + virtual bool DoGetBox(wxCoord& x, wxCoord& y, wxCoord& w, wxCoord& h) const; + virtual wxRegionContain DoContainsPoint(wxCoord x, wxCoord y) const; + virtual wxRegionContain DoContainsRect(const wxRect& rect) const; + + virtual bool DoOffset(wxCoord x, wxCoord y); + virtual bool DoUnionWithRect(const wxRect& rect); + virtual bool DoUnionWithRegion(const wxRegion& region); + virtual bool DoIntersect(const wxRegion& region); + virtual bool DoSubtract(const wxRegion& region); + virtual bool DoXor(const wxRegion& region); + // common part of ctors for a rectangle region void InitRect(wxCoord x, wxCoord y, wxCoord w, wxCoord h); diff --git a/include/wx/mac/carbon/region.h b/include/wx/mac/carbon/region.h index e0f51c0f2e..83f02a155e 100644 --- a/include/wx/mac/carbon/region.h +++ b/include/wx/mac/carbon/region.h @@ -9,28 +9,13 @@ // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// -#ifndef _WX_REGION_H_ -#define _WX_REGION_H_ +#ifndef _WX_MAC_CARBON_REGION_H_ +#define _WX_MAC_CARBON_REGION_H_ #include "wx/list.h" -#include "wx/gdiobj.h" -#include "wx/gdicmn.h" - -class WXDLLEXPORT wxRect; -class WXDLLEXPORT wxPoint; - -// So far, for internal use only -enum wxRegionOp { -wxRGN_AND, // Creates the intersection of the two combined regions. -wxRGN_COPY, // Creates a copy of the region identified by hrgnSrc1. -wxRGN_DIFF, // Combines the parts of hrgnSrc1 that are not part of hrgnSrc2. -wxRGN_OR, // Creates the union of two combined regions. -wxRGN_XOR // Creates the union of two combined regions except for any overlapping areas. -}; -class WXDLLEXPORT wxRegion : public wxGDIObject { -DECLARE_DYNAMIC_CLASS(wxRegion) - friend class WXDLLEXPORT wxRegionIterator; +class WXDLLEXPORT wxRegion : public wxRegionWithCombine +{ public: wxRegion(long x, long y, long w, long h); wxRegion(const wxPoint& topLeft, const wxPoint& bottomRight); @@ -50,89 +35,29 @@ public: virtual ~wxRegion(); - //# Modify region - // Clear current region - void Clear(); - - // Move the region - bool Offset(wxCoord x, wxCoord y); - - // Union rectangle or region with this. - bool Union(long x, long y, long width, long height) - { return Combine(x, y, width, height, wxRGN_OR); } - bool Union(const wxRect& rect) - { return Combine(rect, wxRGN_OR); } - bool Union(const wxRegion& region) - { return Combine(region, wxRGN_OR); } - - // Intersect rectangle or region with this. - bool Intersect(long x, long y, long width, long height) - { return Combine(x, y, width, height, wxRGN_AND); } - bool Intersect(const wxRect& rect) - { return Combine(rect, wxRGN_AND); } - bool Intersect(const wxRegion& region) - { return Combine(region, wxRGN_AND); } - - // Subtract rectangle or region from this: - // Combines the parts of 'this' that are not part of the second region. - bool Subtract(long x, long y, long width, long height) - { return Combine(x, y, width, height, wxRGN_DIFF); } - bool Subtract(const wxRect& rect) - { return Combine(rect, wxRGN_DIFF); } - bool Subtract(const wxRegion& region) - { return Combine(region, wxRGN_DIFF); } - - // XOR: the union of two combined regions except for any overlapping areas. - bool Xor(long x, long y, long width, long height) - { return Combine(x, y, width, height, wxRGN_XOR); } - bool Xor(const wxRect& rect) - { return Combine(rect, wxRGN_XOR); } - bool Xor(const wxRegion& region) - { return Combine(region, wxRGN_XOR); } - - //# Information on region - // Outer bounds of region - void GetBox(wxCoord& x, wxCoord& y, wxCoord&w, wxCoord &h) const; - wxRect GetBox() const ; - - // Is region empty? - bool Empty() const; - inline bool IsEmpty() const { return Empty(); } - - //# Tests - // Does the region contain the point (x,y)? - wxRegionContain Contains(long x, long y) const; - // Does the region contain the point pt? - wxRegionContain Contains(const wxPoint& pt) const; - // Does the region contain the rectangle (x, y, w, h)? - wxRegionContain Contains(long x, long y, long w, long h) const; - // Does the region contain the rectangle rect? - wxRegionContain Contains(const wxRect& rect) const; - - // Convert the region to a B&W bitmap with the white pixels being inside - // the region. - wxBitmap ConvertToBitmap() const; - - // Use the non-transparent pixels of a wxBitmap for the region to combine - // with this region. First version takes transparency from bitmap's mask, - // second lets the user specify the colour to be treated as transparent - // along with an optional tolerance value. - // NOTE: implemented in common/rgncmn.cpp - bool Union(const wxBitmap& bmp); - bool Union(const wxBitmap& bmp, - const wxColour& transColour, int tolerance = 0); + // wxRegionBase methods + virtual void Clear(); + virtual bool IsEmpty() const; // Internal - bool Combine(long x, long y, long width, long height, wxRegionOp op); - bool Combine(const wxRegion& region, wxRegionOp op); - bool Combine(const wxRect& rect, wxRegionOp op); const WXHRGN GetWXHRGN() const ; + +protected: + virtual bool DoIsEqual(const wxRegion& region) const; + virtual bool DoGetBox(wxCoord& x, wxCoord& y, wxCoord& w, wxCoord& h) const; + virtual wxRegionContain DoContainsPoint(wxCoord x, wxCoord y) const; + virtual wxRegionContain DoContainsRect(const wxRect& rect) const; + + virtual bool DoOffset(wxCoord x, wxCoord y); + virtual bool DoCombine(const wxRegion& region, wxRegionOp op); + +private: + DECLARE_DYNAMIC_CLASS(wxRegion) + friend class WXDLLEXPORT wxRegionIterator; }; class WXDLLEXPORT wxRegionIterator : public wxObject { - DECLARE_DYNAMIC_CLASS(wxRegionIterator) - public: wxRegionIterator(); wxRegionIterator(const wxRegion& region); @@ -157,6 +82,7 @@ public: long GetH() const; long GetHeight() const { return GetH(); } wxRect GetRect() const { return wxRect(GetX(), GetY(), GetWidth(), GetHeight()); } + private: void SetRects(long numRects, wxRect *rects); @@ -164,7 +90,8 @@ private: long m_numRects; wxRegion m_region; wxRect* m_rects; + + DECLARE_DYNAMIC_CLASS(wxRegionIterator) }; -#endif - // _WX_REGION_H_ +#endif // _WX_MAC_CARBON_REGION_H_ diff --git a/include/wx/mgl/region.h b/include/wx/mgl/region.h index ec8c23c596..1bfd468fe5 100644 --- a/include/wx/mgl/region.h +++ b/include/wx/mgl/region.h @@ -8,23 +8,17 @@ // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// -#ifndef _WX_REGION_H_ -#define _WX_REGION_H_ +#ifndef _WX_MGL_REGION_H_ +#define _WX_MGL_REGION_H_ #include "wx/list.h" -#include "wx/gdiobj.h" -#include "wx/gdicmn.h" -class WXDLLEXPORT wxRect; -class WXDLLEXPORT wxPoint; class MGLRegion; -class WXDLLEXPORT wxRegion : public wxGDIObject +class WXDLLEXPORT wxRegion : public wxRegionBase { - DECLARE_DYNAMIC_CLASS(wxRegion); - friend class WXDLLEXPORT wxRegionIterator; - public: + wxRegion(); wxRegion(wxCoord x, wxCoord y, wxCoord w, wxCoord h); wxRegion(const wxPoint& topLeft, const wxPoint& bottomRight); wxRegion(const wxRect& rect); @@ -39,68 +33,11 @@ public: Union(bmp, transColour, tolerance); } - wxRegion(); virtual ~wxRegion(); - //# Modify region - // Clear current region - void Clear(void); - - bool Offset(wxCoord x, wxCoord y); - - // Union rectangle or region with this. - bool Union(wxCoord x, wxCoord y, wxCoord width, wxCoord height); - bool Union(const wxRect& rect) { return Union(rect.x, rect.y, rect.width, rect.height); } - bool Union(const wxRegion& region); - - // Intersect rectangle or region with this. - bool Intersect(wxCoord x, wxCoord y, wxCoord width, wxCoord height); - bool Intersect(const wxRect& rect) { return Intersect(rect.x, rect.y, rect.width, rect.height); } - bool Intersect(const wxRegion& region); - - // Subtract rectangle or region from this: - // Combines the parts of 'this' that are not part of the second region. - bool Subtract(wxCoord x, wxCoord y, wxCoord width, wxCoord height); - bool Subtract(const wxRect& rect) { return Subtract(rect.x, rect.y, rect.width, rect.height); } - bool Subtract(const wxRegion& region); - - // XOR: the union of two combined regions except for any overlapping areas. - bool Xor(wxCoord x, wxCoord y, wxCoord width, wxCoord height); - bool Xor(const wxRect& rect) { return Xor(rect.x, rect.y, rect.width, rect.height); } - bool Xor(const wxRegion& region); - - //# Information on region - // Outer bounds of region - void GetBox(wxCoord& x, wxCoord& y, wxCoord&w, wxCoord &h) const; - wxRect GetBox(void) const ; - - // Is region empty? - bool Empty(void) const; - inline bool IsEmpty(void) const { return Empty(); } - - //# Tests - // Does the region contain the point (x,y)? - wxRegionContain Contains(wxCoord x, wxCoord y) const; - // Does the region contain the point pt? - wxRegionContain Contains(const wxPoint& pt) const; - // Does the region contain the rectangle (x, y, w, h)? - wxRegionContain Contains(wxCoord x, wxCoord y, wxCoord w, wxCoord h) const; - // Does the region contain the rectangle rect? - wxRegionContain Contains(const wxRect& rect) const; - - // Convert the region to a B&W bitmap with the white pixels being inside - // the region. - wxBitmap ConvertToBitmap() const; - - // Use the non-transparent pixels of a wxBitmap for the region to combine - // with this region. First version takes transparency from bitmap's mask, - // second lets the user specify the colour to be treated as transparent - // along with an optional tolerance value. - // NOTE: implemented in common/rgncmn.cpp - bool Union(const wxBitmap& bmp); - bool Union(const wxBitmap& bmp, - const wxColour& transColour, int tolerance = 0); - + // wxRegionBase methods + virtual void Clear(); + virtual bool IsEmpty() const; // implementation from now on: const MGLRegion& GetMGLRegion() const; @@ -109,6 +46,23 @@ protected: // ref counting code virtual wxObjectRefData *CreateRefData() const; virtual wxObjectRefData *CloneRefData(const wxObjectRefData *data) const; + + // wxRegionBase pure virtuals + virtual bool DoIsEqual(const wxRegion& region) const; + virtual bool DoGetBox(wxCoord& x, wxCoord& y, wxCoord& w, wxCoord& h) const; + virtual wxRegionContain DoContainsPoint(wxCoord x, wxCoord y) const; + virtual wxRegionContain DoContainsRect(const wxRect& rect) const; + + virtual bool DoOffset(wxCoord x, wxCoord y); + virtual bool DoUnionWithRect(const wxRect& rect); + virtual bool DoUnionWithRegion(const wxRegion& region); + virtual bool DoIntersect(const wxRegion& region); + virtual bool DoSubtract(const wxRegion& region); + virtual bool DoXor(const wxRegion& region); + +private: + DECLARE_DYNAMIC_CLASS(wxRegion); + friend class WXDLLEXPORT wxRegionIterator; }; @@ -116,7 +70,6 @@ WX_DECLARE_EXPORTED_LIST(wxRect, wxRegionRectList); class WXDLLEXPORT wxRegionIterator : public wxObject { - DECLARE_DYNAMIC_CLASS(wxRegionIterator); public: wxRegionIterator(void); wxRegionIterator(const wxRegion& region); @@ -125,9 +78,7 @@ public: void Reset(void) { m_currentNode = NULL; } void Reset(const wxRegion& region); -#ifndef __SALFORDC__ operator bool (void) const { return (m_currentNode != NULL); } -#endif bool HaveRects(void) const { return (m_currentNode != NULL); } @@ -145,7 +96,8 @@ public: private: wxRegionRectList m_rects; wxRegionRectList::Node *m_currentNode; + + DECLARE_DYNAMIC_CLASS(wxRegionIterator); }; -#endif - // _WX_REGION_H_ +#endif // _WX_MGL_REGION_H_ diff --git a/include/wx/msw/region.h b/include/wx/msw/region.h index b26a996c08..d867083f3f 100644 --- a/include/wx/msw/region.h +++ b/include/wx/msw/region.h @@ -9,26 +9,10 @@ // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// -#ifndef _WX_REGION_H_ -#define _WX_REGION_H_ +#ifndef _WX_MSW_REGION_H_ +#define _WX_MSW_REGION_H_ -#include "wx/gdiobj.h" -#include "wx/gdicmn.h" - -class WXDLLEXPORT wxRect; -class WXDLLEXPORT wxPoint; - -// So far, for internal use only -enum wxRegionOp -{ - wxRGN_AND, // Creates the intersection of the two combined regions. - wxRGN_COPY, // Creates a copy of the region identified by hrgnSrc1. - wxRGN_DIFF, // Combines the parts of hrgnSrc1 that are not part of hrgnSrc2. - wxRGN_OR, // Creates the union of two combined regions. - wxRGN_XOR // Creates the union of two combined regions except for any overlapping areas. -}; - -class WXDLLEXPORT wxRegion : public wxGDIObject +class WXDLLEXPORT wxRegion : public wxRegionWithCombine { public: wxRegion(); @@ -49,74 +33,9 @@ public: virtual ~wxRegion(); - // Modify region - // ------------- - - // Clear current region - void Clear(); - - // Move the region - bool Offset(wxCoord x, wxCoord y); - - // Union rectangle or region with this. - bool Union(wxCoord x, wxCoord y, wxCoord width, wxCoord height) { return Combine(x, y, width, height, wxRGN_OR); } - bool Union(const wxRect& rect) { return Combine(rect, wxRGN_OR); } - bool Union(const wxRegion& region) { return Combine(region, wxRGN_OR); } - - // Intersect rectangle or region with this. - bool Intersect(wxCoord x, wxCoord y, wxCoord width, wxCoord height) { return Combine(x, y, width, height, wxRGN_AND); } - bool Intersect(const wxRect& rect) { return Combine(rect, wxRGN_AND); } - bool Intersect(const wxRegion& region) { return Combine(region, wxRGN_AND); } - - // Subtract rectangle or region from this: - // Combines the parts of 'this' that are not part of the second region. - bool Subtract(wxCoord x, wxCoord y, wxCoord width, wxCoord height) { return Combine(x, y, width, height, wxRGN_DIFF); } - bool Subtract(const wxRect& rect) { return Combine(rect, wxRGN_DIFF); } - bool Subtract(const wxRegion& region) { return Combine(region, wxRGN_DIFF); } - - // XOR: the union of two combined regions except for any overlapping areas. - bool Xor(wxCoord x, wxCoord y, wxCoord width, wxCoord height) { return Combine(x, y, width, height, wxRGN_XOR); } - bool Xor(const wxRect& rect) { return Combine(rect, wxRGN_XOR); } - bool Xor(const wxRegion& region) { return Combine(region, wxRGN_XOR); } - - // Information on region - // --------------------- - - // Outer bounds of region - void GetBox(wxCoord& x, wxCoord& y, wxCoord&w, wxCoord &h) const; - wxRect GetBox() const ; - - // Is region empty? - bool Empty() const; - inline bool IsEmpty() const { return Empty(); } - - // Tests - // Does the region contain the point (x,y)? - wxRegionContain Contains(wxCoord x, wxCoord y) const; - // Does the region contain the point pt? - wxRegionContain Contains(const wxPoint& pt) const; - // Does the region contain the rectangle (x, y, w, h)? - wxRegionContain Contains(wxCoord x, wxCoord y, wxCoord w, wxCoord h) const; - // Does the region contain the rectangle rect? - wxRegionContain Contains(const wxRect& rect) const; - - // Convert the region to a B&W bitmap with the white pixels being inside - // the region. - wxBitmap ConvertToBitmap() const; - - // Use the non-transparent pixels of a wxBitmap for the region to combine - // with this region. First version takes transparency from bitmap's mask, - // second lets the user specify the colour to be treated as transparent - // along with an optional tolerance value. - // NOTE: implemented in common/rgncmn.cpp - bool Union(const wxBitmap& bmp); - bool Union(const wxBitmap& bmp, - const wxColour& transColour, int tolerance = 0); - -// Internal - bool Combine(wxCoord x, wxCoord y, wxCoord width, wxCoord height, wxRegionOp op); - bool Combine(const wxRegion& region, wxRegionOp op); - bool Combine(const wxRect& rect, wxRegionOp op); + // wxRegionBase methods + virtual void Clear(); + virtual bool IsEmpty() const; // Get internal region handle WXHRGN GetHRGN() const; @@ -125,6 +44,14 @@ protected: virtual wxObjectRefData *CreateRefData() const; virtual wxObjectRefData *CloneRefData(const wxObjectRefData *data) const; + virtual bool DoIsEqual(const wxRegion& region) const; + virtual bool DoGetBox(wxCoord& x, wxCoord& y, wxCoord& w, wxCoord& h) const; + virtual wxRegionContain DoContainsPoint(wxCoord x, wxCoord y) const; + virtual wxRegionContain DoContainsRect(const wxRect& rect) const; + + virtual bool DoOffset(wxCoord x, wxCoord y); + virtual bool DoCombine(const wxRegion& region, wxRegionOp op); + friend class WXDLLEXPORT wxRegionIterator; DECLARE_DYNAMIC_CLASS(wxRegion) @@ -146,9 +73,7 @@ public: bool HaveRects() const { return (m_current < m_numRects); } -#ifndef __SALFORDC__ operator bool () const { return HaveRects(); } -#endif wxRegionIterator& operator++(); wxRegionIterator operator++(int); @@ -174,5 +99,4 @@ private: DECLARE_DYNAMIC_CLASS(wxRegionIterator) }; -#endif - // _WX_REGION_H_ +#endif // _WX_MSW_REGION_H_ diff --git a/include/wx/os2/region.h b/include/wx/os2/region.h index 00ba96adc9..a2a669b0de 100644 --- a/include/wx/os2/region.h +++ b/include/wx/os2/region.h @@ -9,27 +9,13 @@ // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// -#ifndef _WX_REGION_H_ -#define _WX_REGION_H_ +#ifndef _WX_OS2_REGION_H_ +#define _WX_OS2_REGION_H_ #include "wx/list.h" -#include "wx/gdiobj.h" -#include "wx/gdicmn.h" -#include "wx/bitmap.h" #include "wx/os2/private.h" -class WXDLLEXPORT wxRect; -class WXDLLEXPORT wxPoint; - -// So far, for internal use only -enum wxRegionOp { wxRGN_AND // Creates the intersection of the two combined regions. - ,wxRGN_COPY // Creates a copy of the region identified by hrgnSrc1. - ,wxRGN_DIFF // Combines the parts of hrgnSrc1 that are not part of hrgnSrc2. - ,wxRGN_OR // Creates the union of two combined regions. - ,wxRGN_XOR // Creates the union of two combined regions except for any overlapping areas. - }; - -class WXDLLEXPORT wxRegion : public wxGDIObject +class WXDLLEXPORT wxRegion : public wxRegionWithCombine { public: wxRegion( wxCoord x @@ -62,176 +48,32 @@ public: // // Clear current region // - void Clear(void); - - bool Offset( wxCoord x - ,wxCoord y - ); - - // - // Union rectangle or region with this. - // - inline bool Union( wxCoord x - ,wxCoord y - ,wxCoord vWidth - ,wxCoord vHeight - ) - { - return Combine( x - ,y - ,vWidth - ,vHeight - ,wxRGN_OR - ); - } - inline bool Union( const wxRect& rRect) { return Combine(rRect, wxRGN_OR); } - inline bool Union(const wxRegion& rRegion) { return Combine(rRegion, wxRGN_OR); } - - // - // Intersect rectangle or region with this. - // - inline bool Intersect( wxCoord x - ,wxCoord y - ,wxCoord vWidth - ,wxCoord vHeight - ) - { - return Combine( x - ,y - ,vWidth - ,vHeight - ,wxRGN_AND - ); - } - inline bool Intersect(const wxRect& rRect) { return Combine(rRect, wxRGN_AND); } - inline bool Intersect(const wxRegion& rRegion) { return Combine(rRegion, wxRGN_AND); } - - // - // Subtract rectangle or region from this: - // Combines the parts of 'this' that are not part of the second region. - // - inline bool Subtract( wxCoord x - ,wxCoord y - ,wxCoord vWidth - ,wxCoord vHeight - ) - { - return Combine( x - ,y - ,vWidth - ,vHeight - ,wxRGN_DIFF - ); - } - inline bool Subtract(const wxRect& rRect) { return Combine(rRect, wxRGN_DIFF); } - inline bool Subtract(const wxRegion& rRegion) { return Combine(rRegion, wxRGN_DIFF); } - - // - // XOR: the union of two combined regions except for any overlapping areas. - // - inline bool Xor( wxCoord x - ,wxCoord y - ,wxCoord vWidth - ,wxCoord vHeight - ) - { - return Combine( x - ,y - ,vWidth - ,vHeight - ,wxRGN_XOR - ); - } - inline bool Xor(const wxRect& rRect) { return Combine(rRect, wxRGN_XOR); } - inline bool Xor(const wxRegion& rRegion) { return Combine(rRegion, wxRGN_XOR); } - - // - // Information on region - // Outer bounds of region - // - void GetBox( wxCoord& rX - ,wxCoord& rY - ,wxCoord& rWidth - ,wxCoord& rHeight - ) const; - wxRect GetBox(void) const; + virtual void Clear(); // // Is region empty? // - bool Empty(void) const; - inline bool IsEmpty() const { return Empty(); } - - // - // Tests - // Does the region contain the point (x,y)? - // - inline wxRegionContain Contains( wxCoord lX, wxCoord lY ) const{ - return Contains( wxPoint( lX, lY ) ); - } - // - // Convert the region to a B&W bitmap with the black pixels being inside - // the region. - // - wxBitmap ConvertToBitmap(void) const; - - // Use the non-transparent pixels of a wxBitmap for the region to combine - // with this region. First version takes transparency from bitmap's mask, - // second lets the user specify the colour to be treated as transparent - // along with an optional tolerance value. - // NOTE: implemented in common/rgncmn.cpp - bool Union(const wxBitmap& bmp); - bool Union(const wxBitmap& bmp, - const wxColour& transColour, int tolerance = 0); - - // - // Does the region contain the point pt? - // - wxRegionContain Contains(const wxPoint& rPoint) const; - - // - // Does the region contain the rectangle (x, y, w, h)? - // - wxRegionContain Contains( wxCoord x - ,wxCoord y - ,wxCoord lWidth - ,wxCoord lHeight - ) const; - - // - // Does the region contain the rectangle rect? - // - inline wxRegionContain Contains(const wxRect& rRect) const{ - return Contains( rRect.x, rRect.y, - rRect.GetWidth(), rRect.GetHeight()); - } - - // - // Internal - // - bool Combine( wxCoord x - ,wxCoord y - ,wxCoord vWidth - ,wxCoord vHeight - ,wxRegionOp eOp - ); - bool Combine( const wxRegion& rRegion - ,wxRegionOp eOp - ); - bool Combine( const wxRect& rRect - ,wxRegionOp eOp - ); + virtual bool IsEmpty() const; // // Get internal region handle // - WXHRGN GetHRGN(void) const; + WXHRGN GetHRGN() const; + void SetPS(HPS hPS); protected: virtual wxObjectRefData* CreateData(void) const; virtual wxObjectRefData* CloneData(const wxObjectRefData* pData) const; + virtual bool DoIsEqual(const wxRegion& region) const; + virtual bool DoGetBox(wxCoord& x, wxCoord& y, wxCoord& w, wxCoord& h) const; + virtual wxRegionContain DoContainsPoint(wxCoord x, wxCoord y) const; + virtual wxRegionContain DoContainsRect(const wxRect& rect) const; + + virtual bool DoOffset(wxCoord x, wxCoord y); + virtual bool DoCombine(const wxRegion& region, wxRegionOp op); + friend class WXDLLEXPORT wxRegionIterator; DECLARE_DYNAMIC_CLASS(wxRegion); @@ -269,5 +111,4 @@ private: wxRect* m_pRects; }; // end of wxRegionIterator -#endif - // _WX_REGION_H_ +#endif // _WX_OS2_REGION_H_ diff --git a/include/wx/palmos/region.h b/include/wx/palmos/region.h index 31af0202be..96950f07a8 100644 --- a/include/wx/palmos/region.h +++ b/include/wx/palmos/region.h @@ -9,26 +9,10 @@ // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// -#ifndef _WX_REGION_H_ -#define _WX_REGION_H_ +#ifndef _WX_PALMOS_REGION_H_ +#define _WX_PALMOS_REGION_H_ -#include "wx/gdiobj.h" -#include "wx/gdicmn.h" - -class WXDLLEXPORT wxRect; -class WXDLLEXPORT wxPoint; - -// So far, for internal use only -enum wxRegionOp -{ - wxRGN_AND, // Creates the intersection of the two combined regions. - wxRGN_COPY, // Creates a copy of the region identified by hrgnSrc1. - wxRGN_DIFF, // Combines the parts of hrgnSrc1 that are not part of hrgnSrc2. - wxRGN_OR, // Creates the union of two combined regions. - wxRGN_XOR // Creates the union of two combined regions except for any overlapping areas. -}; - -class WXDLLEXPORT wxRegion : public wxGDIObject +class WXDLLEXPORT wxRegion : public wxRegionWithCombine { public: wxRegion(); @@ -49,74 +33,9 @@ public: virtual ~wxRegion(); - // Modify region - // ------------- - - // Clear current region - void Clear(); - - // Move the region - bool Offset(wxCoord x, wxCoord y); - - // Union rectangle or region with this. - bool Union(wxCoord x, wxCoord y, wxCoord width, wxCoord height) { return Combine(x, y, width, height, wxRGN_OR); } - bool Union(const wxRect& rect) { return Combine(rect, wxRGN_OR); } - bool Union(const wxRegion& region) { return Combine(region, wxRGN_OR); } - - // Intersect rectangle or region with this. - bool Intersect(wxCoord x, wxCoord y, wxCoord width, wxCoord height) { return Combine(x, y, width, height, wxRGN_AND); } - bool Intersect(const wxRect& rect) { return Combine(rect, wxRGN_AND); } - bool Intersect(const wxRegion& region) { return Combine(region, wxRGN_AND); } - - // Subtract rectangle or region from this: - // Combines the parts of 'this' that are not part of the second region. - bool Subtract(wxCoord x, wxCoord y, wxCoord width, wxCoord height) { return Combine(x, y, width, height, wxRGN_DIFF); } - bool Subtract(const wxRect& rect) { return Combine(rect, wxRGN_DIFF); } - bool Subtract(const wxRegion& region) { return Combine(region, wxRGN_DIFF); } - - // XOR: the union of two combined regions except for any overlapping areas. - bool Xor(wxCoord x, wxCoord y, wxCoord width, wxCoord height) { return Combine(x, y, width, height, wxRGN_XOR); } - bool Xor(const wxRect& rect) { return Combine(rect, wxRGN_XOR); } - bool Xor(const wxRegion& region) { return Combine(region, wxRGN_XOR); } - - // Information on region - // --------------------- - - // Outer bounds of region - void GetBox(wxCoord& x, wxCoord& y, wxCoord&w, wxCoord &h) const; - wxRect GetBox() const ; - - // Is region empty? - bool Empty() const; - inline bool IsEmpty() const { return Empty(); } - - // Tests - // Does the region contain the point (x,y)? - wxRegionContain Contains(wxCoord x, wxCoord y) const; - // Does the region contain the point pt? - wxRegionContain Contains(const wxPoint& pt) const; - // Does the region contain the rectangle (x, y, w, h)? - wxRegionContain Contains(wxCoord x, wxCoord y, wxCoord w, wxCoord h) const; - // Does the region contain the rectangle rect? - wxRegionContain Contains(const wxRect& rect) const; - - // Convert the region to a B&W bitmap with the white pixels being inside - // the region. - wxBitmap ConvertToBitmap() const; - - // Use the non-transparent pixels of a wxBitmap for the region to combine - // with this region. First version takes transparency from bitmap's mask, - // second lets the user specify the colour to be treated as transparent - // along with an optional tolerance value. - // NOTE: implemented in common/rgncmn.cpp - bool Union(const wxBitmap& bmp); - bool Union(const wxBitmap& bmp, - const wxColour& transColour, int tolerance = 0); - -// Internal - bool Combine(wxCoord x, wxCoord y, wxCoord width, wxCoord height, wxRegionOp op); - bool Combine(const wxRegion& region, wxRegionOp op); - bool Combine(const wxRect& rect, wxRegionOp op); + // wxRegionBase methods + virtual void Clear(); + virtual bool IsEmpty() const; // Get internal region handle WXHRGN GetHRGN() const; @@ -125,6 +44,14 @@ protected: virtual wxObjectRefData *CreateRefData() const; virtual wxObjectRefData *CloneRefData(const wxObjectRefData *data) const; + virtual bool DoIsEqual(const wxRegion& region) const; + virtual bool DoGetBox(wxCoord& x, wxCoord& y, wxCoord& w, wxCoord& h) const; + virtual wxRegionContain DoContainsPoint(wxCoord x, wxCoord y) const; + virtual wxRegionContain DoContainsRect(const wxRect& rect) const; + + virtual bool DoOffset(wxCoord x, wxCoord y); + virtual bool DoCombine(const wxRegion& region, wxRegionOp op); + friend class WXDLLEXPORT wxRegionIterator; DECLARE_DYNAMIC_CLASS(wxRegion) @@ -146,9 +73,7 @@ public: bool HaveRects() const { return (m_current < m_numRects); } -#ifndef __SALFORDC__ operator bool () const { return HaveRects(); } -#endif wxRegionIterator& operator++(); wxRegionIterator operator++(int); @@ -174,5 +99,4 @@ private: DECLARE_DYNAMIC_CLASS(wxRegionIterator) }; -#endif - // _WX_REGION_H_ +#endif // _WX_PALMOS_REGION_H_ diff --git a/include/wx/region.h b/include/wx/region.h index 3582ecab1c..e5549cf254 100644 --- a/include/wx/region.h +++ b/include/wx/region.h @@ -12,8 +12,18 @@ #ifndef _WX_REGION_H_BASE_ #define _WX_REGION_H_BASE_ -#include "wx/colour.h" +#include "wx/bitmap.h" +#include "wx/gdiobj.h" +#include "wx/gdicmn.h" +class WXDLLEXPORT wxColour; +class WXDLLEXPORT wxRegion; + +// ---------------------------------------------------------------------------- +// constants +// ---------------------------------------------------------------------------- + +// result of wxRegion::Contains() call enum wxRegionContain { wxOutRegion = 0, @@ -21,6 +31,199 @@ enum wxRegionContain wxInRegion = 2 }; +// these constants are used with wxRegion::Combine() in the ports which have +// this method +enum wxRegionOp +{ + // Creates the intersection of the two combined regions. + wxRGN_AND, + + // Creates a copy of the region + wxRGN_COPY, + + // Combines the parts of first region that are not in the second one + wxRGN_DIFF, + + // Creates the union of two combined regions. + wxRGN_OR, + + // Creates the union of two regions except for any overlapping areas. + wxRGN_XOR +}; + +// ---------------------------------------------------------------------------- +// wxRegionBase defines wxRegion API +// ---------------------------------------------------------------------------- + +class WXDLLEXPORT wxRegionBase : public wxGDIObject +{ +public: + // ctors + // ----- + + // none are defined here but the following should be available: +#if 0 + wxRegion(); + wxRegion(wxCoord x, wxCoord y, wxCoord w, wxCoord h); + wxRegion(const wxPoint& topLeft, const wxPoint& bottomRight); + wxRegion(const wxRect& rect); + wxRegion(size_t n, const wxPoint *points, int fillStyle = wxODDEVEN_RULE); + wxRegion(const wxBitmap& bmp); + wxRegion(const wxBitmap& bmp, const wxColour& transp, int tolerance = 0); +#endif // 0 + + // operators + // --------- + + bool operator==(const wxRegion& region) const { return IsEqual(region); } + bool operator!=(const wxRegion& region) const { return !(*this == region); } + + + // accessors + // --------- + + bool Ok() const { return m_refData != NULL; } + + // Is region empty? + virtual bool IsEmpty() const = 0; + bool Empty() const { return IsEmpty(); } + + // Is region equal (i.e. covers the same area as another one)? + bool IsEqual(const wxRegion& region) const; + + // Get the bounding box + bool GetBox(wxCoord& x, wxCoord& y, wxCoord& w, wxCoord& h) const + { return DoGetBox(x, y, w, h); } + wxRect GetBox() const + { + wxCoord x, y, w, h; + return DoGetBox(x, y, w, h) ? wxRect(x, y, w, h) : wxRect(); + } + + // Test if the given point or rectangle is inside this region + wxRegionContain Contains(wxCoord x, wxCoord y) const + { return DoContainsPoint(x, y); } + wxRegionContain Contains(const wxPoint& pt) const + { return DoContainsPoint(pt.x, pt.y); } + wxRegionContain Contains(wxCoord x, wxCoord y, wxCoord w, wxCoord h) const + { return DoContainsRect(wxRect(x, y, w, h)); } + wxRegionContain Contains(const wxRect& rect) const + { return DoContainsRect(rect); } + + + // operations + // ---------- + + virtual void Clear() = 0; + + // Move the region + bool Offset(wxCoord x, wxCoord y) + { return DoOffset(x, y); } + bool Offset(const wxPoint& pt) + { return DoOffset(pt.x, pt.y); } + + // Union rectangle or region with this region. + bool Union(wxCoord x, wxCoord y, wxCoord w, wxCoord h) + { return DoUnionWithRect(wxRect(x, y, w, h)); } + bool Union(const wxRect& rect) + { return DoUnionWithRect(rect); } + bool Union(const wxRegion& region) + { return DoUnionWithRegion(region); } + +#if wxUSE_IMAGE + // Use the non-transparent pixels of a wxBitmap for the region to combine + // with this region. First version takes transparency from bitmap's mask, + // second lets the user specify the colour to be treated as transparent + // along with an optional tolerance value. + // NOTE: implemented in common/rgncmn.cpp + bool Union(const wxBitmap& bmp); + bool Union(const wxBitmap& bmp, const wxColour& transp, int tolerance = 0); +#endif // wxUSE_IMAGE + + // Intersect rectangle or region with this one. + bool Intersect(wxCoord x, wxCoord y, wxCoord w, wxCoord h) + { return Intersect(wxRect(x, y, w, h)); } + bool Intersect(const wxRect& rect); + bool Intersect(const wxRegion& region) + { return DoIntersect(region); } + + // Subtract rectangle or region from this: + // Combines the parts of 'this' that are not part of the second region. + bool Subtract(wxCoord x, wxCoord y, wxCoord w, wxCoord h) + { return Subtract(wxRect(x, y, w, h)); } + bool Subtract(const wxRect& rect); + bool Subtract(const wxRegion& region) + { return DoSubtract(region); } + + // XOR: the union of two combined regions except for any overlapping areas. + bool Xor(wxCoord x, wxCoord y, wxCoord w, wxCoord h) + { return Xor(wxRect(x, y, w, h)); } + bool Xor(const wxRect& rect); + bool Xor(const wxRegion& region) + { return DoXor(region); } + + + // Convert the region to a B&W bitmap with the white pixels being inside + // the region. + wxBitmap ConvertToBitmap() const; + +protected: + virtual bool DoIsEqual(const wxRegion& region) const = 0; + virtual bool DoGetBox(wxCoord& x, wxCoord& y, wxCoord& w, wxCoord& h) const = 0; + virtual wxRegionContain DoContainsPoint(wxCoord x, wxCoord y) const = 0; + virtual wxRegionContain DoContainsRect(const wxRect& rect) const = 0; + + virtual bool DoOffset(wxCoord x, wxCoord y) = 0; + + virtual bool DoUnionWithRect(const wxRect& rect) = 0; + virtual bool DoUnionWithRegion(const wxRegion& region) = 0; + + virtual bool DoIntersect(const wxRegion& region) = 0; + virtual bool DoSubtract(const wxRegion& region) = 0; + virtual bool DoXor(const wxRegion& region) = 0; +}; + +// some ports implement a generic Combine() function while others only +// implement individual wxRegion operations, factor out the common code for the +// ports with Combine() in this class +#if defined(__WXPALMOS__) || \ + defined(__WXMSW__) || \ + defined(__WXMAC__) || \ + defined(__WXPM__) + +#define wxHAS_REGION_COMBINE + +class wxRegionWithCombine : public wxRegionBase +{ +public: + // these methods are not part of public API as they're not implemented on + // all ports + bool Combine(wxCoord x, wxCoord y, wxCoord w, wxCoord h, wxRegionOp op); + bool Combine(const wxRect& rect, wxRegionOp op); + bool Combine(const wxRegion& region, wxRegionOp op) + { return DoCombine(region, op); } + + +protected: + // the real Combine() method, to be defined in the derived class + virtual bool DoCombine(const wxRegion& region, wxRegionOp op) = 0; + + // implement some wxRegionBase pure virtuals in terms of Combine() + virtual bool DoUnionWithRect(const wxRect& rect) + { return Combine(rect, wxRGN_OR); } + virtual bool DoUnionWithRegion(const wxRegion& region) + { return Combine(region, wxRGN_OR); } + + virtual bool DoIntersect(const wxRegion& region) + { return Combine(region, wxRGN_AND); } + virtual bool DoSubtract(const wxRegion& region) + { return Combine(region, wxRGN_DIFF); } + virtual bool DoXor(const wxRegion& region) + { return Combine(region, wxRGN_XOR); } +}; + +#endif // ports with wxRegion::Combine() + #if defined(__WXPALMOS__) #include "wx/palmos/region.h" #elif defined(__WXMSW__) @@ -43,5 +246,45 @@ enum wxRegionContain #include "wx/os2/region.h" #endif -#endif - // _WX_REGION_H_BASE_ +// ---------------------------------------------------------------------------- +// inline functions implementation +// ---------------------------------------------------------------------------- + +// NB: these functions couldn't be defined in the class declaration as they use +// wxRegion and so can be only defined after including the header declaring +// the real class + +inline bool wxRegionBase::Intersect(const wxRect& rect) +{ + return DoIntersect(wxRegion(rect)); +} + +inline bool wxRegionBase::Subtract(const wxRect& rect) +{ + return DoSubtract(wxRegion(rect)); +} + +inline bool wxRegionBase::Xor(const wxRect& rect) +{ + return DoXor(wxRegion(rect)); +} + +#ifdef wxHAS_REGION_COMBINE + +inline bool wxRegionWithCombine::Combine(wxCoord x, + wxCoord y, + wxCoord w, + wxCoord h, + wxRegionOp op) +{ + return DoCombine(wxRegion(x, y, w, h), op); +} + +inline bool wxRegionWithCombine::Combine(const wxRect& rect, wxRegionOp op) +{ + return DoCombine(wxRegion(rect), op); +} + +#endif // wxHAS_REGION_COMBINE + +#endif // _WX_REGION_H_BASE_ diff --git a/include/wx/x11/region.h b/include/wx/x11/region.h index 24f8b4c825..ec257864a1 100644 --- a/include/wx/x11/region.h +++ b/include/wx/x11/region.h @@ -1,46 +1,24 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: region.h +// Name: wx/x11/region.h // Purpose: wxRegion class // Author: Julian Smart // Modified by: // Created: 17/09/98 // RCS-ID: $Id$ // Copyright: (c) Julian Smart, Robert Roebling -// Licence: wxWindows licence +// Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// #ifndef _WX_REGION_H_ #define _WX_REGION_H_ #include "wx/list.h" -#include "wx/gdiobj.h" -#include "wx/gdicmn.h" - -//----------------------------------------------------------------------------- -// classes -//----------------------------------------------------------------------------- - -class WXDLLIMPEXP_CORE wxRegion; - -//----------------------------------------------------------------------------- -// constants -//----------------------------------------------------------------------------- - -// So far, for internal use only -enum wxRegionOp -{ - wxRGN_AND, // Creates the intersection of the two combined regions. - wxRGN_COPY, // Creates a copy of the region identified by hrgnSrc1. - wxRGN_DIFF, // Combines the parts of hrgnSrc1 that are not part of hrgnSrc2. - wxRGN_OR, // Creates the union of two combined regions. - wxRGN_XOR // Creates the union of two combined regions except for any overlapping areas. -}; // ---------------------------------------------------------------------------- // wxRegion // ---------------------------------------------------------------------------- -class WXDLLIMPEXP_CORE wxRegion : public wxGDIObject +class WXDLLIMPEXP_CORE wxRegion : public wxRegionBase { public: wxRegion() { } @@ -75,55 +53,9 @@ public: virtual ~wxRegion(); - bool Ok() const { return m_refData != NULL; } - - bool operator == ( const wxRegion& region ) const; - bool operator != ( const wxRegion& region ) const { return !(*this == region); } - - void Clear(); - - bool Offset( wxCoord x, wxCoord y ); - - bool Union( wxCoord x, wxCoord y, wxCoord width, wxCoord height ); - bool Union( const wxRect& rect ); - bool Union( const wxRegion& region ); - - bool Intersect( wxCoord x, wxCoord y, wxCoord width, wxCoord height ); - bool Intersect( const wxRect& rect ); - bool Intersect( const wxRegion& region ); - - bool Subtract( wxCoord x, wxCoord y, wxCoord width, wxCoord height ); - bool Subtract( const wxRect& rect ); - bool Subtract( const wxRegion& region ); - - bool Xor( wxCoord x, wxCoord y, wxCoord width, wxCoord height ); - bool Xor( const wxRect& rect ); - bool Xor( const wxRegion& region ); - - void GetBox( wxCoord& x, wxCoord& y, wxCoord&w, wxCoord &h ) const; - wxRect GetBox() const ; - - bool Empty() const; - bool IsEmpty() const { return Empty(); } - - wxRegionContain Contains( wxCoord x, wxCoord y ) const; - wxRegionContain Contains( wxCoord x, wxCoord y, wxCoord w, wxCoord h ) const; - wxRegionContain Contains(const wxPoint& pt) const; - wxRegionContain Contains(const wxRect& rect) const; - - // Convert the region to a B&W bitmap with the white pixels being inside - // the region. - wxBitmap ConvertToBitmap() const; - - // Use the non-transparent pixels of a wxBitmap for the region to combine - // with this region. First version takes transparency from bitmap's mask, - // second lets the user specify the colour to be treated as transparent - // along with an optional tolerance value. - // NOTE: implemented in common/rgncmn.cpp - bool Union(const wxBitmap& bmp); - bool Union(const wxBitmap& bmp, - const wxColour& transColour, int tolerance = 0); - + // wxRegionBase methods + virtual void Clear(); + virtual bool IsEmpty() const; public: WXRegion *GetX11Region() const; @@ -133,6 +65,19 @@ protected: virtual wxObjectRefData *CreateRefData() const; virtual wxObjectRefData *CloneRefData(const wxObjectRefData *data) const; + // wxRegionBase pure virtuals + virtual bool DoIsEqual(const wxRegion& region) const; + virtual bool DoGetBox(wxCoord& x, wxCoord& y, wxCoord& w, wxCoord& h) const; + virtual wxRegionContain DoContainsPoint(wxCoord x, wxCoord y) const; + virtual wxRegionContain DoContainsRect(const wxRect& rect) const; + + virtual bool DoOffset(wxCoord x, wxCoord y); + virtual bool DoUnionWithRect(const wxRect& rect); + virtual bool DoUnionWithRegion(const wxRegion& region); + virtual bool DoIntersect(const wxRegion& region); + virtual bool DoSubtract(const wxRegion& region); + virtual bool DoXor(const wxRegion& region); + // common part of ctors for a rectangle region void InitRect(wxCoord x, wxCoord y, wxCoord w, wxCoord h); diff --git a/src/common/rgncmn.cpp b/src/common/rgncmn.cpp index 0732bd75c6..cee89a91c2 100644 --- a/src/common/rgncmn.cpp +++ b/src/common/rgncmn.cpp @@ -9,6 +9,10 @@ // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// +// ============================================================================ +// declarations +// ============================================================================ + // For compilers that support precompilation, includes "wx.h". #include "wx/wxprec.h" @@ -24,8 +28,36 @@ #include "wx/image.h" #endif //WX_PRECOMP +// ============================================================================ +// wxRegionBase implementation +// ============================================================================ + +// ---------------------------------------------------------------------------- +// region comparision +// ---------------------------------------------------------------------------- + +bool wxRegionBase::IsEqual(const wxRegion& region) const +{ + if ( m_refData == region.m_refData ) + { + // regions are identical, hence equal + return true; + } + + if ( !m_refData || !region.m_refData ) + { + // one, but not both, of the regions is invalid + return false; + } + + return DoIsEqual(region); +} + +// ---------------------------------------------------------------------------- +// region to/from bitmap conversions +// ---------------------------------------------------------------------------- -wxBitmap wxRegion::ConvertToBitmap() const +wxBitmap wxRegionBase::ConvertToBitmap() const { wxRect box = GetBox(); wxBitmap bmp(box.GetRight(), box.GetBottom()); @@ -33,17 +65,16 @@ wxBitmap wxRegion::ConvertToBitmap() const dc.SelectObject(bmp); dc.SetBackground(*wxBLACK_BRUSH); dc.Clear(); - dc.SetClippingRegion(*this); + dc.SetClippingRegion(*wx_static_cast(const wxRegion *, this)); dc.SetBackground(*wxWHITE_BRUSH); dc.Clear(); dc.SelectObject(wxNullBitmap); return bmp; } -//--------------------------------------------------------------------------- - #if wxUSE_IMAGE -static bool DoRegionUnion(wxRegion& region, + +static bool DoRegionUnion(wxRegionBase& region, const wxImage& image, unsigned char loR, unsigned char loG, @@ -95,9 +126,8 @@ static bool DoRegionUnion(wxRegion& region, } -bool wxRegion::Union(const wxBitmap& bmp) +bool wxRegionBase::Union(const wxBitmap& bmp) { -#if (!defined(__WXMSW__) || wxUSE_WXDIB) if (bmp.GetMask()) { wxImage image = bmp.ConvertToImage(); @@ -109,42 +139,21 @@ bool wxRegion::Union(const wxBitmap& bmp) 0); } else -#endif { return Union(0, 0, bmp.GetWidth(), bmp.GetHeight()); } } -bool wxRegion::Union(const wxBitmap& bmp, - const wxColour& transColour, - int tolerance) +bool wxRegionBase::Union(const wxBitmap& bmp, + const wxColour& transColour, + int tolerance) { -#if (!defined(__WXMSW__) || wxUSE_WXDIB) wxImage image = bmp.ConvertToImage(); return DoRegionUnion(*this, image, transColour.Red(), transColour.Green(), transColour.Blue(), tolerance); -#else - return false; -#endif -} - -#else - -bool wxRegion::Union(const wxBitmap& WXUNUSED(bmp)) -{ - // No wxImage support - return false; -} - -bool wxRegion::Union(const wxBitmap& WXUNUSED(bmp), - const wxColour& WXUNUSED(transColour), - int WXUNUSED(tolerance)) -{ - // No wxImage support - return false; } -#endif +#endif // wxUSE_IMAGE diff --git a/src/dfb/region.cpp b/src/dfb/region.cpp index c93bb6e651..a69c046869 100644 --- a/src/dfb/region.cpp +++ b/src/dfb/region.cpp @@ -80,42 +80,30 @@ wxRegion::~wxRegion() // m_refData unrefed in ~wxObject } -bool wxRegion::operator==(const wxRegion& region) const -{ - if ( m_refData == region.m_refData ) - return true; - - if ( !Ok() ) - { - // only equal if both are invalid, otherwise different - return !region.Ok(); - } - - return M_REGION->m_rect == M_REGION_OF(region)->m_rect; -} - //----------------------------------------------------------------------------- // Information about the region //----------------------------------------------------------------------------- -void wxRegion::GetBox(wxCoord& x, wxCoord& y, wxCoord&w, wxCoord &h) const +bool wxRegion::DoIsEqual(const wxRegion& region) const +{ + return M_REGION->m_rect == M_REGION_OF(region)->m_rect; +} + +bool wxRegion::DoGetBox(wxCoord& x, wxCoord& y, wxCoord&w, wxCoord &h) const { - wxRect r = GetBox(); + if ( !m_refData ) + return false; + + const wxRect& r = M_REGION->m_rect; x = r.GetX(); y = r.GetY(); w = r.GetWidth(); h = r.GetHeight(); -} -wxRect wxRegion::GetBox() const -{ - if (m_refData) - return M_REGION->m_rect; - else - return wxRect(); + return true; } -bool wxRegion::Empty() const +bool wxRegion::IsEmpty() const { if (!m_refData) return true; @@ -132,14 +120,14 @@ void wxRegion::Clear() UnRef(); } -bool wxRegion::Offset(wxCoord x, wxCoord y) +bool wxRegion::DoOffset(wxCoord x, wxCoord y) { AllocExclusive(); M_REGION->m_rect.Offset(x, y); return true; } -bool wxRegion::Union(const wxRect& rect) +bool wxRegion::DoUnionWithRect(const wxRect& rect) { AllocExclusive(); @@ -159,29 +147,28 @@ bool wxRegion::Union(const wxRect& rect) } } -bool wxRegion::Union(const wxRegion& region) +bool wxRegion::DoUnionWithRegion(const wxRegion& region) { wxCHECK_MSG( region.Ok(), false, _T("invalid region") ); - return Union(M_REGION_OF(region)->m_rect); + return DoUnionWithRect(M_REGION_OF(region)->m_rect); } -bool wxRegion::Intersect(const wxRect& rect) +bool wxRegion::DoIntersect(const wxRegion& region) { + wxCHECK_MSG( region.Ok(), false, _T("invalid region") ); + AllocExclusive(); - M_REGION->m_rect.Intersect(rect); + M_REGION->m_rect.Intersect(M_REGION_OF(region)->m_rect); return true; } -bool wxRegion::Intersect(const wxRegion& region) +bool wxRegion::DoSubtract(const wxRegion& region) { wxCHECK_MSG( region.Ok(), false, _T("invalid region") ); - return Intersect(M_REGION_OF(region)->m_rect); -} - -bool wxRegion::Subtract(const wxRect& rect) -{ wxCHECK_MSG( Ok(), false, _T("invalid region") ); + const wxRect& rect = M_REGION_OF(region)->m_rect; + if ( rect.Contains(M_REGION->m_rect) ) { // subtracted rectangle contains this one, so the result is empty @@ -201,30 +188,19 @@ bool wxRegion::Subtract(const wxRect& rect) } } -bool wxRegion::Subtract(const wxRegion& region) +bool wxRegion::DoXor(const wxRegion& region) { wxCHECK_MSG( region.Ok(), false, _T("invalid region") ); - return Subtract(M_REGION_OF(region)->m_rect); -} - -bool wxRegion::Xor(const wxRect& rect) -{ wxFAIL_MSG( _T("Xor not implemented") ); return false; } -bool wxRegion::Xor(const wxRegion& region) -{ - wxCHECK_MSG( region.Ok(), false, _T("invalid region") ); - return Xor(M_REGION_OF(region)->m_rect); -} - //----------------------------------------------------------------------------- // Tests //----------------------------------------------------------------------------- -wxRegionContain wxRegion::Contains(wxCoord x, wxCoord y) const +wxRegionContain wxRegion::DoContainsPoint(wxCoord x, wxCoord y) const { wxCHECK_MSG( Ok(), wxOutRegion, _T("invalid region") ); @@ -234,7 +210,7 @@ wxRegionContain wxRegion::Contains(wxCoord x, wxCoord y) const return wxOutRegion; } -wxRegionContain wxRegion::Contains(const wxRect& rect) const +wxRegionContain wxRegion::DoContainsRect(const wxRect& rect) const { wxCHECK_MSG( Ok(), wxOutRegion, _T("invalid region") ); diff --git a/src/generic/regiong.cpp b/src/generic/regiong.cpp index 9c7bf1d034..a60937a63c 100644 --- a/src/generic/regiong.cpp +++ b/src/generic/regiong.cpp @@ -286,100 +286,72 @@ wxObjectRefData *wxRegionGeneric::CloneRefData(const wxObjectRefData *data) cons return new wxRegionRefData(*(wxRegionRefData *)data); } -bool wxRegionGeneric::operator== (const wxRegionGeneric& region) const +bool wxRegionGeneric::DoIsEqual(const wxRegion& region) const { - wxASSERT(m_refData && region.m_refData); return REGION::XEqualRegion(M_REGIONDATA,M_REGIONDATA_OF(region)); } -wxRect wxRegionGeneric::GetBox() const +bool wxRegionGeneric::DoGetBox(wxCoord& x, wxCoord& y, wxCoord&w, wxCoord &h) const { - wxASSERT(m_refData); - wxRect rect; - REGION::XClipBox(M_REGIONDATA,&rect); - return rect; -} + if ( !m_refData ) + return false; -void wxRegionGeneric::GetBox(wxCoord& x, wxCoord& y, wxCoord&w, wxCoord &h) const -{ - wxASSERT(m_refData); wxRect rect; REGION::XClipBox(M_REGIONDATA,&rect); x = rect.x; y = rect.y; w = rect.width; h = rect.height; + return true; } // ---------------------------------------------------------------------------- // wxRegionGeneric operations // ---------------------------------------------------------------------------- -bool wxRegionGeneric::Union(const wxRect& rect) -/* XUnionRectWithRegion */ +bool wxRegionGeneric::DoUnionWithRect(const wxRect& rect) { - if (!rect.width || !rect.height) - return false; + if ( rect.IsEmpty() ) + { + // nothing to do + return true; + } AllocExclusive(); REGION region(rect); return REGION::XUnionRegion(®ion,M_REGIONDATA,M_REGIONDATA); } -bool wxRegionGeneric::Union(const wxRegionGeneric& region) +bool wxRegionGeneric::DoUnionWithRegion(const wxRegionGeneric& region) { AllocExclusive(); return REGION::XUnionRegion(M_REGIONDATA_OF(region),M_REGIONDATA,M_REGIONDATA); } -bool wxRegionGeneric::Intersect(const wxRect& rect) -{ - if (!rect.width || !rect.height) - return false; - AllocExclusive(); - REGION region(rect); - - return REGION::XIntersectRegion(®ion,M_REGIONDATA,M_REGIONDATA); -} - -bool wxRegionGeneric::Intersect(const wxRegionGeneric& region) +bool wxRegionGeneric::DoIntersect(const wxRegionGeneric& region) { AllocExclusive(); return REGION::XIntersectRegion(M_REGIONDATA_OF(region),M_REGIONDATA,M_REGIONDATA); } -bool wxRegionGeneric::Subtract(const wxRect& rect) +bool wxRegionGeneric::DoSubtract(const wxRegionGeneric& region) { - if (!rect.width || !rect.height) - return false; - AllocExclusive(); - REGION region(rect); - - return REGION::XSubtractRegion(®ion,M_REGIONDATA,M_REGIONDATA); -} + if ( region.IsEmpty() ) + { + // nothing to do + return true; + } -bool wxRegionGeneric::Subtract(const wxRegionGeneric& region) -{ return REGION::XSubtractRegion(M_REGIONDATA_OF(region),M_REGIONDATA,M_REGIONDATA); } -bool wxRegionGeneric::Xor(const wxRect& rect) -{ - if (!rect.width || !rect.height) - return false; - AllocExclusive(); - REGION region(rect); - - return REGION::XXorRegion(®ion,M_REGIONDATA,M_REGIONDATA); -} - -bool wxRegionGeneric::Xor(const wxRegionGeneric& region) +bool wxRegionGeneric::DoXor(const wxRegionGeneric& region) { AllocExclusive(); return REGION::XXorRegion(M_REGIONDATA_OF(region),M_REGIONDATA,M_REGIONDATA); } -bool wxRegionGeneric::Offset(wxCoord x, wxCoord y) +bool wxRegionGeneric::DoOffset(wxCoord x, wxCoord y) { AllocExclusive(); return REGION::XOffsetRegion(M_REGIONDATA, x, y); @@ -389,35 +361,21 @@ bool wxRegionGeneric::Offset(wxCoord x, wxCoord y) // wxRegionGeneric comparison // ---------------------------------------------------------------------------- -bool wxRegionGeneric::Empty() const +bool wxRegionGeneric::IsEmpty() const { wxASSERT(m_refData); return REGION::XEmptyRegion(M_REGIONDATA); } // Does the region contain the point (x,y)? -wxRegionContain wxRegionGeneric::Contains(long x, long y) const -{ - wxASSERT(m_refData); - return REGION::XPointInRegion(M_REGIONDATA,x,y)?wxInRegion:wxOutRegion; -} - -// Does the region contain the point pt? -wxRegionContain wxRegionGeneric::Contains(const wxPoint& pt) const -{ - wxASSERT(m_refData); - return REGION::XPointInRegion(M_REGIONDATA,pt.x,pt.y)?wxInRegion:wxOutRegion; -} - -// Does the region contain the rectangle (x, y, w, h)? -wxRegionContain wxRegionGeneric::Contains(long x, long y, long w, long h) const +wxRegionContain wxRegionGeneric::DoContainsPoint(long x, long y) const { wxASSERT(m_refData); - return REGION::XRectInRegion(M_REGIONDATA,x,y,w,h); + return REGION::XPointInRegion(M_REGIONDATA,x,y) ? wxInRegion : wxOutRegion; } // Does the region contain the rectangle rect? -wxRegionContain wxRegionGeneric::Contains(const wxRect& rect) const +wxRegionContain wxRegionGeneric::DoContainsRect(const wxRect& rect) const { wxASSERT(m_refData); return REGION::XRectInRegion(M_REGIONDATA,rect.x,rect.y,rect.width,rect.height); diff --git a/src/gtk/region.cpp b/src/gtk/region.cpp index 0cb6a0ee19..91eecba5e4 100644 --- a/src/gtk/region.cpp +++ b/src/gtk/region.cpp @@ -133,13 +133,8 @@ wxObjectRefData *wxRegion::CloneRefData(const wxObjectRefData *data) const // wxRegion comparison // ---------------------------------------------------------------------------- -bool wxRegion::operator==( const wxRegion& region ) const +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 gdk_region_equal(M_REGIONDATA->m_region, M_REGIONDATA_OF(region)->m_region); } @@ -153,27 +148,27 @@ void wxRegion::Clear() UnRef(); } -bool wxRegion::Union( wxCoord x, wxCoord y, wxCoord width, wxCoord height ) +bool wxRegion::DoUnionWithRect(const wxRect& r) { // workaround for a strange GTK/X11 bug: taking union with an empty // rectangle results in an empty region which is definitely not what we // want - if ( !width || !height ) + if ( r.IsEmpty() ) return true; if ( !m_refData ) { - InitRect(x, y, width, height); + InitRect(r.x, r.y, r.width, r.height); } else { AllocExclusive(); GdkRectangle rect; - rect.x = x; - rect.y = y; - rect.width = width; - rect.height = height; + rect.x = r.x; + rect.y = r.y; + rect.width = r.width; + rect.height = r.height; gdk_region_union_with_rect( M_REGIONDATA->m_region, &rect ); } @@ -181,15 +176,9 @@ bool wxRegion::Union( wxCoord x, wxCoord y, wxCoord width, wxCoord height ) return true; } -bool wxRegion::Union( const wxRect& rect ) -{ - return Union( rect.x, rect.y, rect.width, rect.height ); -} - -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) { @@ -206,24 +195,9 @@ bool wxRegion::Union( const wxRegion& region ) return true; } -bool wxRegion::Intersect( wxCoord x, wxCoord y, wxCoord width, wxCoord height ) +bool wxRegion::DoIntersect( const wxRegion& region ) { - wxRegion reg( x, y, width, height ); - - return Intersect( reg ); -} - -bool wxRegion::Intersect( const wxRect& rect ) -{ - wxRegion reg( rect ); - - return Intersect( reg ); -} - -bool wxRegion::Intersect( const wxRegion& region ) -{ - if (region.IsNull()) - return false; + wxCHECK_MSG( region.Ok(), false, _T("invalid region") ); if (!m_refData) { @@ -238,22 +212,9 @@ bool wxRegion::Intersect( const wxRegion& region ) 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) { @@ -268,22 +229,9 @@ bool wxRegion::Subtract( const wxRegion& 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 ); -} - -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) { @@ -297,7 +245,7 @@ bool wxRegion::Xor( const wxRegion& region ) return true; } -bool wxRegion::Offset( wxCoord x, wxCoord y ) +bool wxRegion::DoOffset( wxCoord x, wxCoord y ) { if (!m_refData) return false; @@ -313,7 +261,7 @@ bool wxRegion::Offset( wxCoord x, wxCoord y ) // 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 ) { @@ -323,6 +271,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 { @@ -330,17 +280,12 @@ 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::Empty() const +bool wxRegion::IsEmpty() const { if (!m_refData) return true; @@ -348,7 +293,7 @@ bool wxRegion::Empty() const return gdk_region_empty( M_REGIONDATA->m_region ); } -wxRegionContain wxRegion::Contains( wxCoord x, wxCoord y ) const +wxRegionContain wxRegion::DoContainsPoint( wxCoord x, wxCoord y ) const { if (!m_refData) return wxOutRegion; @@ -359,16 +304,16 @@ 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; GdkRectangle rect; - rect.x = x; - rect.y = y; - rect.width = w; - rect.height = h; + rect.x = r.x; + rect.y = r.y; + rect.width = r.width; + rect.height = r.height; GdkOverlapType res = gdk_region_rect_in( M_REGIONDATA->m_region, &rect ); switch (res) { @@ -379,16 +324,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 ); -} - GdkRegion *wxRegion::GetRegion() const { if (!m_refData) diff --git a/src/gtk1/region.cpp b/src/gtk1/region.cpp index 80fd038c6d..acad6e5f64 100644 --- a/src/gtk1/region.cpp +++ b/src/gtk1/region.cpp @@ -150,13 +150,8 @@ wxObjectRefData *wxRegion::CloneRefData(const wxObjectRefData *data) const // wxRegion comparison // ---------------------------------------------------------------------------- -bool wxRegion::operator==( const wxRegion& region ) const +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 gdk_region_equal(M_REGIONDATA->m_region, M_REGIONDATA_OF(region)->m_region); } @@ -170,42 +165,35 @@ void wxRegion::Clear() UnRef(); } -bool wxRegion::Union( wxCoord x, wxCoord y, wxCoord width, wxCoord height ) +bool wxRegion::DoUnionWithRect(const wxRect& r) { // workaround for a strange GTK/X11 bug: taking union with an empty // rectangle results in an empty region which is definitely not what we // want - if ( !width || !height ) + if ( r.IsEmpty() ) return TRUE; if ( !m_refData ) { - InitRect(x, y, width, height); + InitRect(r.x, r.y, r.width, r.height); } else { AllocExclusive(); GdkRectangle rect; - rect.x = x; - rect.y = y; - rect.width = width; - rect.height = height; - - GdkRegion *reg = gdk_region_union_with_rect( M_REGIONDATA->m_region, &rect ); - gdk_region_destroy( M_REGIONDATA->m_region ); - M_REGIONDATA->m_region = reg; + rect.x = r.x; + rect.y = r.y; + rect.width = r.width; + rect.height = r.height; + + gdk_region_union_with_rect( M_REGIONDATA->m_region, &rect ); } return TRUE; } -bool wxRegion::Union( const wxRect& rect ) -{ - return Union( rect.x, rect.y, rect.width, rect.height ); -} - -bool wxRegion::Union( const wxRegion& region ) +bool wxRegion::DoUnionWithRegion( const wxRegion& region ) { if (region.IsNull()) return FALSE; @@ -227,24 +215,9 @@ bool wxRegion::Union( const wxRegion& 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 ); -} - -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) { @@ -261,22 +234,9 @@ bool wxRegion::Intersect( const wxRegion& region ) return TRUE; } -bool wxRegion::Subtract( wxCoord x, wxCoord y, wxCoord width, wxCoord height ) -{ - 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 ) +bool wxRegion::DoSubtract( const wxRegion& region ) { - if (region.IsNull()) - return FALSE; + wxCHECK_MSG( region.Ok(), false, _T("invalid region") ); if (!m_refData) { @@ -293,22 +253,9 @@ bool wxRegion::Subtract( const wxRegion& region ) return TRUE; } -bool wxRegion::Xor( wxCoord x, wxCoord y, wxCoord width, wxCoord height ) +bool wxRegion::DoXor( const wxRegion& region ) { - wxRegion reg( x, y, width, height ); - return Xor( reg ); -} - -bool wxRegion::Xor( const wxRect& rect ) -{ - wxRegion reg( rect ); - return Xor( reg ); -} - -bool wxRegion::Xor( const wxRegion& region ) -{ - if (region.IsNull()) - return FALSE; + wxCHECK_MSG( region.Ok(), false, _T("invalid region") ); if (!m_refData) { @@ -324,7 +271,7 @@ bool wxRegion::Xor( const wxRegion& region ) return TRUE; } -bool wxRegion::Offset( wxCoord x, wxCoord y ) +bool wxRegion::DoOffset( wxCoord x, wxCoord y ) { if (!m_refData) return FALSE; @@ -340,7 +287,7 @@ bool wxRegion::Offset( wxCoord x, wxCoord y ) // 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 ) { @@ -350,6 +297,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 { @@ -357,17 +306,12 @@ 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::Empty() const +bool wxRegion::IsEmpty() const { if (!m_refData) return TRUE; @@ -375,7 +319,7 @@ bool wxRegion::Empty() const return gdk_region_empty( M_REGIONDATA->m_region ); } -wxRegionContain wxRegion::Contains( wxCoord x, wxCoord y ) const +wxRegionContain wxRegion::DoContainsPoint( wxCoord x, wxCoord y ) const { if (!m_refData) return wxOutRegion; @@ -386,16 +330,16 @@ 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; GdkRectangle rect; - rect.x = x; - rect.y = y; - rect.width = w; - rect.height = h; + rect.x = r.x; + rect.y = r.y; + rect.width = r.width; + rect.height = r.height; GdkOverlapType res = gdk_region_rect_in( M_REGIONDATA->m_region, &rect ); switch (res) { @@ -406,16 +350,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 ); -} - GdkRegion *wxRegion::GetRegion() const { if (!m_refData) diff --git a/src/mac/carbon/region.cpp b/src/mac/carbon/region.cpp index 1f26fe1575..8bbc439e8e 100644 --- a/src/mac/carbon/region.cpp +++ b/src/mac/carbon/region.cpp @@ -142,7 +142,7 @@ void wxRegion::Clear() } // Move the region -bool wxRegion::Offset(wxCoord x, wxCoord y) +bool wxRegion::DoOffset(wxCoord x, wxCoord y) { wxCHECK_MSG( M_REGION, false, _T("invalid wxRegion") ); @@ -156,58 +156,10 @@ bool wxRegion::Offset(wxCoord x, wxCoord y) } -//! Combine rectangle (x, y, w, h) with this. -bool wxRegion::Combine(long x, long y, long width, long height, wxRegionOp op) -{ - // Don't change shared data - if (!m_refData) - { - m_refData = new wxRegionRefData(); - } - else if (m_refData->GetRefCount() > 1) - { - wxRegionRefData* ref = (wxRegionRefData*)m_refData; - UnRef(); - m_refData = new wxRegionRefData( *ref ); - } - - RgnHandle rgn = NewRgn() ; - SetRectRgn( rgn , x , y, x + width, y + height ) ; - - switch (op) - { - case wxRGN_AND: - SectRgn( M_REGION , rgn , M_REGION ) ; - break ; - - case wxRGN_OR: - UnionRgn( M_REGION , rgn , M_REGION ) ; - break ; - - case wxRGN_XOR: - XorRgn( M_REGION , rgn , M_REGION ) ; - break ; - - case wxRGN_DIFF: - DiffRgn( M_REGION , rgn , M_REGION ) ; - break ; - - case wxRGN_COPY: - default: - CopyRgn( rgn , M_REGION ) ; - break ; - } - - DisposeRgn( rgn ) ; - - return true; -} - //! Union /e region with this. -bool wxRegion::Combine(const wxRegion& region, wxRegionOp op) +bool wxRegion::DoCombine(const wxRegion& region, wxRegionOp op) { - if (region.Empty()) - return false; + wxCHECK_MSG( region.Ok(), false, _T("invalid wxRegion") ); // Don't change shared data if (!m_refData) @@ -248,17 +200,19 @@ bool wxRegion::Combine(const wxRegion& region, wxRegionOp op) return true; } -bool wxRegion::Combine(const wxRect& rect, wxRegionOp op) -{ - return Combine(rect.GetLeft(), rect.GetTop(), rect.GetWidth(), rect.GetHeight(), op); -} - //----------------------------------------------------------------------------- //# Information on region //----------------------------------------------------------------------------- +bool wxRegion::DoIsEqual(const wxRegion& region) const +{ + wxFAIL_MSG( _T("not implemented") ); + + return false; +} + // Outer bounds of region -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) { @@ -268,23 +222,19 @@ void wxRegion::GetBox(wxCoord& x, wxCoord& y, wxCoord& w, wxCoord& h) const y = box.top ; w = box.right - box.left ; h = box.bottom - box.top ; + + return true; } else { x = y = w = h = 0; - } -} - -wxRect wxRegion::GetBox() const -{ - wxCoord x, y, w, h; - GetBox(x, y, w, h); - return wxRect(x, y, w, h); + return false; + } } // Is region empty? -bool wxRegion::Empty() const +bool wxRegion::IsEmpty() const { if ( m_refData ) return EmptyRgn( M_REGION ) ; @@ -301,26 +251,13 @@ const WXHRGN wxRegion::GetWXHRGN() const //# Tests //----------------------------------------------------------------------------- -// Does the region contain the point (x,y)? -wxRegionContain wxRegion::Contains(long x, long y) const -{ - if (!m_refData) - return wxOutRegion; - - // TODO. Return wxInRegion if within region. -// if (0) -// return wxInRegion; - - return wxOutRegion; -} - // Does the region contain the point? -wxRegionContain wxRegion::Contains(const wxPoint& pt) const +wxRegionContain wxRegion::DoContainsPoint(wxCoord x, wxCoord y) const { if (!m_refData) return wxOutRegion; - Point p = { pt.y , pt.x } ; + Point p = { y , x } ; if (PtInRgn( p , M_REGION ) ) return wxInRegion; @@ -328,34 +265,18 @@ wxRegionContain wxRegion::Contains(const wxPoint& pt) const } // Does the region contain the rectangle (x, y, w, h)? -wxRegionContain wxRegion::Contains(long x, long y, long w, long h) const +wxRegionContain wxRegion::DoContainsRect(const wxRect& r) const { if (!m_refData) return wxOutRegion; - Rect rect = { y , x , y + h , x + w } ; + Rect rect = { r.y , r.x , r.y + r.h , r.x + r.w } ; if (RectInRgn( &rect , M_REGION ) ) return wxInRegion; else return wxOutRegion; } -// Does the region contain the rectangle rect -wxRegionContain wxRegion::Contains(const wxRect& rect) const -{ - if (!m_refData) - return wxOutRegion; - - long x, y, w, h; - - x = rect.x; - y = rect.y; - w = rect.GetWidth(); - h = rect.GetHeight(); - - return Contains(x, y, w, h); -} - /////////////////////////////////////////////////////////////////////////////// // // // wxRegionIterator // @@ -479,7 +400,7 @@ void wxRegionIterator::Reset(const wxRegion& region) m_rects = NULL; } - if (m_region.Empty()) + if (m_region.IsEmpty()) { m_numRects = 0; } diff --git a/src/mgl/region.cpp b/src/mgl/region.cpp index f53a93131b..f2778ffa99 100644 --- a/src/mgl/region.cpp +++ b/src/mgl/region.cpp @@ -127,8 +127,15 @@ void wxRegion::Clear() // Information on region //----------------------------------------------------------------------------- +bool wxRegion::DoIsEqual(const wxRegion& region) const +{ + wxFAIL_MSG( _T("not implemented") ); + + return false; +} + // Outer bounds of region -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) { @@ -138,22 +145,18 @@ void wxRegion::GetBox(wxCoord& x, wxCoord& y, wxCoord&w, wxCoord &h) const y = rect.top; w = rect.right - rect.left; h = rect.bottom - rect.top; + + return true; } else { x = y = w = h = 0; + return false; } } -wxRect wxRegion::GetBox() const -{ - wxCoord x, y, w, h; - GetBox(x, y, w, h); - return wxRect(x, y, w, h); -} - // Is region empty? -bool wxRegion::Empty() const +bool wxRegion::IsEmpty() const { if (!m_refData) return true; @@ -165,7 +168,7 @@ bool wxRegion::Empty() const // Modifications //----------------------------------------------------------------------------- -bool wxRegion::Offset(wxCoord x, wxCoord y) +bool wxRegion::DoOffset(wxCoord x, wxCoord y) { AllocExclusive(); M_REGION.offset(x, y); @@ -173,63 +176,35 @@ bool wxRegion::Offset(wxCoord x, wxCoord y) } // Union rectangle or region with this. -bool wxRegion::Union(wxCoord x, wxCoord y, wxCoord width, wxCoord height) +bool wxRegion::DoUnionWithRect(const wxRect& r) { AllocExclusive(); - M_REGION += MGLRect(x, y, x + width, y + height); + M_REGION += MGLRect(r.x, r.y, r.GetRight() + 1, r.GetHeight() + 1); return true; } -bool wxRegion::Union(const wxRegion& region) +bool wxRegion::DoUnionWithRegion(const wxRegion& region) { AllocExclusive(); M_REGION += M_REGION_OF(region); return true; } -// Intersect rectangle or region with this. -bool wxRegion::Intersect(wxCoord x, wxCoord y, wxCoord width, wxCoord height) -{ - AllocExclusive(); - M_REGION &= MGLRect(x, y, x + width, y + height); - return true; -} - -bool wxRegion::Intersect(const wxRegion& region) +bool wxRegion::DoIntersect(const wxRegion& region) { AllocExclusive(); M_REGION &= M_REGION_OF(region); return true; } -// Subtract rectangle or region from this: -// Combines the parts of 'this' that are not part of the second region. -bool wxRegion::Subtract(wxCoord x, wxCoord y, wxCoord width, wxCoord height) -{ - AllocExclusive(); - M_REGION -= MGLRect(x, y, x + width, y + height); - return true; -} - -bool wxRegion::Subtract(const wxRegion& region) +bool wxRegion::DoSubtract(const wxRegion& region) { AllocExclusive(); M_REGION -= M_REGION_OF(region); return true; } -// XOR: the union of two combined regions except for any overlapping areas. -bool wxRegion::Xor(wxCoord x, wxCoord y, wxCoord width, wxCoord height) -{ - AllocExclusive(); - MGLRect rect(x, y, x + width, y + height); - MGLRegion rg1 = M_REGION + rect, - rg2 = M_REGION & rect; - M_REGION = rg1 - rg2; - return true; -} - -bool wxRegion::Xor(const wxRegion& region) +bool wxRegion::DoXor(const wxRegion& region) { AllocExclusive(); MGLRegion rg1 = M_REGION + M_REGION_OF(region), @@ -244,7 +219,7 @@ bool wxRegion::Xor(const wxRegion& region) //----------------------------------------------------------------------------- // Does the region contain the point (x,y)? -wxRegionContain wxRegion::Contains(wxCoord x, wxCoord y) const +wxRegionContain wxRegion::DoContainsPoint(wxCoord x, wxCoord y) const { if (!m_refData) return wxOutRegion; @@ -255,40 +230,29 @@ wxRegionContain wxRegion::Contains(wxCoord x, wxCoord y) const return wxOutRegion; } -// Does the region contain the point pt? -wxRegionContain wxRegion::Contains(const wxPoint& pt) const -{ - return Contains(pt.x, pt.y); -} - // Does the region contain the rectangle (x, y, w, h)? -wxRegionContain wxRegion::Contains(wxCoord x, wxCoord y, wxCoord w, wxCoord h) const +wxRegionContain wxRegion::DoContainsRect(const wxRect& r) const { if (!m_refData) return wxOutRegion; - MGLRect rect(x, y, x + w, y + h); + MGLRect rect(r.x, r.y, r.GetRight() + 1, r.GetBottom() + 1); MGLRegion rg; // 1) is the rectangle entirely covered by the region? rg = MGLRegion(rect) - M_REGION; - if (rg.isEmpty()) return wxInRegion; + if (rg.isEmpty()) + return wxInRegion; // 2) is the rectangle completely outside the region? rg = M_REGION & rect; // intersection - if (rg.isEmpty()) return wxOutRegion; + if (rg.isEmpty()) + return wxOutRegion; // 3) neither case happened => it is partially covered: return wxPartRegion; } -// Does the region contain the rectangle rect -wxRegionContain wxRegion::Contains(const wxRect& rect) const -{ - return Contains(rect.x, rect.y, rect.width, rect.height); -} - - /////////////////////////////////////////////////////////////////////////////// // wxRegionIterator // /////////////////////////////////////////////////////////////////////////////// diff --git a/src/msw/region.cpp b/src/msw/region.cpp index 565ddf949c..51aff2b707 100644 --- a/src/msw/region.cpp +++ b/src/msw/region.cpp @@ -163,7 +163,7 @@ void wxRegion::Clear() UnRef(); } -bool wxRegion::Offset(wxCoord x, wxCoord y) +bool wxRegion::DoOffset(wxCoord x, wxCoord y) { wxCHECK_MSG( M_REGION, false, _T("invalid wxRegion") ); @@ -186,7 +186,7 @@ bool wxRegion::Offset(wxCoord x, wxCoord y) } // combine another region with this one -bool wxRegion::Combine(const wxRegion& rgn, wxRegionOp op) +bool wxRegion::DoCombine(const wxRegion& rgn, wxRegionOp op) { // we can't use the API functions if we don't have a valid region handle if ( !m_refData ) @@ -254,26 +254,12 @@ bool wxRegion::Combine(const wxRegion& rgn, wxRegionOp op) return true; } -// Combine rectangle (x, y, w, h) with this. -bool wxRegion::Combine(wxCoord x, wxCoord y, - wxCoord width, wxCoord height, - wxRegionOp op) -{ - return Combine(wxRegion(x, y, width, height), op); -} - -bool wxRegion::Combine(const wxRect& rect, wxRegionOp op) -{ - return Combine(rect.GetLeft(), rect.GetTop(), - rect.GetWidth(), rect.GetHeight(), op); -} - // ---------------------------------------------------------------------------- // wxRegion bounding box // ---------------------------------------------------------------------------- // Outer bounds of region -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) { @@ -283,22 +269,19 @@ void wxRegion::GetBox(wxCoord& x, wxCoord& y, wxCoord&w, wxCoord &h) const y = rect.top; w = rect.right - rect.left; h = rect.bottom - rect.top; + + return true; } else { x = y = w = h = 0; - } -} -wxRect wxRegion::GetBox() const -{ - wxCoord x, y, w, h; - GetBox(x, y, w, h); - return wxRect(x, y, w, h); + return false; + } } // Is region empty? -bool wxRegion::Empty() const +bool wxRegion::IsEmpty() const { wxCoord x, y, w, h; GetBox(x, y, w, h); @@ -306,12 +289,17 @@ bool wxRegion::Empty() const return (w == 0) && (h == 0); } +bool wxRegion::DoIsEqual(const wxRegion& region) const +{ + return ::EqualRgn(M_REGION, M_REGION_OF(region)) != 0; +} + // ---------------------------------------------------------------------------- // wxRegion hit testing // ---------------------------------------------------------------------------- // Does the region contain the point (x,y)? -wxRegionContain wxRegion::Contains(wxCoord x, wxCoord y) const +wxRegionContain wxRegion::DoContainsPoint(wxCoord x, wxCoord y) const { if (!m_refData) return wxOutRegion; @@ -319,32 +307,16 @@ wxRegionContain wxRegion::Contains(wxCoord x, wxCoord y) const return ::PtInRegion(M_REGION, (int) x, (int) y) ? wxInRegion : wxOutRegion; } -// Does the region contain the point pt? -wxRegionContain wxRegion::Contains(const wxPoint& pt) const -{ - return Contains(pt.x, pt.y); -} - // Does the region contain the rectangle (x, y, w, h)? -wxRegionContain wxRegion::Contains(wxCoord x, wxCoord y, - wxCoord w, wxCoord h) const +wxRegionContain wxRegion::DoContainsRect(const wxRect& rect) const { if (!m_refData) return wxOutRegion; - RECT rect; - rect.left = x; - rect.top = y; - rect.right = x + w; - rect.bottom = y + h; + RECT rc; + wxCopyRectToRECT(rect, rc); - return ::RectInRegion(M_REGION, &rect) ? wxInRegion : wxOutRegion; -} - -// Does the region contain the rectangle rect -wxRegionContain wxRegion::Contains(const wxRect& rect) const -{ - return Contains(rect.x, rect.y, rect.width, rect.height); + return ::RectInRegion(M_REGION, &rc) ? wxInRegion : wxOutRegion; } // Get internal region handle diff --git a/src/os2/region.cpp b/src/os2/region.cpp index a312ff367d..02832228a8 100644 --- a/src/os2/region.cpp +++ b/src/os2/region.cpp @@ -246,7 +246,7 @@ wxObjectRefData *wxRegion::CloneData(const wxObjectRefData *data) const //# Modify region //----------------------------------------------------------------------------- -bool wxRegion::Offset( wxCoord x, wxCoord y ) +bool wxRegion::DoOffset( wxCoord x, wxCoord y ) { if ( !x && !y ) { @@ -275,24 +275,10 @@ void wxRegion::Clear() UnRef(); } // end of wxRegion::Clear -// -// Combine rectangle (x, y, w, h) with this. -// -bool wxRegion::Combine( - wxCoord x -, wxCoord y -, wxCoord vWidth -, wxCoord vHeight -, wxRegionOp eOp -) -{ - return Combine(wxRegion(x, y, vWidth, vHeight), eOp); -} // end of wxRegion::Combine - // // Union region with this. // -bool wxRegion::Combine( const wxRegion& rRegion, wxRegionOp eOp ) +bool wxRegion::DoCombine( const wxRegion& rRegion, wxRegionOp eOp ) { // // We can't use the API functions if we don't have a valid region handle @@ -357,27 +343,19 @@ bool wxRegion::Combine( const wxRegion& rRegion, wxRegionOp eOp ) return true; } // end of wxRegion::Combine -bool wxRegion::Combine( - const wxRect& rRect -, wxRegionOp eOp -) -{ - return Combine( rRect.GetLeft() - ,rRect.GetTop() - ,rRect.GetWidth() - ,rRect.GetHeight() - ,eOp - ); -} // end of wxRegion::Combine - //----------------------------------------------------------------------------- //# Information on region //----------------------------------------------------------------------------- +bool wxRegion::DoIsEqual(const wxRegion& region) const +{ + return false; +} + // // Outer bounds of region // -void wxRegion::GetBox( +bool wxRegion::DoGetBox( wxCoord& x , wxCoord& y , wxCoord& vWidth @@ -397,24 +375,19 @@ void wxRegion::GetBox( y = vRect.yBottom; vWidth = vRect.xRight - vRect.xLeft; vHeight = vRect.yTop - vRect.yBottom; + return true; } else { x = y = vWidth = vHeight = 0L; + return false; } } // end of wxRegion::GetBox -wxRect wxRegion::GetBox() const -{ - wxCoord x, y, w, h; - GetBox(x, y, w, h); - return wxRect(x, y, w, h); -} - // // Is region empty? // -bool wxRegion::Empty() const +bool wxRegion::IsEmpty() const { wxCoord x; wxCoord y; @@ -430,7 +403,7 @@ bool wxRegion::Empty() const ,vHeight ); return ((vWidth == 0) && (vHeight == 0)); -} // end of wxRegion::Empty +} // end of wxRegion::IsEmpty //----------------------------------------------------------------------------- // Tests @@ -438,7 +411,7 @@ bool wxRegion::Empty() const // // Does the region contain the point pt? // -wxRegionContain wxRegion::Contains( const wxPoint& rPoint ) const +wxRegionContain wxRegion::DoContainsPoint( const wxPoint& rPoint ) const { POINTL vPoint = { rPoint.x, rPoint.y }; @@ -448,7 +421,7 @@ wxRegionContain wxRegion::Contains( const wxPoint& rPoint ) const LONG lInside = ::GpiPtInRegion( ((wxRegionRefData*)m_refData)->m_hPS, M_REGION, &vPoint - ); + ); if (lInside == PRGN_INSIDE) return wxInRegion; else @@ -458,23 +431,20 @@ wxRegionContain wxRegion::Contains( const wxPoint& rPoint ) const // // Does the region contain the rectangle (x, y, w, h)? // -wxRegionContain wxRegion::Contains( wxCoord x, - wxCoord y, - wxCoord vWidth, - wxCoord vHeight ) const +wxRegionContain wxRegion::DoContainsRect(const wxRect& rect) const { if (!m_refData) return wxOutRegion; RECTL vRect; - vRect.xLeft = x; - vRect.xRight = x + vWidth; - vRect.yTop = y + vHeight; - vRect.yBottom = y; + vRect.xLeft = r.x; + vRect.xRight = r.x + r.width; + vRect.yTop = r.y + r.height; + vRect.yBottom = r.y; LONG lInside = ::GpiRectInRegion( ((wxRegionRefData*)m_refData)->m_hPS, M_REGION, - &vRect + &vRect ); switch (lInside) { diff --git a/src/palmos/region.cpp b/src/palmos/region.cpp index 8a408284a1..46c1839b40 100644 --- a/src/palmos/region.cpp +++ b/src/palmos/region.cpp @@ -92,26 +92,13 @@ void wxRegion::Clear() { } -bool wxRegion::Offset(wxCoord x, wxCoord y) +bool wxRegion::DoOffset(wxCoord x, wxCoord y) { return false; } // combine another region with this one -bool wxRegion::Combine(const wxRegion& rgn, wxRegionOp op) -{ - return false; -} - -// Combine rectangle (x, y, w, h) with this. -bool wxRegion::Combine(wxCoord x, wxCoord y, - wxCoord width, wxCoord height, - wxRegionOp op) -{ - return false; -} - -bool wxRegion::Combine(const wxRect& rect, wxRegionOp op) +bool wxRegion::DoCombine(const wxRegion& rgn, wxRegionOp op) { return false; } @@ -121,19 +108,20 @@ bool wxRegion::Combine(const wxRect& rect, wxRegionOp op) // ---------------------------------------------------------------------------- // Outer bounds of region -void wxRegion::GetBox(wxCoord& x, wxCoord& y, wxCoord&w, wxCoord &h) const +bool wxRegion::DoGetBox(wxCoord& x, wxCoord& y, wxCoord&w, wxCoord &h) const { + return false; } -wxRect wxRegion::GetBox() const +// Is region empty? +bool wxRegion::IsEmpty() const { - return wxRect(0, 0, 0, 0); + return true; } -// Is region empty? -bool wxRegion::Empty() const +bool wxRegion::DoIsEqual(const wxRegion& region) const { - return true; + return false; } // ---------------------------------------------------------------------------- @@ -141,26 +129,13 @@ bool wxRegion::Empty() const // ---------------------------------------------------------------------------- // Does the region contain the point (x,y)? -wxRegionContain wxRegion::Contains(wxCoord x, wxCoord y) const -{ - return wxOutRegion; -} - -// Does the region contain the point pt? -wxRegionContain wxRegion::Contains(const wxPoint& pt) const -{ - return wxOutRegion; -} - -// Does the region contain the rectangle (x, y, w, h)? -wxRegionContain wxRegion::Contains(wxCoord x, wxCoord y, - wxCoord w, wxCoord h) const +wxRegionContain wxRegion::DoContainsPoint(wxCoord x, wxCoord y) const { return wxOutRegion; } // Does the region contain the rectangle rect -wxRegionContain wxRegion::Contains(const wxRect& rect) const +wxRegionContain wxRegion::DoContainsRect(const wxRect& rect) const { return wxOutRegion; } diff --git a/src/x11/region.cpp b/src/x11/region.cpp index 02b26b1600..bf46762fe0 100644 --- a/src/x11/region.cpp +++ b/src/x11/region.cpp @@ -129,13 +129,8 @@ wxObjectRefData *wxRegion::CloneRefData(const wxObjectRefData *data) const // wxRegion comparison // ---------------------------------------------------------------------------- -bool wxRegion::operator==( const wxRegion& region ) const +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 ) == True; } @@ -149,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 ) + if ( r.IsEmpty() ) return true; XRectangle rect; - rect.x = (short)x; - rect.y = (short)y; - rect.width = (unsigned short)width; - rect.height = (unsigned short)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) { @@ -206,24 +194,9 @@ bool wxRegion::Union( const wxRegion& 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 ); -} - -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) { @@ -245,22 +218,9 @@ bool wxRegion::Intersect( const wxRegion& region ) return true; } -bool wxRegion::Subtract( wxCoord x, wxCoord y, wxCoord width, wxCoord height ) -{ - wxRegion reg( x, y, width, height ); - return Subtract( reg ); -} - -bool wxRegion::Subtract( const wxRect& rect ) +bool wxRegion::DoSubtract( const wxRegion& region ) { - 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) { @@ -279,22 +239,9 @@ bool wxRegion::Subtract( const wxRegion& 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 ) +bool wxRegion::DoXor( const wxRegion& region ) { - wxRegion reg( rect ); - return Xor( reg ); -} - -bool wxRegion::Xor( const wxRegion& region ) -{ - if (region.IsNull()) - return false; + wxCHECK_MSG( region.Ok(), false, _T("invalid region") ); if (!m_refData) { @@ -317,7 +264,7 @@ bool wxRegion::Xor( const wxRegion& region ) // 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) { @@ -327,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 { @@ -334,17 +283,12 @@ 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; @@ -356,7 +300,7 @@ bool wxRegion::Offset( wxCoord x, wxCoord y ) return true; } -bool wxRegion::Empty() const +bool wxRegion::IsEmpty() const { if (!m_refData) return true; @@ -364,7 +308,7 @@ bool wxRegion::Empty() const 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; @@ -375,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; @@ -390,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) -- 2.45.2