X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/83df96d63a52ebb08b9e32549dc255354b4a18d0..ce7208d49d5ce2ca1dc0b3b83f14f1d04f29c4bf:/src/x11/brush.cpp diff --git a/src/x11/brush.cpp b/src/x11/brush.cpp index 685b376427..685c12b747 100644 --- a/src/x11/brush.cpp +++ b/src/x11/brush.cpp @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: src/motif/brush.cpp +// Name: src/x11/brush.cpp // Purpose: wxBrush // Author: Julian Smart // Modified by: @@ -9,115 +9,163 @@ // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// -#ifdef __GNUG__ -#pragma implementation "brush.h" -#endif +// for compilers that support precompilation, includes "wx.h". +#include "wx/wxprec.h" -#include "wx/setup.h" -#include "wx/utils.h" #include "wx/brush.h" -IMPLEMENT_DYNAMIC_CLASS(wxBrush, wxGDIObject) +#ifndef WX_PRECOMP + #include "wx/utils.h" + #include "wx/bitmap.h" + #include "wx/colour.h" +#endif -wxBrushRefData::wxBrushRefData() -{ - m_style = wxSOLID; -} +//----------------------------------------------------------------------------- +// wxBrush +//----------------------------------------------------------------------------- -wxBrushRefData::wxBrushRefData(const wxBrushRefData& data) +class wxBrushRefData: public wxObjectRefData { - m_style = data.m_style; - m_stipple = data.m_stipple; - m_colour = data.m_colour; -} +public: + wxBrushRefData() + { + m_style = 0; + } + + wxBrushRefData( const wxBrushRefData& data ) + { + m_style = data.m_style; + m_stipple = data.m_stipple; + m_colour = data.m_colour; + } + + bool operator == (const wxBrushRefData& data) const + { + return (m_style == data.m_style && + m_stipple == data.m_stipple && + m_colour == data.m_colour); + } + + int m_style; + wxColour m_colour; + wxBitmap m_stipple; +}; + +//----------------------------------------------------------------------------- -wxBrushRefData::~wxBrushRefData() +#define M_BRUSHDATA ((wxBrushRefData *)m_refData) + +IMPLEMENT_DYNAMIC_CLASS(wxBrush,wxGDIObject) + +wxBrush::wxBrush( const wxColour &colour, int style ) { + m_refData = new wxBrushRefData(); + M_BRUSHDATA->m_style = style; + M_BRUSHDATA->m_colour = colour; } -// Brushes -wxBrush::wxBrush() +wxBrush::wxBrush( const wxBitmap &stippleBitmap ) { + m_refData = new wxBrushRefData(); + M_BRUSHDATA->m_colour = *wxBLACK; + + M_BRUSHDATA->m_stipple = stippleBitmap; + + if (M_BRUSHDATA->m_stipple.GetMask()) + M_BRUSHDATA->m_style = wxSTIPPLE_MASK_OPAQUE; + else + M_BRUSHDATA->m_style = wxSTIPPLE; } wxBrush::~wxBrush() { + // m_refData unrefed in ~wxObject } -wxBrush::wxBrush(const wxColour& col, int Style) +wxObjectRefData *wxBrush::CreateRefData() const { - m_refData = new wxBrushRefData; - - M_BRUSHDATA->m_colour = col; - M_BRUSHDATA->m_style = Style; + return new wxBrushRefData; +} - RealizeResource(); +wxObjectRefData *wxBrush::CloneRefData(const wxObjectRefData *data) const +{ + return new wxBrushRefData(*(wxBrushRefData *)data); } -wxBrush::wxBrush(const wxBitmap& stipple) +bool wxBrush::operator == ( const wxBrush& brush ) const { - m_refData = new wxBrushRefData; + if (m_refData == brush.m_refData) return true; - M_BRUSHDATA->m_style = wxSTIPPLE; - M_BRUSHDATA->m_stipple = stipple; + if (!m_refData || !brush.m_refData) return false; - RealizeResource(); + return ( *(wxBrushRefData*)m_refData == *(wxBrushRefData*)brush.m_refData ); } -void wxBrush::Unshare() +int wxBrush::GetStyle() const { - // Don't change shared data - if (!m_refData) + if (m_refData == NULL) { - m_refData = new wxBrushRefData(); + wxFAIL_MSG( wxT("invalid brush") ); + return 0; } - else + + return M_BRUSHDATA->m_style; +} + +wxColour &wxBrush::GetColour() const +{ + if (m_refData == NULL) { - wxBrushRefData* ref = new wxBrushRefData(*(wxBrushRefData*)m_refData); - UnRef(); - m_refData = ref; + wxFAIL_MSG( wxT("invalid brush") ); + return wxNullColour; } + + return M_BRUSHDATA->m_colour; } -void wxBrush::SetColour(const wxColour& col) +wxBitmap *wxBrush::GetStipple() const { - Unshare(); - - M_BRUSHDATA->m_colour = col; + if (m_refData == NULL) + { + wxFAIL_MSG( wxT("invalid brush") ); + return &wxNullBitmap; + } - RealizeResource(); + return &M_BRUSHDATA->m_stipple; } -void wxBrush::SetColour(unsigned char r, unsigned char g, unsigned char b) +void wxBrush::SetColour( const wxColour& col ) { - Unshare(); - - M_BRUSHDATA->m_colour.Set(r, g, b); + AllocExclusive(); - RealizeResource(); + M_BRUSHDATA->m_colour = col; } -void wxBrush::SetStyle(int Style) +void wxBrush::SetColour( unsigned char r, unsigned char g, unsigned char b ) { - Unshare(); - - M_BRUSHDATA->m_style = Style; + AllocExclusive(); - RealizeResource(); + M_BRUSHDATA->m_colour.Set( r, g, b ); } -void wxBrush::SetStipple(const wxBitmap& Stipple) +void wxBrush::SetStyle( int style ) { - Unshare(); - - M_BRUSHDATA->m_stipple = Stipple; + AllocExclusive(); - RealizeResource(); + M_BRUSHDATA->m_style = style; } -bool wxBrush::RealizeResource() +void wxBrush::SetStipple( const wxBitmap& stipple ) { - // Nothing more to do - return TRUE; -} + AllocExclusive(); + M_BRUSHDATA->m_stipple = stipple; + if (M_BRUSHDATA->m_stipple.GetMask()) + { + M_BRUSHDATA->m_style = wxSTIPPLE_MASK_OPAQUE; + } + else + { + M_BRUSHDATA->m_style = wxSTIPPLE; + } +}