/////////////////////////////////////////////////////////////////////////////
-// Name: src/motif/brush.cpp
+// Name: src/x11/brush.cpp
// Purpose: wxBrush
// Author: Julian Smart
// Modified by:
#include "wx/utils.h"
#include "wx/brush.h"
-IMPLEMENT_DYNAMIC_CLASS(wxBrush, wxGDIObject)
+//-----------------------------------------------------------------------------
+// wxBrush
+//-----------------------------------------------------------------------------
-wxBrushRefData::wxBrushRefData()
+class wxBrushRefData: public wxObjectRefData
{
- m_style = wxSOLID;
-}
+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(const wxBrushRefData& data)
-{
- m_style = data.m_style;
- m_stipple = data.m_stipple;
- m_colour = data.m_colour;
-}
+//-----------------------------------------------------------------------------
-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;
-
- RealizeResource();
+ return new wxBrushRefData;
}
-wxBrush::wxBrush(const wxBitmap& stipple)
+wxObjectRefData *wxBrush::CloneRefData(const wxObjectRefData *data) const
{
- m_refData = new wxBrushRefData;
-
- M_BRUSHDATA->m_style = wxSTIPPLE;
- M_BRUSHDATA->m_stipple = stipple;
+ return new wxBrushRefData(*(wxBrushRefData *)data);
+}
- RealizeResource();
+bool wxBrush::operator == ( const wxBrush& brush ) const
+{
+ if (m_refData == brush.m_refData) return TRUE;
+
+ if (!m_refData || !brush.m_refData) return FALSE;
+
+ 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();
- }
- else
- {
- wxBrushRefData* ref = new wxBrushRefData(*(wxBrushRefData*)m_refData);
- UnRef();
- m_refData = ref;
+ wxFAIL_MSG( wxT("invalid brush") );
+ return 0;
}
+
+ return M_BRUSHDATA->m_style;
}
-void wxBrush::SetColour(const wxColour& col)
+wxColour &wxBrush::GetColour() const
{
- Unshare();
-
- M_BRUSHDATA->m_colour = col;
+ if (m_refData == NULL)
+ {
+ wxFAIL_MSG( wxT("invalid brush") );
+ return wxNullColour;
+ }
- RealizeResource();
+ return M_BRUSHDATA->m_colour;
}
-void wxBrush::SetColour(unsigned char r, unsigned char g, unsigned char b)
+wxBitmap *wxBrush::GetStipple() const
{
- Unshare();
-
- M_BRUSHDATA->m_colour.Set(r, g, b);
+ if (m_refData == NULL)
+ {
+ wxFAIL_MSG( wxT("invalid brush") );
+ return &wxNullBitmap;
+ }
- RealizeResource();
+ return &M_BRUSHDATA->m_stipple;
}
-void wxBrush::SetStyle(int Style)
+void wxBrush::SetColour( const wxColour& col )
{
- Unshare();
-
- M_BRUSHDATA->m_style = Style;
-
- RealizeResource();
+ AllocExclusive();
+
+ M_BRUSHDATA->m_colour = col;
}
-void wxBrush::SetStipple(const wxBitmap& Stipple)
+void wxBrush::SetColour( unsigned char r, unsigned char g, unsigned char b )
{
- Unshare();
-
- M_BRUSHDATA->m_stipple = Stipple;
-
- RealizeResource();
+ AllocExclusive();
+
+ M_BRUSHDATA->m_colour.Set( r, g, b );
}
-bool wxBrush::RealizeResource()
+void wxBrush::SetStyle( int style )
{
- // Nothing more to do
- return TRUE;
+ AllocExclusive();
+
+ M_BRUSHDATA->m_style = style;
}
+void wxBrush::SetStipple( const wxBitmap& stipple )
+{
+ 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;
+ }
+}