1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/mac/carbon/brush.cpp
4 // Author: Stefan Csomor
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #include "wx/wxprec.h"
20 #include "wx/mac/private.h"
22 IMPLEMENT_DYNAMIC_CLASS(wxBrush
, wxGDIObject
)
24 class WXDLLEXPORT wxBrushRefData
: public wxGDIRefData
27 wxBrushRefData(const wxColour
& colour
= wxNullColour
, wxBrushStyle style
= wxBRUSHSTYLE_SOLID
);
28 wxBrushRefData(const wxBitmap
& stipple
);
29 wxBrushRefData(const wxBrushRefData
& data
);
30 virtual ~wxBrushRefData();
32 bool operator==(const wxBrushRefData
& data
) const;
34 const wxColour
& GetColour() const { return m_colour
; }
35 wxBrushStyle
GetStyle() const { return m_style
; }
36 wxBitmap
*GetStipple() { return &m_stipple
; }
38 void SetColour(const wxColour
& colour
) { m_colour
= colour
; }
39 void SetStyle(wxBrushStyle style
) { m_style
= style
; }
40 void SetStipple(const wxBitmap
& stipple
) { DoSetStipple(stipple
); }
43 void DoSetStipple(const wxBitmap
& stipple
);
50 #define M_BRUSHDATA ((wxBrushRefData *)m_refData)
52 wxBrushRefData::wxBrushRefData(const wxColour
& colour
, wxBrushStyle style
)
53 : m_colour(colour
), m_style( style
)
57 wxBrushRefData::wxBrushRefData(const wxBitmap
& stipple
)
59 DoSetStipple( stipple
);
62 wxBrushRefData::wxBrushRefData(const wxBrushRefData
& data
)
64 m_stipple(data
.m_stipple
),
65 m_colour(data
.m_colour
),
70 wxBrushRefData::~wxBrushRefData()
74 bool wxBrushRefData::operator==(const wxBrushRefData
& data
) const
76 return m_style
== data
.m_style
&&
77 m_colour
== data
.m_colour
&&
78 m_stipple
.IsSameAs(data
.m_stipple
);
81 void wxBrushRefData::DoSetStipple(const wxBitmap
& stipple
)
84 m_style
= stipple
.GetMask() ? wxSTIPPLE_MASK_OPAQUE
: wxSTIPPLE
;
98 wxBrush::wxBrush(const wxColour
& col
, wxBrushStyle style
)
100 m_refData
= new wxBrushRefData( col
, style
);
103 wxBrush::wxBrush(const wxBitmap
& stipple
)
105 m_refData
= new wxBrushRefData( stipple
);
108 // ----------------------------------------------------------------------------
109 // wxBrush house keeping stuff
110 // ----------------------------------------------------------------------------
112 bool wxBrush::operator==(const wxBrush
& brush
) const
114 const wxBrushRefData
*brushData
= (wxBrushRefData
*)brush
.m_refData
;
116 // an invalid brush is considered to be only equal to another invalid brush
117 return m_refData
? (brushData
&& *M_BRUSHDATA
== *brushData
) : !brushData
;
120 wxGDIRefData
*wxBrush::CreateGDIRefData() const
122 return new wxBrushRefData
;
125 wxGDIRefData
*wxBrush::CloneGDIRefData(const wxGDIRefData
*data
) const
127 return new wxBrushRefData(*(const wxBrushRefData
*)data
);
130 // ----------------------------------------------------------------------------
132 // ----------------------------------------------------------------------------
134 const wxColour
& wxBrush::GetColour() const
136 wxCHECK_MSG( Ok(), wxNullColour
, _T("invalid brush") );
138 return M_BRUSHDATA
->GetColour();
141 wxBrushStyle
wxBrush::GetStyle() const
143 wxCHECK_MSG( Ok(), 0, _T("invalid brush") );
145 return M_BRUSHDATA
->GetStyle();
148 wxBitmap
*wxBrush::GetStipple() const
150 wxCHECK_MSG( Ok(), NULL
, _T("invalid brush") );
152 return M_BRUSHDATA
->GetStipple();
155 // ----------------------------------------------------------------------------
157 // ----------------------------------------------------------------------------
159 void wxBrush::SetColour(const wxColour
& col
)
163 M_BRUSHDATA
->SetColour(col
);
166 void wxBrush::SetColour(unsigned char r
, unsigned char g
, unsigned char b
)
170 M_BRUSHDATA
->SetColour(wxColour(r
, g
, b
));
173 void wxBrush::SetStyle(wxBrushStyle style
)
177 M_BRUSHDATA
->SetStyle(style
);
180 void wxBrush::SetStipple(const wxBitmap
& stipple
)
184 M_BRUSHDATA
->SetStipple(stipple
);