From 6d7ee9e860187240a5f82ec4489c831f894065f2 Mon Sep 17 00:00:00 2001 From: =?utf8?q?V=C3=A1clav=20Slav=C3=ADk?= Date: Sat, 9 Feb 2002 23:29:05 +0000 Subject: [PATCH] use AllocExclusive for reference counting git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@14093 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/mgl/brush.h | 7 +++-- include/wx/mgl/font.h | 9 +++--- include/wx/mgl/pen.h | 7 +++-- include/wx/mgl/region.h | 10 +++++-- src/mgl/brush.cpp | 26 +++++++---------- src/mgl/font.cpp | 33 ++++++++++----------- src/mgl/pen.cpp | 34 ++++++++++------------ src/mgl/region.cpp | 63 ++++++++++++++++++----------------------- 8 files changed, 90 insertions(+), 99 deletions(-) diff --git a/include/wx/mgl/brush.h b/include/wx/mgl/brush.h index 5d12600bad..325828bf16 100644 --- a/include/wx/mgl/brush.h +++ b/include/wx/mgl/brush.h @@ -56,11 +56,14 @@ public: // implementation: - void Unshare(); - void* GetMaskPattern() const; void* GetPixPattern() const; +protected: + // ref counting code + virtual wxObjectRefData *CreateRefData() const; + virtual wxObjectRefData *CloneRefData(const wxObjectRefData *data) const; + private: DECLARE_DYNAMIC_CLASS(wxBrush) }; diff --git a/include/wx/mgl/font.h b/include/wx/mgl/font.h index 4aed3d6dfb..0fcb960dd2 100644 --- a/include/wx/mgl/font.h +++ b/include/wx/mgl/font.h @@ -90,17 +90,16 @@ public: virtual void SetUnderlined(bool underlined); virtual void SetEncoding(wxFontEncoding encoding); - // implementation from now on - void Unshare(); - struct font_t *GetMGLfont_t(float scale, bool antialiased); - // no data :-) - protected: // common part of all ctors void Init() {} + // ref counting code + virtual wxObjectRefData *CreateRefData() const; + virtual wxObjectRefData *CloneRefData(const wxObjectRefData *data) const; + private: DECLARE_DYNAMIC_CLASS(wxFont) }; diff --git a/include/wx/mgl/pen.h b/include/wx/mgl/pen.h index 0441758301..d3c4459455 100644 --- a/include/wx/mgl/pen.h +++ b/include/wx/mgl/pen.h @@ -65,11 +65,14 @@ public: bool Ok() const; - void Unshare(); - // implementation: void* GetPixPattern() const; +protected: + // ref counting code + virtual wxObjectRefData *CreateRefData() const; + virtual wxObjectRefData *CloneRefData(const wxObjectRefData *data) const; + private: DECLARE_DYNAMIC_CLASS(wxPen) }; diff --git a/include/wx/mgl/region.h b/include/wx/mgl/region.h index 3f9e10461b..e5c33b61da 100644 --- a/include/wx/mgl/region.h +++ b/include/wx/mgl/region.h @@ -55,6 +55,8 @@ public: // 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); } @@ -97,9 +99,11 @@ public: // implementation from now on: const MGLRegion& GetMGLRegion() const; - -private: - void Unshare(); + +protected: + // ref counting code + virtual wxObjectRefData *CreateRefData() const; + virtual wxObjectRefData *CloneRefData(const wxObjectRefData *data) const; }; diff --git a/src/mgl/brush.cpp b/src/mgl/brush.cpp index 6bddd63b3b..92ba164307 100644 --- a/src/mgl/brush.cpp +++ b/src/mgl/brush.cpp @@ -223,25 +223,25 @@ void* wxBrush::GetPixPattern() const void wxBrush::SetColour(const wxColour& col) { - Unshare(); + AllocExclusive(); M_BRUSHDATA->m_colour = col; } void wxBrush::SetColour(unsigned char r, unsigned char g, unsigned char b) { - Unshare(); + AllocExclusive(); M_BRUSHDATA->m_colour.Set(r, g, b); } void wxBrush::SetStyle( int style ) { - Unshare(); + AllocExclusive(); M_BRUSHDATA->m_style = style; } void wxBrush::SetStipple(const wxBitmap& stipple) { - Unshare(); + AllocExclusive(); wxCHECK_RET( stipple.Ok(), _T("invalid bitmap") ); wxCHECK_RET( stipple.GetWidth() == 8 && stipple.GetHeight() == 8, @@ -257,17 +257,13 @@ void wxBrush::SetStipple(const wxBitmap& stipple) M_BRUSHDATA->m_style = wxSTIPPLE; } -void wxBrush::Unshare() +wxObjectRefData *wxBrush::CreateRefData() const { - if (!m_refData) - { - m_refData = new wxBrushRefData(); - } - else - { - wxBrushRefData* ref = new wxBrushRefData(*(wxBrushRefData*)m_refData); - UnRef(); - m_refData = ref; - } + return new wxBrushRefData; +} + +wxObjectRefData *wxBrush::CloneRefData(const wxObjectRefData *data) const +{ + return new wxBrushRefData(*(wxBrushRefData *)data); } diff --git a/src/mgl/font.cpp b/src/mgl/font.cpp index 3120a1d59f..b6d93684c1 100644 --- a/src/mgl/font.cpp +++ b/src/mgl/font.cpp @@ -192,20 +192,17 @@ struct font_t *wxFont::GetMGLfont_t(float scale, bool antialiased) return instance->GetMGLfont_t(); } -void wxFont::Unshare() +wxObjectRefData *wxFont::CreateRefData() const { - if ( !m_refData ) - { - m_refData = new wxFontRefData(); - } - else - { - wxFontRefData* ref = new wxFontRefData(*(wxFontRefData*)m_refData); - UnRef(); - m_refData = ref; - } + return new wxFontRefData; } +wxObjectRefData *wxFont::CloneRefData(const wxObjectRefData *data) const +{ + return new wxFontRefData(*(wxFontRefData *)data); +} + + // ---------------------------------------------------------------------------- // accessors // ---------------------------------------------------------------------------- @@ -274,7 +271,7 @@ bool wxFont::IsFixedWidth() const void wxFont::SetPointSize(int pointSize) { - Unshare(); + AllocExclusive(); M_FONTDATA->m_pointSize = pointSize; M_FONTDATA->m_valid = FALSE; @@ -282,7 +279,7 @@ void wxFont::SetPointSize(int pointSize) void wxFont::SetFamily(int family) { - Unshare(); + AllocExclusive(); M_FONTDATA->m_family = family; M_FONTDATA->m_valid = FALSE; @@ -290,7 +287,7 @@ void wxFont::SetFamily(int family) void wxFont::SetStyle(int style) { - Unshare(); + AllocExclusive(); M_FONTDATA->m_style = style; M_FONTDATA->m_valid = FALSE; @@ -298,7 +295,7 @@ void wxFont::SetStyle(int style) void wxFont::SetWeight(int weight) { - Unshare(); + AllocExclusive(); M_FONTDATA->m_weight = weight; M_FONTDATA->m_valid = FALSE; @@ -306,7 +303,7 @@ void wxFont::SetWeight(int weight) void wxFont::SetFaceName(const wxString& faceName) { - Unshare(); + AllocExclusive(); M_FONTDATA->m_faceName = faceName; M_FONTDATA->m_valid = FALSE; @@ -314,14 +311,14 @@ void wxFont::SetFaceName(const wxString& faceName) void wxFont::SetUnderlined(bool underlined) { - Unshare(); + AllocExclusive(); M_FONTDATA->m_underlined = underlined; } void wxFont::SetEncoding(wxFontEncoding encoding) { - Unshare(); + AllocExclusive(); M_FONTDATA->m_encoding = encoding; M_FONTDATA->m_valid = FALSE; diff --git a/src/mgl/pen.cpp b/src/mgl/pen.cpp index e46418d070..d7a3cb142a 100644 --- a/src/mgl/pen.cpp +++ b/src/mgl/pen.cpp @@ -131,38 +131,38 @@ bool wxPen::operator != (const wxPen& pen) const void wxPen::SetColour(const wxColour &colour) { - Unshare(); + AllocExclusive(); M_PENDATA->m_colour = colour; } void wxPen::SetDashes(int number_of_dashes, const wxDash *dash) { - Unshare(); + AllocExclusive(); M_PENDATA->m_countDashes = number_of_dashes; M_PENDATA->m_dash = (wxDash *)dash; /* TODO */ } void wxPen::SetColour(int red, int green, int blue) { - Unshare(); + AllocExclusive(); M_PENDATA->m_colour.Set(red, green, blue); } void wxPen::SetCap(int capStyle) { - Unshare(); + AllocExclusive(); M_PENDATA->m_capStyle = capStyle; } void wxPen::SetJoin(int joinStyle) { - Unshare(); + AllocExclusive(); M_PENDATA->m_joinStyle = joinStyle; } void wxPen::SetStyle(int style) { - Unshare(); + AllocExclusive(); M_PENDATA->m_style = style; } @@ -172,14 +172,14 @@ void wxPen::SetStipple(const wxBitmap& stipple) wxCHECK_RET( stipple.GetWidth() == 8 && stipple.GetHeight() == 8, _T("stipple bitmap must be 8x8") ); - Unshare(); + AllocExclusive(); M_PENDATA->m_stipple = stipple; wxBitmapToPixPattern(stipple, &(M_PENDATA->m_pixPattern), NULL); } void wxPen::SetWidth(int width) { - Unshare(); + AllocExclusive(); M_PENDATA->m_width = width; } @@ -254,17 +254,13 @@ bool wxPen::Ok() const return (m_refData != NULL); } -void wxPen::Unshare() +wxObjectRefData *wxPen::CreateRefData() const { - if (!m_refData) - { - m_refData = new wxPenRefData(); - } - else - { - wxPenRefData* ref = new wxPenRefData( *(wxPenRefData*)m_refData ); - UnRef(); - m_refData = ref; - } + return new wxPenRefData; +} + +wxObjectRefData *wxPen::CloneRefData(const wxObjectRefData *data) const +{ + return new wxPenRefData(*(wxPenRefData *)data); } diff --git a/src/mgl/region.cpp b/src/mgl/region.cpp index 2002add8b8..a3f2b9b0c6 100644 --- a/src/mgl/region.cpp +++ b/src/mgl/region.cpp @@ -37,18 +37,14 @@ IMPLEMENT_DYNAMIC_CLASS(wxRegionIterator, wxObject) class WXDLLEXPORT wxRegionRefData : public wxGDIRefData { public: - wxRegionRefData() - { - } + wxRegionRefData() {} wxRegionRefData(const wxRegionRefData& data) { m_region = data.m_region; } - ~wxRegionRefData() - { - } + ~wxRegionRefData() {} MGLRegion m_region; }; @@ -60,12 +56,22 @@ public: // wxRegion //----------------------------------------------------------------------------- +wxObjectRefData *wxRegion::CreateRefData() const +{ + return new wxRegionRefData; +} + +wxObjectRefData *wxRegion::CloneRefData(const wxObjectRefData *data) const +{ + return new wxRegionRefData(*(wxRegionRefData *)data); +} + /* * Create an empty region. */ wxRegion::wxRegion() { - m_refData = (wxRegionRefData *)NULL; + m_refData = NULL; } wxRegion::wxRegion(wxCoord x, wxCoord y, wxCoord w, wxCoord h) @@ -156,17 +162,24 @@ bool wxRegion::Empty() const // Modifications //----------------------------------------------------------------------------- +bool wxRegion::Offset(wxCoord x, wxCoord y) +{ + AllocExclusive(); + M_REGION.offset(x, y); + return TRUE; +} + // Union rectangle or region with this. bool wxRegion::Union(wxCoord x, wxCoord y, wxCoord width, wxCoord height) { - Unshare(); + AllocExclusive(); M_REGION += MGLRect(x, y, x + width, y + height); return TRUE; } bool wxRegion::Union(const wxRegion& region) { - Unshare(); + AllocExclusive(); M_REGION += M_REGION_OF(region); return TRUE; } @@ -174,14 +187,14 @@ bool wxRegion::Union(const wxRegion& region) // Intersect rectangle or region with this. bool wxRegion::Intersect(wxCoord x, wxCoord y, wxCoord width, wxCoord height) { - Unshare(); + AllocExclusive(); M_REGION &= MGLRect(x, y, x + width, y + height); return TRUE; } bool wxRegion::Intersect(const wxRegion& region) { - Unshare(); + AllocExclusive(); M_REGION &= M_REGION_OF(region); return TRUE; } @@ -190,14 +203,14 @@ bool wxRegion::Intersect(const wxRegion& region) // Combines the parts of 'this' that are not part of the second region. bool wxRegion::Subtract(wxCoord x, wxCoord y, wxCoord width, wxCoord height) { - Unshare(); + AllocExclusive(); M_REGION -= MGLRect(x, y, x + width, y + height); return TRUE; } bool wxRegion::Subtract(const wxRegion& region) { - Unshare(); + AllocExclusive(); M_REGION -= M_REGION_OF(region); return TRUE; } @@ -205,7 +218,7 @@ bool wxRegion::Subtract(const wxRegion& region) // XOR: the union of two combined regions except for any overlapping areas. bool wxRegion::Xor(wxCoord x, wxCoord y, wxCoord width, wxCoord height) { - Unshare(); + AllocExclusive(); MGLRect rect(x, y, x + width, y + height); MGLRegion rg1 = M_REGION + rect, rg2 = M_REGION & rect; @@ -215,7 +228,7 @@ bool wxRegion::Xor(wxCoord x, wxCoord y, wxCoord width, wxCoord height) bool wxRegion::Xor(const wxRegion& region) { - Unshare(); + AllocExclusive(); MGLRegion rg1 = M_REGION + M_REGION_OF(region), rg2 = M_REGION & M_REGION_OF(region); M_REGION = rg1 - rg2; @@ -273,25 +286,6 @@ wxRegionContain wxRegion::Contains(const wxRect& rect) const } - -void wxRegion::Unshare() -{ - if (!m_refData) - { - m_refData = new wxRegionRefData(); - } - else - { - wxRegionRefData* ref = new wxRegionRefData(*(wxRegionRefData*)m_refData); - UnRef(); - m_refData = ref; - } -} - - - - - /////////////////////////////////////////////////////////////////////////////// // wxRegionIterator // /////////////////////////////////////////////////////////////////////////////// @@ -396,4 +390,3 @@ wxCoord wxRegionIterator::GetH() const else return 0; } - -- 2.45.2