class wxRegion : public wxGDIObject
{
public:
- 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() { }
+
+ wxRegion( wxCoord x, wxCoord y, wxCoord w, wxCoord h )
+ {
+ InitRect(x, y, w, h);
+ }
+
+ wxRegion( const wxPoint& topLeft, const wxPoint& bottomRight )
+ {
+ InitRect(topLeft.x, topLeft.y,
+ bottomRight.x - topLeft.x, bottomRight.y - topLeft.y);
+ }
+
+ wxRegion( const wxRect& rect )
+ {
+ InitRect(rect.x, rect.y, rect.width, rect.height);
+ }
+
+ wxRegion( size_t n, const wxPoint *points, int fillStyle = wxODDEVEN_RULE );
virtual ~wxRegion();
wxRegion( const wxRegion& r ) { Ref(r); }
bool operator != ( const wxRegion& region );
void Clear();
-
+
bool Offset( wxCoord x, wxCoord y );
bool Union( wxCoord x, wxCoord y, wxCoord width, wxCoord height );
GdkRegion *GetRegion() const;
protected:
+ // common part of ctors for a rectangle region
+ void InitRect(wxCoord x, wxCoord y, wxCoord w, wxCoord h);
+
// helper of Intersect()
bool IntersectRegionOnly(const wxRegion& reg);
- // call this before modifying the region
- void Unshare();
-
private:
DECLARE_DYNAMIC_CLASS(wxRegion);
};
class wxRegion : public wxGDIObject
{
public:
- 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() { }
+
+ wxRegion( wxCoord x, wxCoord y, wxCoord w, wxCoord h )
+ {
+ InitRect(x, y, w, h);
+ }
+
+ wxRegion( const wxPoint& topLeft, const wxPoint& bottomRight )
+ {
+ InitRect(topLeft.x, topLeft.y,
+ bottomRight.x - topLeft.x, bottomRight.y - topLeft.y);
+ }
+
+ wxRegion( const wxRect& rect )
+ {
+ InitRect(rect.x, rect.y, rect.width, rect.height);
+ }
+
+ wxRegion( size_t n, const wxPoint *points, int fillStyle = wxODDEVEN_RULE );
virtual ~wxRegion();
wxRegion( const wxRegion& r ) { Ref(r); }
bool operator != ( const wxRegion& region );
void Clear();
-
+
bool Offset( wxCoord x, wxCoord y );
bool Union( wxCoord x, wxCoord y, wxCoord width, wxCoord height );
GdkRegion *GetRegion() const;
protected:
+ // common part of ctors for a rectangle region
+ void InitRect(wxCoord x, wxCoord y, wxCoord w, wxCoord h);
+
// helper of Intersect()
bool IntersectRegionOnly(const wxRegion& reg);
- // call this before modifying the region
- void Unshare();
-
private:
DECLARE_DYNAMIC_CLASS(wxRegion);
};
// Name: gtk/region.cpp
// Purpose:
// Author: Robert Roebling
-// Modified: VZ at 05.10.00: use Unshare(), comparison fixed
+// Modified: VZ at 05.10.00: use AllocExclusive(), comparison fixed
// Id: $Id$
// Copyright: (c) 1998 Robert Roebling
// Licence: wxWindows licence
wxRegionRefData::~wxRegionRefData()
{
- if (m_region) gdk_region_destroy( m_region );
+ if (m_region)
+ gdk_region_destroy( m_region );
#if OLDCODE
wxNode *node = m_rects.First();
{
}
-wxRegion::wxRegion( wxCoord x, wxCoord y, wxCoord w, wxCoord h )
+void wxRegion::InitRect(wxCoord x, wxCoord y, wxCoord w, wxCoord h)
{
m_refData = new wxRegionRefData();
GdkRegion *reg = gdk_region_new();
M_REGIONDATA->m_region = gdk_region_union_with_rect( reg, &rect );
gdk_region_destroy( reg );
#endif
-#if OLDCODE
- M_REGIONDATA->m_rects.Append( (wxObject*) new wxRect(x,y,w,h) );
-#endif
-}
-
-wxRegion::wxRegion( const wxPoint& topLeft, const wxPoint& bottomRight )
-{
- m_refData = new wxRegionRefData();
- GdkRegion *reg = gdk_region_new();
- GdkRectangle rect;
- rect.x = topLeft.x;
- rect.y = topLeft.y;
- rect.width = bottomRight.x - rect.x;
- rect.height = bottomRight.y - rect.y;
-#ifdef __WXGTK20__
- gdk_region_union_with_rect( reg, &rect );
- M_REGIONDATA->m_region = reg;
-#else
- M_REGIONDATA->m_region = gdk_region_union_with_rect( reg, &rect );
- gdk_region_destroy( reg );
-#endif
-#if OLDCODE
- M_REGIONDATA->m_rects.Append( (wxObject*) new wxRect(topLeft,bottomRight) );
-#endif
-}
-wxRegion::wxRegion( const wxRect& rect )
-{
- m_refData = new wxRegionRefData();
- GdkRegion *reg = gdk_region_new();
- GdkRectangle g_rect;
- g_rect.x = rect.x;
- g_rect.y = rect.y;
- g_rect.width = rect.width;
- g_rect.height = rect.height;
-#ifdef __WXGTK20__
- gdk_region_union_with_rect( reg, &g_rect );
- M_REGIONDATA->m_region = reg;
-#else
- M_REGIONDATA->m_region = gdk_region_union_with_rect( reg, &g_rect );
- gdk_region_destroy( reg );
-#endif
#if OLDCODE
- M_REGIONDATA->m_rects.Append( (wxObject*) new wxRect(rect.x,rect.y,rect.width,rect.height) );
+ M_REGIONDATA->m_rects.Append( (wxObject*) new wxRect(x, y, w, h) );
#endif
}
{
}
+// ----------------------------------------------------------------------------
+// wxRegion comparison
+// ----------------------------------------------------------------------------
+
bool wxRegion::operator==( const wxRegion& region )
{
- // VZ: compare the regions themselves, not the pointers to ref data!
+ // compare the regions themselves, not the pointers to ref data!
return gdk_region_equal(M_REGIONDATA->m_region,
M_REGIONDATA_OF(region)->m_region);
}
return !(*this == region);
}
-void wxRegion::Unshare()
-{
- if ( !m_refData )
- {
- m_refData = new wxRegionRefData;
- M_REGIONDATA->m_region = gdk_region_new();
- }
- else if ( m_refData->GetRefCount() > 1 )
- {
- wxRegionRefData *refData = new wxRegionRefData(*M_REGIONDATA);
- UnRef();
- m_refData = refData;
- }
- //else: we're not shared
-}
-
// ----------------------------------------------------------------------------
// wxRegion operations
// ----------------------------------------------------------------------------
}
else
{
- Unshare();
+ AllocExclusive();
#ifdef __WXGTK20__
gdk_region_union_with_rect( M_REGIONDATA->m_region, &rect );
if (region.IsNull())
return FALSE;
- Unshare();
+ AllocExclusive();
#ifdef __WXGTK20__
gdk_region_union( M_REGIONDATA->m_region, region.GetRegion() );
// if we called Intersect() itself recursively
bool wxRegion::IntersectRegionOnly(const wxRegion& region)
{
- Unshare();
+ AllocExclusive();
#ifdef __WXGTK20__
gdk_region_intersect( M_REGIONDATA->m_region, region.GetRegion() );
node = node->Next();
}
-#endif
+#endif // OLDCODE
+
return TRUE;
}
M_REGIONDATA->m_region = gdk_region_new();
}
- Unshare();
+ AllocExclusive();
#ifdef __WXGTK20__
gdk_region_subtract( M_REGIONDATA->m_region, region.GetRegion() );
}
else
{
- Unshare();
+ AllocExclusive();
}
#ifdef __WXGTK20__
M_REGIONDATA->m_rects.Append( (wxObject*) new wxRect(r->x,r->y,r->width,r->height) );
node = node->Next();
}
-#endif
+#endif // OLDCODE
return TRUE;
}
if (!m_refData)
return FALSE;
+ AllocExclusive();
+
gdk_region_offset( M_REGIONDATA->m_region, x, y );
-
+
return TRUE;
}
return r->height;
}
-#else
+#else // !OLDCODE
// the following structures must match the private structures
// in X11 region code ( xc/lib/X11/region.h )
return r;
}
-#endif
+#endif // OLDCODE/!OLDCODE
// Name: gtk/region.cpp
// Purpose:
// Author: Robert Roebling
-// Modified: VZ at 05.10.00: use Unshare(), comparison fixed
+// Modified: VZ at 05.10.00: use AllocExclusive(), comparison fixed
// Id: $Id$
// Copyright: (c) 1998 Robert Roebling
// Licence: wxWindows licence
wxRegionRefData::~wxRegionRefData()
{
- if (m_region) gdk_region_destroy( m_region );
+ if (m_region)
+ gdk_region_destroy( m_region );
#if OLDCODE
wxNode *node = m_rects.First();
{
}
-wxRegion::wxRegion( wxCoord x, wxCoord y, wxCoord w, wxCoord h )
+void wxRegion::InitRect(wxCoord x, wxCoord y, wxCoord w, wxCoord h)
{
m_refData = new wxRegionRefData();
GdkRegion *reg = gdk_region_new();
M_REGIONDATA->m_region = gdk_region_union_with_rect( reg, &rect );
gdk_region_destroy( reg );
#endif
-#if OLDCODE
- M_REGIONDATA->m_rects.Append( (wxObject*) new wxRect(x,y,w,h) );
-#endif
-}
-
-wxRegion::wxRegion( const wxPoint& topLeft, const wxPoint& bottomRight )
-{
- m_refData = new wxRegionRefData();
- GdkRegion *reg = gdk_region_new();
- GdkRectangle rect;
- rect.x = topLeft.x;
- rect.y = topLeft.y;
- rect.width = bottomRight.x - rect.x;
- rect.height = bottomRight.y - rect.y;
-#ifdef __WXGTK20__
- gdk_region_union_with_rect( reg, &rect );
- M_REGIONDATA->m_region = reg;
-#else
- M_REGIONDATA->m_region = gdk_region_union_with_rect( reg, &rect );
- gdk_region_destroy( reg );
-#endif
-#if OLDCODE
- M_REGIONDATA->m_rects.Append( (wxObject*) new wxRect(topLeft,bottomRight) );
-#endif
-}
-wxRegion::wxRegion( const wxRect& rect )
-{
- m_refData = new wxRegionRefData();
- GdkRegion *reg = gdk_region_new();
- GdkRectangle g_rect;
- g_rect.x = rect.x;
- g_rect.y = rect.y;
- g_rect.width = rect.width;
- g_rect.height = rect.height;
-#ifdef __WXGTK20__
- gdk_region_union_with_rect( reg, &g_rect );
- M_REGIONDATA->m_region = reg;
-#else
- M_REGIONDATA->m_region = gdk_region_union_with_rect( reg, &g_rect );
- gdk_region_destroy( reg );
-#endif
#if OLDCODE
- M_REGIONDATA->m_rects.Append( (wxObject*) new wxRect(rect.x,rect.y,rect.width,rect.height) );
+ M_REGIONDATA->m_rects.Append( (wxObject*) new wxRect(x, y, w, h) );
#endif
}
{
}
+// ----------------------------------------------------------------------------
+// wxRegion comparison
+// ----------------------------------------------------------------------------
+
bool wxRegion::operator==( const wxRegion& region )
{
- // VZ: compare the regions themselves, not the pointers to ref data!
+ // compare the regions themselves, not the pointers to ref data!
return gdk_region_equal(M_REGIONDATA->m_region,
M_REGIONDATA_OF(region)->m_region);
}
return !(*this == region);
}
-void wxRegion::Unshare()
-{
- if ( !m_refData )
- {
- m_refData = new wxRegionRefData;
- M_REGIONDATA->m_region = gdk_region_new();
- }
- else if ( m_refData->GetRefCount() > 1 )
- {
- wxRegionRefData *refData = new wxRegionRefData(*M_REGIONDATA);
- UnRef();
- m_refData = refData;
- }
- //else: we're not shared
-}
-
// ----------------------------------------------------------------------------
// wxRegion operations
// ----------------------------------------------------------------------------
}
else
{
- Unshare();
+ AllocExclusive();
#ifdef __WXGTK20__
gdk_region_union_with_rect( M_REGIONDATA->m_region, &rect );
if (region.IsNull())
return FALSE;
- Unshare();
+ AllocExclusive();
#ifdef __WXGTK20__
gdk_region_union( M_REGIONDATA->m_region, region.GetRegion() );
// if we called Intersect() itself recursively
bool wxRegion::IntersectRegionOnly(const wxRegion& region)
{
- Unshare();
+ AllocExclusive();
#ifdef __WXGTK20__
gdk_region_intersect( M_REGIONDATA->m_region, region.GetRegion() );
node = node->Next();
}
-#endif
+#endif // OLDCODE
+
return TRUE;
}
M_REGIONDATA->m_region = gdk_region_new();
}
- Unshare();
+ AllocExclusive();
#ifdef __WXGTK20__
gdk_region_subtract( M_REGIONDATA->m_region, region.GetRegion() );
}
else
{
- Unshare();
+ AllocExclusive();
}
#ifdef __WXGTK20__
M_REGIONDATA->m_rects.Append( (wxObject*) new wxRect(r->x,r->y,r->width,r->height) );
node = node->Next();
}
-#endif
+#endif // OLDCODE
return TRUE;
}
if (!m_refData)
return FALSE;
+ AllocExclusive();
+
gdk_region_offset( M_REGIONDATA->m_region, x, y );
-
+
return TRUE;
}
return r->height;
}
-#else
+#else // !OLDCODE
// the following structures must match the private structures
// in X11 region code ( xc/lib/X11/region.h )
return r;
}
-#endif
+#endif // OLDCODE/!OLDCODE