use AllocExclusive for reference counting

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@14093 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Václav Slavík
2002-02-09 23:29:05 +00:00
parent 5c235ea098
commit 6d7ee9e860
8 changed files with 90 additions and 99 deletions

View File

@@ -56,11 +56,14 @@ public:
// implementation: // implementation:
void Unshare();
void* GetMaskPattern() const; void* GetMaskPattern() const;
void* GetPixPattern() const; void* GetPixPattern() const;
protected:
// ref counting code
virtual wxObjectRefData *CreateRefData() const;
virtual wxObjectRefData *CloneRefData(const wxObjectRefData *data) const;
private: private:
DECLARE_DYNAMIC_CLASS(wxBrush) DECLARE_DYNAMIC_CLASS(wxBrush)
}; };

View File

@@ -90,17 +90,16 @@ public:
virtual void SetUnderlined(bool underlined); virtual void SetUnderlined(bool underlined);
virtual void SetEncoding(wxFontEncoding encoding); virtual void SetEncoding(wxFontEncoding encoding);
// implementation from now on
void Unshare();
struct font_t *GetMGLfont_t(float scale, bool antialiased); struct font_t *GetMGLfont_t(float scale, bool antialiased);
// no data :-)
protected: protected:
// common part of all ctors // common part of all ctors
void Init() {} void Init() {}
// ref counting code
virtual wxObjectRefData *CreateRefData() const;
virtual wxObjectRefData *CloneRefData(const wxObjectRefData *data) const;
private: private:
DECLARE_DYNAMIC_CLASS(wxFont) DECLARE_DYNAMIC_CLASS(wxFont)
}; };

View File

@@ -65,11 +65,14 @@ public:
bool Ok() const; bool Ok() const;
void Unshare();
// implementation: // implementation:
void* GetPixPattern() const; void* GetPixPattern() const;
protected:
// ref counting code
virtual wxObjectRefData *CreateRefData() const;
virtual wxObjectRefData *CloneRefData(const wxObjectRefData *data) const;
private: private:
DECLARE_DYNAMIC_CLASS(wxPen) DECLARE_DYNAMIC_CLASS(wxPen)
}; };

View File

@@ -55,6 +55,8 @@ public:
// Clear current region // Clear current region
void Clear(void); void Clear(void);
bool Offset(wxCoord x, wxCoord y);
// Union rectangle or region with this. // Union rectangle or region with this.
bool Union(wxCoord x, wxCoord y, wxCoord width, wxCoord height); 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 wxRect& rect) { return Union(rect.x, rect.y, rect.width, rect.height); }
@@ -97,9 +99,11 @@ public:
// implementation from now on: // implementation from now on:
const MGLRegion& GetMGLRegion() const; const MGLRegion& GetMGLRegion() const;
private: protected:
void Unshare(); // ref counting code
virtual wxObjectRefData *CreateRefData() const;
virtual wxObjectRefData *CloneRefData(const wxObjectRefData *data) const;
}; };

View File

