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:
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)
};

View 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)
};

View 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)
};

View 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;
};

View 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);
}

View 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;

View 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);
}

View 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;
}