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 #if FUTURE_WXWIN_COMPATIBILITY_3_0
104 wxBrush::wxBrush(const wxColour
& col
, int style
)
106 m_refData
= new wxBrushRefData(col
, (wxBrushStyle
)style
);
110 wxBrush::wxBrush(const wxBitmap
& stipple
)
112 m_refData
= new wxBrushRefData( stipple
);
115 // ----------------------------------------------------------------------------
116 // wxBrush house keeping stuff
117 // ----------------------------------------------------------------------------
119 bool wxBrush::operator==(const wxBrush
& brush
) const
121 const wxBrushRefData
*brushData
= (wxBrushRefData
*)brush
.m_refData
;
123 // an invalid brush is considered to be only equal to another invalid brush
124 return m_refData
? (brushData
&& *M_BRUSHDATA
== *brushData
) : !brushData
;
127 wxGDIRefData
*wxBrush::CreateGDIRefData() const
129 return new wxBrushRefData
;
132 wxGDIRefData
*wxBrush::CloneGDIRefData(const wxGDIRefData
*data
) const
134 return new wxBrushRefData(*(const wxBrushRefData
*)data
);
137 // ----------------------------------------------------------------------------
139 // ----------------------------------------------------------------------------
141 const wxColour
& wxBrush::GetColour() const
143 wxCHECK_MSG( Ok(), wxNullColour
, _T("invalid brush") );
145 return M_BRUSHDATA
->GetColour();
148 wxBrushStyle
wxBrush::GetStyle() const
150 wxCHECK_MSG( Ok(), wxBRUSHSTYLE_INVALID
, _T("invalid brush") );
152 return M_BRUSHDATA
->GetStyle();
155 wxBitmap
*wxBrush::GetStipple() const
157 wxCHECK_MSG( Ok(), NULL
, _T("invalid brush") );
159 return M_BRUSHDATA
->GetStipple();
162 // ----------------------------------------------------------------------------
164 // ----------------------------------------------------------------------------
166 void wxBrush::SetColour(const wxColour
& col
)
170 M_BRUSHDATA
->SetColour(col
);
173 void wxBrush::SetColour(unsigned char r
, unsigned char g
, unsigned char b
)
177 M_BRUSHDATA
->SetColour(wxColour(r
, g
, b
));
180 void wxBrush::SetStyle(wxBrushStyle style
)
184 M_BRUSHDATA
->SetStyle(style
);
187 void wxBrush::SetStipple(const wxBitmap
& stipple
)
191 M_BRUSHDATA
->SetStipple(stipple
);