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
);
34 wxMacBrushKind m_macBrushKind
;
39 ThemeBrush m_macThemeBrush
;
41 ThemeBackgroundKind m_macThemeBackground
;
42 Rect m_macThemeBackgroundExtent
;
45 #define M_BRUSHDATA ((wxBrushRefData *)m_refData)
48 wxBrushRefData::wxBrushRefData()
51 m_macBrushKind
= kwxMacBrushColour
;
54 wxBrushRefData::wxBrushRefData(const wxBrushRefData
& data
)
56 , m_style(data
.m_style
)
58 m_stipple
= data
.m_stipple
;
59 m_colour
= data
.m_colour
;
60 m_macBrushKind
= data
.m_macBrushKind
;
61 m_macThemeBrush
= data
.m_macThemeBrush
;
62 m_macThemeBackground
= data
.m_macThemeBackground
;
63 m_macThemeBackgroundExtent
= data
.m_macThemeBackgroundExtent
;
66 wxBrushRefData::~wxBrushRefData()
78 wxBrush::wxBrush(const wxColour
& col
, int Style
)
80 m_refData
= new wxBrushRefData
;
82 M_BRUSHDATA
->m_colour
= col
;
83 M_BRUSHDATA
->m_style
= Style
;
88 wxBrush::wxBrush(const wxBitmap
& stipple
)
90 m_refData
= new wxBrushRefData
;
92 M_BRUSHDATA
->m_colour
= *wxBLACK
;
93 M_BRUSHDATA
->m_stipple
= stipple
;
95 if (M_BRUSHDATA
->m_stipple
.GetMask())
96 M_BRUSHDATA
->m_style
= wxSTIPPLE_MASK_OPAQUE
;
98 M_BRUSHDATA
->m_style
= wxSTIPPLE
;
103 wxBrush::wxBrush( ThemeBrush macThemeBrush
)
105 m_refData
= new wxBrushRefData
;
107 M_BRUSHDATA
->m_macBrushKind
= kwxMacBrushTheme
;
108 M_BRUSHDATA
->m_macThemeBrush
= macThemeBrush
;
113 void wxBrush::Unshare()
115 // Don't change shared data
118 m_refData
= new wxBrushRefData();
122 wxBrushRefData
* ref
= new wxBrushRefData(*(wxBrushRefData
*)m_refData
);
128 void wxBrush::SetColour(const wxColour
& col
)
131 M_BRUSHDATA
->m_macBrushKind
= kwxMacBrushColour
;
132 M_BRUSHDATA
->m_colour
= col
;
137 void wxBrush::SetColour(unsigned char r
, unsigned char g
, unsigned char b
)
141 M_BRUSHDATA
->m_macBrushKind
= kwxMacBrushColour
;
142 M_BRUSHDATA
->m_colour
.Set(r
, g
, b
);
147 void wxBrush::SetStyle(int Style
)
151 M_BRUSHDATA
->m_macBrushKind
= kwxMacBrushColour
;
152 M_BRUSHDATA
->m_style
= Style
;
157 void wxBrush::SetStipple(const wxBitmap
& Stipple
)
161 M_BRUSHDATA
->m_macBrushKind
= kwxMacBrushColour
;
162 M_BRUSHDATA
->m_stipple
= Stipple
;
167 void wxBrush::MacSetTheme(ThemeBrush macThemeBrush
)
171 M_BRUSHDATA
->m_macBrushKind
= kwxMacBrushTheme
;
172 M_BRUSHDATA
->m_macThemeBrush
= macThemeBrush
;
175 GetThemeBrushAsColor( macThemeBrush
, 32, true, &color
);
176 M_BRUSHDATA
->m_colour
.Set( color
.red
>> 8 , color
.green
>> 8 , color
.blue
>> 8 );
181 void wxBrush::MacSetThemeBackground(unsigned long macThemeBackground
, const WXRECTPTR extent
)
185 M_BRUSHDATA
->m_macBrushKind
= kwxMacBrushThemeBackground
;
186 M_BRUSHDATA
->m_macThemeBackground
= macThemeBackground
;
187 M_BRUSHDATA
->m_macThemeBackgroundExtent
= *(Rect
*)extent
;
192 bool wxBrush::RealizeResource()
197 unsigned long wxBrush::MacGetThemeBackground(WXRECTPTR extent
) const
199 if ( M_BRUSHDATA
&& M_BRUSHDATA
->m_macBrushKind
== kwxMacBrushThemeBackground
)
202 *(Rect
*)extent
= M_BRUSHDATA
->m_macThemeBackgroundExtent
;
204 return M_BRUSHDATA
->m_macThemeBackground
;
212 short wxBrush::MacGetTheme() const
214 return (M_BRUSHDATA
? ((M_BRUSHDATA
->m_macBrushKind
== kwxMacBrushTheme
) ? M_BRUSHDATA
->m_macThemeBrush
: kThemeBrushBlack
) : kThemeBrushBlack
);
217 wxColour
& wxBrush::GetColour() const
219 return (M_BRUSHDATA
? M_BRUSHDATA
->m_colour
: wxNullColour
);
222 int wxBrush::GetStyle() const
224 return (M_BRUSHDATA
? M_BRUSHDATA
->m_style
: 0);
227 wxBitmap
*wxBrush::GetStipple() const
229 return (M_BRUSHDATA
? & M_BRUSHDATA
->m_stipple
: 0);
232 wxMacBrushKind
wxBrush::MacGetBrushKind() const
234 return (M_BRUSHDATA
? M_BRUSHDATA
->m_macBrushKind
: kwxMacBrushColour
);