#include "wx/gtk/private.h"
+#ifndef __WXGTK20__
+
+// ----------------------------------------------------------------------------
+// wxGdkRegion: creates a new region in ctor and destroys in dtor
+// ----------------------------------------------------------------------------
+
+class wxGdkRegion
+{
+public:
+ wxGdkRegion() { m_region = gdk_region_new(); }
+ ~wxGdkRegion() { gdk_region_destroy(m_region); }
+
+ operator GdkRegion *() const { return m_region; }
+
+private:
+ GdkRegion *m_region;
+};
+
+#endif // __WXGTK20__
+
// ----------------------------------------------------------------------------
// wxRegionRefData: private class containing the information about the region
// ----------------------------------------------------------------------------
{
m_region = NULL;
}
-
+
wxRegionRefData(const wxRegionRefData& refData)
+ : wxObjectRefData()
{
#ifdef __WXGTK20__
m_region = gdk_region_copy(refData.m_region);
#else
- m_region = gdk_region_new();
- GdkRegion *regCopy = gdk_regions_union(m_region, refData.m_region);
- gdk_region_destroy(m_region);
- m_region = regCopy;
+ m_region = gdk_regions_union(wxGdkRegion(), refData.m_region);
#endif
}
-
+
~wxRegionRefData()
{
if (m_region)
#define M_REGIONDATA ((wxRegionRefData *)m_refData)
#define M_REGIONDATA_OF(rgn) ((wxRegionRefData *)(rgn.m_refData))
-IMPLEMENT_DYNAMIC_CLASS(wxRegion, wxGDIObject);
-IMPLEMENT_DYNAMIC_CLASS(wxRegionIterator,wxObject);
+IMPLEMENT_DYNAMIC_CLASS(wxRegion, wxGDIObject)
+IMPLEMENT_DYNAMIC_CLASS(wxRegionIterator,wxObject)
// ----------------------------------------------------------------------------
// wxRegion construction
rect.y = y;
rect.width = w;
rect.height = h;
-
+
m_refData = new wxRegionRefData();
-
+
#ifdef __WXGTK20__
M_REGIONDATA->m_region = gdk_region_rectangle( &rect );
#else
- GdkRegion *reg = gdk_region_new();
- M_REGIONDATA->m_region = gdk_region_union_with_rect( reg, &rect );
- gdk_region_destroy( reg );
+ M_REGIONDATA->m_region = gdk_region_union_with_rect( wxGdkRegion(), &rect );
+#endif
+}
+
+wxRegion::wxRegion( GdkRegion *region )
+{
+ m_refData = new wxRegionRefData();
+#ifdef __WXGTK20__
+ M_REGIONDATA->m_region = gdk_region_copy( region );
+#else
+ M_REGIONDATA->m_region = gdk_regions_union(wxGdkRegion(), region);
#endif
}
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);
rect.y = y;
rect.width = width;
rect.height = height;
-
+
if (!m_refData)
{
m_refData = new wxRegionRefData();
#ifdef __WXGTK20__
M_REGIONDATA->m_region = gdk_region_rectangle( &rect );
#else
- GdkRegion *reg = gdk_region_new();
- M_REGIONDATA->m_region = gdk_region_union_with_rect( reg, &rect );
- gdk_region_destroy( reg );
+ M_REGIONDATA->m_region = gdk_region_union_with_rect(wxGdkRegion(), &rect);
#endif
}
else
bool wxRegion::Intersect( const wxRect& rect )
{
wxRegion reg( rect );
-
+
return Intersect( reg );
}
{
m_refData = new wxRegionRefData();
M_REGIONDATA->m_region = gdk_region_new();
-
- // leave here
+
+ // leave here
return TRUE;
}
else
class wxRIRefData: public wxObjectRefData
{
public:
+ wxRIRefData() { Init(); }
+ virtual ~wxRIRefData();
+
+ void CreateRects( const wxRegion& r );
- wxRIRefData() : m_rects(0), m_numRects(0){}
- ~wxRIRefData();
+ void Init() { m_rects = NULL; m_numRects = 0; }
wxRect *m_rects;
size_t m_numRects;
-
- void CreateRects( const wxRegion& r );
};
wxRIRefData::~wxRIRefData()
{
- delete m_rects;
+ delete [] m_rects;
}
void wxRIRefData::CreateRects( const wxRegion& region )
{
- if (m_rects)
- delete m_rects;
+ delete [] m_rects;
+
+ Init();
- m_rects = 0;
- m_numRects = 0;
-
GdkRegion *gdkregion = region.GetRegion();
- if (!gdkregion) return;
-
+ if (!gdkregion)
+ return;
+
#ifdef __WXGTK20__
GdkRectangle *gdkrects = NULL;
gint numRects = 0;
gdk_region_get_rectangles( gdkregion, &gdkrects, &numRects );
-
+
m_numRects = numRects;
if (numRects)
{