1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/osx/brush.cpp
4 // Author: Stefan Csomor
7 // Copyright: (c) Stefan Csomor
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 #include "wx/wxprec.h"
19 #include "wx/osx/private.h"
21 IMPLEMENT_DYNAMIC_CLASS(wxBrush
, wxGDIObject
)
23 class WXDLLEXPORT wxBrushRefData
: public wxGDIRefData
26 wxBrushRefData(const wxColour
& colour
= wxNullColour
, wxBrushStyle style
= wxBRUSHSTYLE_SOLID
);
27 wxBrushRefData(const wxBitmap
& stipple
);
28 wxBrushRefData(const wxBrushRefData
& data
);
29 virtual ~wxBrushRefData();
31 bool operator==(const wxBrushRefData
& data
) const;
33 const wxColour
& GetColour() const { return m_colour
; }
34 wxBrushStyle
GetStyle() const { return m_style
; }
35 wxBitmap
*GetStipple() { return &m_stipple
; }
37 void SetColour(const wxColour
& colour
) { m_colour
= colour
; }
38 void SetStyle(wxBrushStyle style
) { m_style
= style
; }
39 void SetStipple(const wxBitmap
& stipple
) { DoSetStipple(stipple
); }
42 void DoSetStipple(const wxBitmap
& stipple
);
49 #define M_BRUSHDATA ((wxBrushRefData *)m_refData)
51 wxBrushRefData::wxBrushRefData(const wxColour
& colour
, wxBrushStyle style
)
52 : m_colour(colour
), m_style( style
)
56 wxBrushRefData::wxBrushRefData(const wxBitmap
& stipple
)
58 DoSetStipple( stipple
);
61 wxBrushRefData::wxBrushRefData(const wxBrushRefData
& data
)
63 m_stipple(data
.m_stipple
),
64 m_colour(data
.m_colour
),
69 wxBrushRefData::~wxBrushRefData()
73 bool wxBrushRefData::operator==(const wxBrushRefData
& data
) const
75 return m_style
== data
.m_style
&&
76 m_colour
== data
.m_colour
&&
77 m_stipple
.IsSameAs(data
.m_stipple
);
80 void wxBrushRefData::DoSetStipple(const wxBitmap
& stipple
)
83 m_style
= stipple
.GetMask() ? wxBRUSHSTYLE_STIPPLE_MASK_OPAQUE
: wxBRUSHSTYLE_STIPPLE
;
97 wxBrush::wxBrush(const wxColour
& col
, wxBrushStyle style
)
99 m_refData
= new wxBrushRefData( col
, style
);
102 #if FUTURE_WXWIN_COMPATIBILITY_3_0
103 wxBrush::wxBrush(const wxColour
& col
, int style
)
105 m_refData
= new wxBrushRefData(col
, (wxBrushStyle
)style
);
109 wxBrush::wxBrush(const wxBitmap
& stipple
)
111 m_refData
= new wxBrushRefData( stipple
);
114 // ----------------------------------------------------------------------------
115 // wxBrush house keeping stuff
116 // ----------------------------------------------------------------------------
118 bool wxBrush::operator==(const wxBrush
& brush
) const
120 const wxBrushRefData
*brushData
= (wxBrushRefData
*)brush
.m_refData
;
122 // an invalid brush is considered to be only equal to another invalid brush
123 return m_refData
? (brushData
&& *M_BRUSHDATA
== *brushData
) : !brushData
;
126 wxGDIRefData
*wxBrush::CreateGDIRefData() const
128 return new wxBrushRefData
;
131 wxGDIRefData
*wxBrush::CloneGDIRefData(const wxGDIRefData
*data
) const
133 return new wxBrushRefData(*(const wxBrushRefData
*)data
);
136 // ----------------------------------------------------------------------------
138 // ----------------------------------------------------------------------------
140 wxColour
wxBrush::GetColour() const
142 wxCHECK_MSG( IsOk(), wxNullColour
, wxT("invalid brush") );
144 return M_BRUSHDATA
->GetColour();
147 wxBrushStyle
wxBrush::GetStyle() const
149 wxCHECK_MSG( IsOk(), wxBRUSHSTYLE_INVALID
, wxT("invalid brush") );
151 return M_BRUSHDATA
->GetStyle();
154 wxBitmap
*wxBrush::GetStipple() const
156 wxCHECK_MSG( IsOk(), NULL
, wxT("invalid brush") );
158 return M_BRUSHDATA
->GetStipple();
161 // ----------------------------------------------------------------------------
163 // ----------------------------------------------------------------------------
165 void wxBrush::SetColour(const wxColour
& col
)
169 M_BRUSHDATA
->SetColour(col
);
172 void wxBrush::SetColour(unsigned char r
, unsigned char g
, unsigned char b
)
176 M_BRUSHDATA
->SetColour(wxColour(r
, g
, b
));
179 void wxBrush::SetStyle(wxBrushStyle style
)
183 M_BRUSHDATA
->SetStyle(style
);
186 void wxBrush::SetStipple(const wxBitmap
& stipple
)
190 M_BRUSHDATA
->SetStipple(stipple
);