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
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
;
186 RGBColor color
= { 0,0,0 } ;
188 CGColorRef colorref
= 0;
189 HIThemeBrushCreateCGColor( macThemeBrush
, &colorref
);
190 size_t noComp
= CGColorGetNumberOfComponents( colorref
);
191 if ( noComp
>=3 && noComp
<= 4 )
193 // TODO verify whether we really are on a RGB color space
194 const CGFloat
*components
= CGColorGetComponents( colorref
);
195 color
.red
= (int)(components
[0]*255+0.5);
196 color
.green
= (int)(components
[1]*255+0.5);
197 color
.blue
= (int)(components
[2]*255+0.5);
199 CFRelease( colorref
);
201 GetThemeBrushAsColor( macThemeBrush
, 32, true, &color
);
203 M_BRUSHDATA
->m_colour
= color
;
209 void wxBrush::MacSetThemeBackground(unsigned long macThemeBackground, const WXRECTPTR extent)
213 M_BRUSHDATA->m_macBrushKind = kwxMacBrushThemeBackground;
214 M_BRUSHDATA->m_macThemeBackground = macThemeBackground;
215 M_BRUSHDATA->m_macThemeBackgroundExtent = *(Rect*)extent;
221 bool wxBrush::RealizeResource()
227 unsigned long wxBrush::MacGetThemeBackground(WXRECTPTR extent) const
229 if ( M_BRUSHDATA && M_BRUSHDATA->m_macBrushKind == kwxMacBrushThemeBackground )
232 *(Rect*)extent = M_BRUSHDATA->m_macThemeBackgroundExtent;
234 return M_BRUSHDATA->m_macThemeBackground;
243 short wxBrush::MacGetTheme() const
245 return (M_BRUSHDATA
? ((M_BRUSHDATA
->m_macBrushKind
== kwxMacBrushTheme
) ? M_BRUSHDATA
->m_macThemeBrush
: kThemeBrushBlack
) : kThemeBrushBlack
);
248 wxColour
& wxBrush::GetColour() const
250 return (M_BRUSHDATA
? M_BRUSHDATA
->m_colour
: wxNullColour
);
253 int wxBrush::GetStyle() const
255 return (M_BRUSHDATA
? M_BRUSHDATA
->m_style
: 0);
258 wxBitmap
*wxBrush::GetStipple() const
260 return (M_BRUSHDATA
? & M_BRUSHDATA
->m_stipple
: 0);
263 wxMacBrushKind
wxBrush::MacGetBrushKind() const
265 return (M_BRUSHDATA
? M_BRUSHDATA
->m_macBrushKind
: kwxMacBrushColour
);
268 bool wxBrush::operator == ( const wxBrush
& brush
) const
270 if (m_refData
== brush
.m_refData
) return true;
272 if (!m_refData
|| !brush
.m_refData
) return false;
274 return ( *(wxBrushRefData
*)m_refData
== *(wxBrushRefData
*)brush
.m_refData
);