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
26 friend class WXDLLEXPORT wxBrush
;
30 wxBrushRefData(const wxBrushRefData
& data
);
31 virtual ~wxBrushRefData();
33 bool operator == ( const wxBrushRefData
& brush
) const
35 return m_style
== brush
.m_style
&&
36 m_stipple
.IsSameAs(brush
.m_stipple
) &&
37 m_colour
== brush
.m_colour
&&
38 m_macBrushKind
== brush
.m_macBrushKind
&&
39 m_macThemeBrush
== brush
.m_macThemeBrush
&&
40 m_macThemeBackground
== brush
.m_macThemeBackground
&&
41 EqualRect(&m_macThemeBackgroundExtent
, &brush
.m_macThemeBackgroundExtent
);
46 wxMacBrushKind m_macBrushKind
;
51 ThemeBrush m_macThemeBrush
;
53 ThemeBackgroundKind m_macThemeBackground
;
54 Rect m_macThemeBackgroundExtent
;
57 #define M_BRUSHDATA ((wxBrushRefData *)m_refData)
60 wxBrushRefData::wxBrushRefData()
63 m_macBrushKind
= kwxMacBrushColour
;
66 wxBrushRefData::wxBrushRefData(const wxBrushRefData
& data
)
68 , m_style(data
.m_style
)
70 m_stipple
= data
.m_stipple
;
71 m_colour
= data
.m_colour
;
72 m_macBrushKind
= data
.m_macBrushKind
;
73 m_macThemeBrush
= data
.m_macThemeBrush
;
74 m_macThemeBackground
= data
.m_macThemeBackground
;
75 m_macThemeBackgroundExtent
= data
.m_macThemeBackgroundExtent
;
78 wxBrushRefData::~wxBrushRefData()
90 wxBrush::wxBrush(const wxColour
& col
, int Style
)
92 m_refData
= new wxBrushRefData
;
94 M_BRUSHDATA
->m_colour
= col
;
95 M_BRUSHDATA
->m_style
= Style
;
100 wxBrush::wxBrush(const wxBitmap
& stipple
)
102 m_refData
= new wxBrushRefData
;
104 M_BRUSHDATA
->m_colour
= *wxBLACK
;
105 M_BRUSHDATA
->m_stipple
= stipple
;
107 if (M_BRUSHDATA
->m_stipple
.GetMask())
108 M_BRUSHDATA
->m_style
= wxSTIPPLE_MASK_OPAQUE
;
110 M_BRUSHDATA
->m_style
= wxSTIPPLE
;
115 wxBrush::wxBrush( ThemeBrush macThemeBrush
)
117 m_refData
= new wxBrushRefData
;
119 M_BRUSHDATA
->m_macBrushKind
= kwxMacBrushTheme
;
120 M_BRUSHDATA
->m_macThemeBrush
= macThemeBrush
;
125 void wxBrush::Unshare()
127 // Don't change shared data
130 m_refData
= new wxBrushRefData();
134 wxBrushRefData
* ref
= new wxBrushRefData(*(wxBrushRefData
*)m_refData
);
140 void wxBrush::SetColour(const wxColour
& col
)
143 M_BRUSHDATA
->m_macBrushKind
= kwxMacBrushColour
;
144 M_BRUSHDATA
->m_colour
= col
;
149 void wxBrush::SetColour(unsigned char r
, unsigned char g
, unsigned char b
)
153 M_BRUSHDATA
->m_macBrushKind
= kwxMacBrushColour
;
154 M_BRUSHDATA
->m_colour
.Set(r
, g
, b
);
159 void wxBrush::SetStyle(int Style
)
163 M_BRUSHDATA
->m_macBrushKind
= kwxMacBrushColour
;
164 M_BRUSHDATA
->m_style
= Style
;
169 void wxBrush::SetStipple(const wxBitmap
& Stipple
)
173 M_BRUSHDATA
->m_macBrushKind
= kwxMacBrushColour
;
174 M_BRUSHDATA
->m_stipple
= Stipple
;
179 void wxBrush::MacSetTheme(ThemeBrush macThemeBrush
)
183 M_BRUSHDATA
->m_macBrushKind
= kwxMacBrushTheme
;
184 M_BRUSHDATA
->m_macThemeBrush
= macThemeBrush
;
187 GetThemeBrushAsColor( macThemeBrush
, 32, true, &color
);
188 M_BRUSHDATA
->m_colour
= color
;
193 void wxBrush::MacSetThemeBackground(unsigned long macThemeBackground
, const WXRECTPTR extent
)
197 M_BRUSHDATA
->m_macBrushKind
= kwxMacBrushThemeBackground
;
198 M_BRUSHDATA
->m_macThemeBackground
= macThemeBackground
;
199 M_BRUSHDATA
->m_macThemeBackgroundExtent
= *(Rect
*)extent
;
204 bool wxBrush::RealizeResource()
209 unsigned long wxBrush::MacGetThemeBackground(WXRECTPTR extent
) const
211 if ( M_BRUSHDATA
&& M_BRUSHDATA
->m_macBrushKind
== kwxMacBrushThemeBackground
)
214 *(Rect
*)extent
= M_BRUSHDATA
->m_macThemeBackgroundExtent
;
216 return M_BRUSHDATA
->m_macThemeBackground
;
224 short wxBrush::MacGetTheme() const
226 return (M_BRUSHDATA
? ((M_BRUSHDATA
->m_macBrushKind
== kwxMacBrushTheme
) ? M_BRUSHDATA
->m_macThemeBrush
: kThemeBrushBlack
) : kThemeBrushBlack
);
229 wxColour
& wxBrush::GetColour() const
231 return (M_BRUSHDATA
? M_BRUSHDATA
->m_colour
: wxNullColour
);
234 int wxBrush::GetStyle() const
236 return (M_BRUSHDATA
? M_BRUSHDATA
->m_style
: 0);
239 wxBitmap
*wxBrush::GetStipple() const
241 return (M_BRUSHDATA
? & M_BRUSHDATA
->m_stipple
: 0);
244 wxMacBrushKind
wxBrush::MacGetBrushKind() const
246 return (M_BRUSHDATA
? M_BRUSHDATA
->m_macBrushKind
: kwxMacBrushColour
);
249 bool wxBrush::operator == ( const wxBrush
& brush
) const
251 if (m_refData
== brush
.m_refData
) return true;
253 if (!m_refData
|| !brush
.m_refData
) return false;
255 return ( *(wxBrushRefData
*)m_refData
== *(wxBrushRefData
*)brush
.m_refData
);