]> git.saurik.com Git - wxWidgets.git/commitdiff
use AllocExclusive for reference counting
authorVáclav Slavík <vslavik@fastmail.fm>
Sat, 9 Feb 2002 23:29:05 +0000 (23:29 +0000)
committerVáclav Slavík <vslavik@fastmail.fm>
Sat, 9 Feb 2002 23:29:05 +0000 (23:29 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@14093 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/mgl/brush.h
include/wx/mgl/font.h
include/wx/mgl/pen.h
include/wx/mgl/region.h
src/mgl/brush.cpp
src/mgl/font.cpp
src/mgl/pen.cpp
src/mgl/region.cpp

index 5d12600bad1b903dc98b18c1b17e691468d8f484..325828bf16ff17a0441471ad874cbae2088b3b81 100644 (file)
@@ -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)
 };
index 4aed3d6dfb59041a6c4c2039a417c2346b1aa302..0fcb960dd26f429cf691d43c032868fc58bfabfa 100644 (file)
@@ -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)
 };
index 04417583010bdc9b49d800e9726c360e50d132b5..d3c44594554e150115f93091b63d6485c7b02b41 100644 (file)
@@ -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)
 };
index 3f9e10461baf721551de6e137c3deaffe3ede4dd..e5c33b61da188d15471cda66bc600b3e4af7e6c8 100644 (file)
@@ -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;
 };
 
 
index 6bddd63b3b2b3e926d972f2ca1b79fe6248a2930..92ba1643072ab584a24220083df151f8fab30213 100644 (file)
@@ -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);
 }
 
index 3120a1d59f097a0c2ff4b6c1a99f1f6095930e88..b6d93684c166ffdd22bbf262e314f1cfe481306d 100644 (file)
@@ -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;
index e46418d07067f6967f53c9c68366b28029cfd2d8..d7a3cb142afb9d5e3dfee40af3c9018f8172ba99 100644 (file)
@@ -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);
 }
 
index 2002add8b896bce706914540840cbf76c3b5c6db..a3f2b9b0c619669038c58a31faa7a6b7aaf63987 100644 (file)
@@ -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;
 }
-