@@ -223,25 +223,25 @@ void* wxBrush::GetPixPattern() const
void wxBrush::SetColour(const wxColour& col) void wxBrush::SetColour(const wxColour& col)
{ {
Unshare(); AllocExclusive();
M_BRUSHDATA->m_colour = col; M_BRUSHDATA->m_colour = col;
} }
void wxBrush::SetColour(unsigned char r, unsigned char g, unsigned char b) void wxBrush::SetColour(unsigned char r, unsigned char g, unsigned char b)
{ {
Unshare(); AllocExclusive();
M_BRUSHDATA->m_colour.Set(r, g, b); M_BRUSHDATA->m_colour.Set(r, g, b);
} }
void wxBrush::SetStyle( int style ) void wxBrush::SetStyle( int style )
{ {
Unshare(); AllocExclusive();
M_BRUSHDATA->m_style = style; M_BRUSHDATA->m_style = style;
} }
void wxBrush::SetStipple(const wxBitmap& stipple) void wxBrush::SetStipple(const wxBitmap& stipple)
{ {
Unshare(); AllocExclusive();
wxCHECK_RET( stipple.Ok(), _T("invalid bitmap") ); wxCHECK_RET( stipple.Ok(), _T("invalid bitmap") );
wxCHECK_RET( stipple.GetWidth() == 8 && stipple.GetHeight() == 8, wxCHECK_RET( stipple.GetWidth() == 8 && stipple.GetHeight() == 8,
@@ -257,17 +257,13 @@ void wxBrush::SetStipple(const wxBitmap& stipple)
M_BRUSHDATA->m_style = wxSTIPPLE; M_BRUSHDATA->m_style = wxSTIPPLE;
} }
void wxBrush::Unshare() wxObjectRefData *wxBrush::CreateRefData() const
{ {
if (!m_refData) return new wxBrushRefData;
{ }
m_refData = new wxBrushRefData();
} wxObjectRefData *wxBrush::CloneRefData(const wxObjectRefData *data) const
else {
{ return new wxBrushRefData(*(wxBrushRefData *)data);
wxBrushRefData* ref = new wxBrushRefData(*(wxBrushRefData*)m_refData);
UnRef();
m_refData = ref;
}
} }

View File

@@ -192,20 +192,17 @@ struct font_t *wxFont::GetMGLfont_t(float scale, bool antialiased)
return instance->GetMGLfont_t(); return instance->GetMGLfont_t();
} }
void wxFont::Unshare() wxObjectRefData *wxFont::CreateRefData() const
{ {
if ( !m_refData ) return new wxFontRefData;
{
m_refData = new wxFontRefData();
}
else
{
wxFontRefData* ref = new wxFontRefData(*(wxFontRefData*)m_refData);
UnRef();
m_refData = ref;
}
} }
wxObjectRefData *wxFont::CloneRefData(const wxObjectRefData *data) const
{
return new wxFontRefData(*(wxFontRefData *)data);
}
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// accessors // accessors
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@@ -274,7 +271,7 @@ bool wxFont::IsFixedWidth() const
void wxFont::SetPointSize(int pointSize) void wxFont::SetPointSize(int pointSize)
{ {
Unshare(); AllocExclusive();
M_FONTDATA->m_pointSize = pointSize; M_FONTDATA->m_pointSize = pointSize;
M_FONTDATA->m_valid = FALSE; M_FONTDATA->m_valid = FALSE;
@@ -282,7 +279,7 @@ void wxFont::SetPointSize(int pointSize)
void wxFont::SetFamily(int family) void wxFont::SetFamily(int family)
{ {
Unshare(); AllocExclusive();
M_FONTDATA->m_family = family; M_FONTDATA->m_family = family;
M_FONTDATA->m_valid = FALSE; M_FONTDATA->m_valid = FALSE;
@@ -290,7 +287,7 @@ void wxFont::SetFamily(int family)
void wxFont::SetStyle(int style) void wxFont::SetStyle(int style)
{ {
Unshare(); AllocExclusive();
M_FONTDATA->m_style = style; M_FONTDATA->m_style = style;
M_FONTDATA->m_valid = FALSE; M_FONTDATA->m_valid = FALSE;
@@ -298,7 +295,7 @@ void wxFont::SetStyle(int style)
void wxFont::SetWeight(int weight) void wxFont::SetWeight(int weight)
{ {
Unshare(); AllocExclusive();
M_FONTDATA->m_weight = weight; M_FONTDATA->m_weight = weight;
M_FONTDATA->m_valid = FALSE; M_FONTDATA->m_valid = FALSE;
@@ -306,7 +303,7 @@ void wxFont::SetWeight(int weight)
void wxFont::SetFaceName(const wxString& faceName) void wxFont::SetFaceName(const wxString& faceName)
{ {
Unshare(); AllocExclusive();
M_FONTDATA->m_faceName = faceName; M_FONTDATA->m_faceName = faceName;
M_FONTDATA->m_valid = FALSE; M_FONTDATA->m_valid = FALSE;
@@ -314,14 +311,14 @@ void wxFont::SetFaceName(const wxString& faceName)
void wxFont::SetUnderlined(bool underlined) void wxFont::SetUnderlined(bool underlined)
{ {
Unshare(); AllocExclusive();
M_FONTDATA->m_underlined = underlined; M_FONTDATA->m_underlined = underlined;
} }
void wxFont::SetEncoding(wxFontEncoding encoding) void wxFont::SetEncoding(wxFontEncoding encoding)
{ {
Unshare(); AllocExclusive();
M_FONTDATA->m_encoding = encoding; M_FONTDATA->m_encoding = encoding;
M_FONTDATA->m_valid = FALSE; M_FONTDATA->m_valid = FALSE;

View File

@@ -131,38 +131,38 @@ bool wxPen::operator != (const wxPen& pen) const
void wxPen::SetColour(const wxColour &colour) void wxPen::SetColour(const wxColour &colour)
{ {
Unshare(); AllocExclusive();
M_PENDATA->m_colour = colour; M_PENDATA->m_colour = colour;
} }
void wxPen::SetDashes(int number_of_dashes, const wxDash *dash) void wxPen::SetDashes(int number_of_dashes, const wxDash *dash)
{ {
Unshare(); AllocExclusive();
M_PENDATA->m_countDashes = number_of_dashes; M_PENDATA->m_countDashes = number_of_dashes;
M_PENDATA->m_dash = (wxDash *)dash; /* TODO */ M_PENDATA->m_dash = (wxDash *)dash; /* TODO */
} }
void wxPen::SetColour(int red, int green, int blue) void wxPen::SetColour(int red, int green, int blue)
{ {
Unshare(); AllocExclusive();
M_PENDATA->m_colour.Set(red, green, blue); M_PENDATA->m_colour.Set(red, green, blue);
} }
void wxPen::SetCap(int capStyle) void wxPen::SetCap(int capStyle)
{ {
Unshare(); AllocExclusive();
M_PENDATA->m_capStyle = capStyle; M_PENDATA->m_capStyle = capStyle;
} }
void wxPen::SetJoin(int joinStyle) void wxPen::SetJoin(int joinStyle)
{ {
Unshare(); AllocExclusive();
M_PENDATA->m_joinStyle = joinStyle; M_PENDATA->m_joinStyle = joinStyle;
} }
void wxPen::SetStyle(int style) void wxPen::SetStyle(int style)
{ {
Unshare(); AllocExclusive();
M_PENDATA->m_style = style; M_PENDATA->m_style = style;
} }
@@ -172,14 +172,14 @@ void wxPen::SetStipple(const wxBitmap& stipple)
wxCHECK_RET( stipple.GetWidth() == 8 && stipple.GetHeight() == 8, wxCHECK_RET( stipple.GetWidth() == 8 && stipple.GetHeight() == 8,
_T("stipple bitmap must be 8x8") ); _T("stipple bitmap must be 8x8") );
Unshare(); AllocExclusive();
M_PENDATA->m_stipple = stipple; M_PENDATA->m_stipple = stipple;
wxBitmapToPixPattern(stipple, &(M_PENDATA->m_pixPattern), NULL); wxBitmapToPixPattern(stipple, &(M_PENDATA->m_pixPattern), NULL);
} }
void wxPen::SetWidth(int width) void wxPen::SetWidth(int width)
{ {
Unshare(); AllocExclusive();
M_PENDATA->m_width = width; M_PENDATA->m_width = width;
} }
@@ -254,17 +254,13 @@ bool wxPen::Ok() const
return (m_refData != NULL); return (m_refData != NULL);
} }
void wxPen::Unshare() wxObjectRefData *wxPen::CreateRefData() const
{ {
if (!m_refData) return new wxPenRefData;
{ }
m_refData = new wxPenRefData();
} wxObjectRefData *wxPen::CloneRefData(const wxObjectRefData *data) const
else {
{ return new wxPenRefData(*(wxPenRefData *)data);
wxPenRefData* ref = new wxPenRefData( *(wxPenRefData*)m_refData );
UnRef();
m_refData = ref;
}
} }

View File

@@ -37,18 +37,14 @@ IMPLEMENT_DYNAMIC_CLASS(wxRegionIterator, wxObject)
class WXDLLEXPORT wxRegionRefData : public wxGDIRefData class WXDLLEXPORT wxRegionRefData : public wxGDIRefData
{ {
public: public:
wxRegionRefData() wxRegionRefData() {}
{
}
wxRegionRefData(const wxRegionRefData& data) wxRegionRefData(const wxRegionRefData& data)
{ {
m_region = data.m_region; m_region = data.m_region;
} }
~wxRegionRefData() ~wxRegionRefData() {}
{
}
MGLRegion m_region; MGLRegion m_region;
}; };
@@ -60,12 +56,22 @@ public:
// wxRegion // wxRegion
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
wxObjectRefData *wxRegion::CreateRefData() const
{
return new wxRegionRefData;
}
wxObjectRefData *wxRegion::CloneRefData(const wxObjectRefData *data) const
{
return new wxRegionRefData(*(wxRegionRefData *)data);
}
/* /*
* Create an empty region. * Create an empty region.
*/ */
wxRegion::wxRegion() wxRegion::wxRegion()
{ {
m_refData = (wxRegionRefData *)NULL; m_refData = NULL;
} }
wxRegion::wxRegion(wxCoord x, wxCoord y, wxCoord w, wxCoord h) wxRegion::wxRegion(wxCoord x, wxCoord y, wxCoord w, wxCoord h)
@@ -156,17 +162,24 @@ bool wxRegion::Empty() const
// Modifications // Modifications
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
bool wxRegion::Offset(wxCoord x, wxCoord y)
{
AllocExclusive();
M_REGION.offset(x, y);
return TRUE;
}
// Union rectangle or region with this. // Union rectangle or region with this.
bool wxRegion::Union(wxCoord x, wxCoord y, wxCoord width, wxCoord height) bool wxRegion::Union(wxCoord x, wxCoord y, wxCoord width, wxCoord height)
{ {
Unshare(); AllocExclusive();
M_REGION += MGLRect(x, y, x + width, y + height); M_REGION += MGLRect(x, y, x + width, y + height);
return TRUE; return TRUE;
} }
bool wxRegion::Union(const wxRegion& region) bool wxRegion::Union(const wxRegion& region)
{ {
Unshare(); AllocExclusive();
M_REGION += M_REGION_OF(region); M_REGION += M_REGION_OF(region);
return TRUE; return TRUE;
} }
@@ -174,14 +187,14 @@ bool wxRegion::Union(const wxRegion& region)
// Intersect rectangle or region with this. // Intersect rectangle or region with this.
bool wxRegion::Intersect(wxCoord x, wxCoord y, wxCoord width, wxCoord height) bool wxRegion::Intersect(wxCoord x, wxCoord y, wxCoord width, wxCoord height)
{ {
Unshare(); AllocExclusive();
M_REGION &= MGLRect(x, y, x + width, y + height); M_REGION &= MGLRect(x, y, x + width, y + height);
return TRUE; return TRUE;
} }
bool wxRegion::Intersect(const wxRegion& region) bool wxRegion::Intersect(const wxRegion& region)
{ {
Unshare(); AllocExclusive();
M_REGION &= M_REGION_OF(region); M_REGION &= M_REGION_OF(region);
return TRUE; 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. // Combines the parts of 'this' that are not part of the second region.
bool wxRegion::Subtract(wxCoord x, wxCoord y, wxCoord width, wxCoord height) bool wxRegion::Subtract(wxCoord x, wxCoord y, wxCoord width, wxCoord height)
{ {
Unshare(); AllocExclusive();
M_REGION -= MGLRect(x, y, x + width, y + height); M_REGION -= MGLRect(x, y, x + width, y + height);
return TRUE; return TRUE;
} }
bool wxRegion::Subtract(const wxRegion& region) bool wxRegion::Subtract(const wxRegion& region)
{ {
Unshare(); AllocExclusive();
M_REGION -= M_REGION_OF(region); M_REGION -= M_REGION_OF(region);
return TRUE; return TRUE;
} }
@@ -205,7 +218,7 @@ bool wxRegion::Subtract(const wxRegion& region)
// XOR: the union of two combined regions except for any overlapping areas. // XOR: the union of two combined regions except for any overlapping areas.
bool wxRegion::Xor(wxCoord x, wxCoord y, wxCoord width, wxCoord height) bool wxRegion::Xor(wxCoord x, wxCoord y, wxCoord width, wxCoord height)
{ {
Unshare(); AllocExclusive();
MGLRect rect(x, y, x + width, y + height); MGLRect rect(x, y, x + width, y + height);
MGLRegion rg1 = M_REGION + rect, MGLRegion rg1 = M_REGION + rect,
rg2 = 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) bool wxRegion::Xor(const wxRegion& region)
{ {
Unshare(); AllocExclusive();
MGLRegion rg1 = M_REGION + M_REGION_OF(region), MGLRegion rg1 = M_REGION + M_REGION_OF(region),
rg2 = M_REGION & M_REGION_OF(region); rg2 = M_REGION & M_REGION_OF(region);
M_REGION = rg1 - rg2; 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 // // wxRegionIterator //
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
@@ -396,4 +390,3 @@ wxCoord wxRegionIterator::GetH() const
else else
return 0; return 0;
} }