]> git.saurik.com Git - wxWidgets.git/blobdiff - src/x11/brush.cpp
always remember to test IsOk() after using wxFileInputStream
[wxWidgets.git] / src / x11 / brush.cpp
index 685b376427d3a7829418348a248b195fc95cab90..71046981e4868ea2f146bf9de23f57b3dbefa678 100644 (file)
@@ -1,5 +1,5 @@
 /////////////////////////////////////////////////////////////////////////////
-// Name:        src/motif/brush.cpp
+// Name:        src/x11/brush.cpp
 // Purpose:     wxBrush
 // Author:      Julian Smart
 // Modified by:
 // 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
+
+//-----------------------------------------------------------------------------
+// wxBrush
+//-----------------------------------------------------------------------------
 
-wxBrushRefData::wxBrushRefData()
+class wxBrushRefData : public wxGDIRefData
 {
-    m_style = wxSOLID;
-}
+public:
+    wxBrushRefData()
+    {
+        m_style = wxBRUSHSTYLE_INVALID;
+    }
+
+    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.IsSameAs(data.m_stipple) &&
+                m_colour == data.m_colour);
+    }
 
-wxBrushRefData::wxBrushRefData(const wxBrushRefData& data)
+    wxBrushStyle m_style;
+    wxColour     m_colour;
+    wxBitmap     m_stipple;
+};
+
+//-----------------------------------------------------------------------------
+
+#define M_BRUSHDATA ((wxBrushRefData *)m_refData)
+
+IMPLEMENT_DYNAMIC_CLASS(wxBrush,wxGDIObject)
+
+wxBrush::wxBrush( const wxColour &colour, wxBrushStyle style )
 {
-    m_style = data.m_style;
-    m_stipple = data.m_stipple;
-    m_colour = data.m_colour;
+    m_refData = new wxBrushRefData();
+    M_BRUSHDATA->m_style = style;
+    M_BRUSHDATA->m_colour = colour;
 }
 
-wxBrushRefData::~wxBrushRefData()
+#if FUTURE_WXWIN_COMPATIBILITY_3_0
+wxBrush::wxBrush(const wxColour& col, int style)
 {
+    m_refData = new wxBrushRefData;
+    M_BRUSHDATA->m_style = (wxBrushStyle)style;
+    M_BRUSHDATA->m_colour = col;
 }
+#endif
 
-// 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 = wxBRUSHSTYLE_STIPPLE_MASK_OPAQUE;
+    else
+        M_BRUSHDATA->m_style = wxBRUSHSTYLE_STIPPLE_MASK;
 }
 
 wxBrush::~wxBrush()
 {
+    // m_refData unrefed in ~wxObject
 }
 
-wxBrush::wxBrush(const wxColour& col, int Style)
+wxGDIRefData *wxBrush::CreateGDIRefData() const
 {
-    m_refData = new wxBrushRefData;
-
-    M_BRUSHDATA->m_colour = col;
-    M_BRUSHDATA->m_style = Style;
+    return new wxBrushRefData;
+}
 
-    RealizeResource();
+wxGDIRefData *wxBrush::CloneGDIRefData(const wxGDIRefData *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()
+wxBrushStyle wxBrush::GetStyle() const
 {
-    // Don't change shared data
-    if (!m_refData)
-    {
-        m_refData = new wxBrushRefData();
-    }
-    else
-    {
-        wxBrushRefData* ref = new wxBrushRefData(*(wxBrushRefData*)m_refData);
-        UnRef();
-        m_refData = ref;
-    }
+    wxCHECK_MSG( Ok(), wxBRUSHSTYLE_INVALID, _T("invalid brush") );
+
+    return M_BRUSHDATA->m_style;
 }
 
-void wxBrush::SetColour(const wxColour& col)
+wxColour wxBrush::GetColour() const
 {
-    Unshare();
+    wxCHECK_MSG( Ok(), wxNullColour, _T("invalid brush") );
 
-    M_BRUSHDATA->m_colour = col;
-
-    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);
+    wxCHECK_MSG( Ok(), NULL, _T("invalid brush") );
 
-    RealizeResource();
+    return &M_BRUSHDATA->m_stipple;
 }
 
-void wxBrush::SetStyle(int Style)
+void wxBrush::SetColour( const wxColour& col )
 {
-    Unshare();
-
-    M_BRUSHDATA->m_style = Style;
+    AllocExclusive();
 
-    RealizeResource();
+    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;
+    AllocExclusive();
 
-    RealizeResource();
+    M_BRUSHDATA->m_colour.Set( r, g, b );
 }
 
-bool wxBrush::RealizeResource()
+void wxBrush::SetStyle( wxBrushStyle 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 = wxBRUSHSTYLE_STIPPLE_MASK_OPAQUE;
+    else
+        M_BRUSHDATA->m_style = wxBRUSHSTYLE_STIPPLE_MASK;
+}