X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/b2aef89b7a675805b601e757492c982031f38d21..6244848856584171db8cd74a7ff227250e46cc54:/src/msw/brush.cpp diff --git a/src/msw/brush.cpp b/src/msw/brush.cpp index f9043c2e1d..4a46f5c0b4 100644 --- a/src/msw/brush.cpp +++ b/src/msw/brush.cpp @@ -40,7 +40,14 @@ IMPLEMENT_DYNAMIC_CLASS(wxBrush, wxGDIObject) wxBrushRefData::wxBrushRefData(void) { m_style = wxSOLID; -// m_stipple = NULL ; + m_hBrush = 0; +} + +wxBrushRefData::wxBrushRefData(const wxBrushRefData& data) +{ + m_style = data.m_style; + m_stipple = data.m_stipple; + m_colour = data.m_colour; m_hBrush = 0; } @@ -77,20 +84,6 @@ wxBrush::wxBrush(const wxColour& col, int Style) wxTheBrushList->AddBrush(this); } -wxBrush::wxBrush(const wxString& col, int Style) -{ - m_refData = new wxBrushRefData; - - M_BRUSHDATA->m_colour = col; - M_BRUSHDATA->m_style = Style; - M_BRUSHDATA->m_hBrush = 0; - - RealizeResource(); - - if ( wxTheBrushList ) - wxTheBrushList->AddBrush(this); -} - wxBrush::wxBrush(const wxBitmap& stipple) { m_refData = new wxBrushRefData; @@ -186,77 +179,60 @@ bool wxBrush::FreeResource(bool force) else return FALSE; } -/* -bool wxBrush::UseResource(void) -{ - IncrementResourceUsage(); - return TRUE; -} - -bool wxBrush::ReleaseResource(void) -{ - DecrementResourceUsage(); - return TRUE; -} -*/ - bool wxBrush::IsFree(void) { return (M_BRUSHDATA && (M_BRUSHDATA->m_hBrush == 0)); } -void wxBrush::SetColour(const wxColour& col) +void wxBrush::Unshare() { - if ( !M_BRUSHDATA ) - m_refData = new wxBrushRefData; - - M_BRUSHDATA->m_colour = col; - - if (FreeResource()) - RealizeResource(); + // Don't change shared data + if (!m_refData) + { + m_refData = new wxBrushRefData(); + } + else + { + wxBrushRefData* ref = new wxBrushRefData(*(wxBrushRefData*)m_refData); + UnRef(); + m_refData = ref; + } } -void wxBrush::SetColour(const wxString& col) + +void wxBrush::SetColour(const wxColour& col) { - if ( !M_BRUSHDATA ) - m_refData = new wxBrushRefData; + Unshare(); - M_BRUSHDATA->m_colour = col; + M_BRUSHDATA->m_colour = col; - if (FreeResource()) RealizeResource(); } -void wxBrush::SetColour(const unsigned char r, const unsigned char g, const unsigned char b) +void wxBrush::SetColour(unsigned char r, unsigned char g, unsigned char b) { - if ( !M_BRUSHDATA ) - m_refData = new wxBrushRefData; + Unshare(); - M_BRUSHDATA->m_colour.Set(r, g, b); + M_BRUSHDATA->m_colour.Set(r, g, b); - if (FreeResource()) RealizeResource(); } void wxBrush::SetStyle(int Style) { - if ( !M_BRUSHDATA ) - m_refData = new wxBrushRefData; + Unshare(); - M_BRUSHDATA->m_style = Style; + M_BRUSHDATA->m_style = Style; - if (FreeResource()) RealizeResource(); } void wxBrush::SetStipple(const wxBitmap& Stipple) { - if ( !M_BRUSHDATA ) - m_refData = new wxBrushRefData; + Unshare(); - M_BRUSHDATA->m_stipple = Stipple; + M_BRUSHDATA->m_stipple = Stipple; - if (FreeResource()) RealizeResource(); }