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"
17 #include "wx/mac/private.h"
19 IMPLEMENT_DYNAMIC_CLASS(wxBrush
, wxGDIObject
)
21 class WXDLLEXPORT wxBrushRefData
: public wxGDIRefData
23 friend class WXDLLEXPORT wxBrush
;
27 wxBrushRefData(const wxBrushRefData
& data
);
31 wxMacBrushKind m_macBrushKind
;
36 ThemeBrush m_macThemeBrush
;
38 ThemeBackgroundKind m_macThemeBackground
;
39 Rect m_macThemeBackgroundExtent
;
42 #define M_BRUSHDATA ((wxBrushRefData *)m_refData)
45 wxBrushRefData::wxBrushRefData()
48 m_macBrushKind
= kwxMacBrushColour
;
51 wxBrushRefData::wxBrushRefData(const wxBrushRefData
& data
)
53 , m_style(data
.m_style
)
55 m_stipple
= data
.m_stipple
;
56 m_colour
= data
.m_colour
;
57 m_macBrushKind
= data
.m_macBrushKind
;
58 m_macThemeBrush
= data
.m_macThemeBrush
;
59 m_macThemeBackground
= data
.m_macThemeBackground
;
60 m_macThemeBackgroundExtent
= data
.m_macThemeBackgroundExtent
;
63 wxBrushRefData::~wxBrushRefData()
75 wxBrush::wxBrush(const wxColour
& col
, int Style
)
77 m_refData
= new wxBrushRefData
;
79 M_BRUSHDATA
->m_colour
= col
;
80 M_BRUSHDATA
->m_style
= Style
;
85 wxBrush::wxBrush(const wxBitmap
& stipple
)
87 m_refData
= new wxBrushRefData
;
89 M_BRUSHDATA
->m_colour
= *wxBLACK
;
90 M_BRUSHDATA
->m_stipple
= stipple
;
92 if (M_BRUSHDATA
->m_stipple
.GetMask())
93 M_BRUSHDATA
->m_style
= wxSTIPPLE_MASK_OPAQUE
;
95 M_BRUSHDATA
->m_style
= wxSTIPPLE
;
100 wxBrush::wxBrush( ThemeBrush macThemeBrush
)
102 m_refData
= new wxBrushRefData
;
104 M_BRUSHDATA
->m_macBrushKind
= kwxMacBrushTheme
;
105 M_BRUSHDATA
->m_macThemeBrush
= macThemeBrush
;
110 void wxBrush::Unshare()
112 // Don't change shared data
115 m_refData
= new wxBrushRefData();
119 wxBrushRefData
* ref
= new wxBrushRefData(*(wxBrushRefData
*)m_refData
);
125 void wxBrush::SetColour(const wxColour
& col
)
128 M_BRUSHDATA
->m_macBrushKind
= kwxMacBrushColour
;
129 M_BRUSHDATA
->m_colour
= col
;
134 void wxBrush::SetColour(unsigned char r
, unsigned char g
, unsigned char b
)
138 M_BRUSHDATA
->m_macBrushKind
= kwxMacBrushColour
;
139 M_BRUSHDATA
->m_colour
.Set(r
, g
, b
);
144 void wxBrush::SetStyle(int Style
)
148 M_BRUSHDATA
->m_macBrushKind
= kwxMacBrushColour
;
149 M_BRUSHDATA
->m_style
= Style
;
154 void wxBrush::SetStipple(const wxBitmap
& Stipple
)
158 M_BRUSHDATA
->m_macBrushKind
= kwxMacBrushColour
;
159 M_BRUSHDATA
->m_stipple
= Stipple
;
164 void wxBrush::MacSetTheme(ThemeBrush macThemeBrush
)
168 M_BRUSHDATA
->m_macBrushKind
= kwxMacBrushTheme
;
169 M_BRUSHDATA
->m_macThemeBrush
= macThemeBrush
;
172 GetThemeBrushAsColor( macThemeBrush
, 32, true, &color
);
173 M_BRUSHDATA
->m_colour
.Set( color
.red
>> 8 , color
.green
>> 8 , color
.blue
>> 8 );
178 void wxBrush::MacSetThemeBackground(unsigned long macThemeBackground
, const WXRECTPTR extent
)
182 M_BRUSHDATA
->m_macBrushKind
= kwxMacBrushThemeBackground
;
183 M_BRUSHDATA
->m_macThemeBackground
= macThemeBackground
;
184 M_BRUSHDATA
->m_macThemeBackgroundExtent
= *(Rect
*)extent
;
189 bool wxBrush::RealizeResource()
194 unsigned long wxBrush::MacGetThemeBackground(WXRECTPTR extent
) const
196 if ( M_BRUSHDATA
&& M_BRUSHDATA
->m_macBrushKind
== kwxMacBrushThemeBackground
)
199 *(Rect
*)extent
= M_BRUSHDATA
->m_macThemeBackgroundExtent
;
201 return M_BRUSHDATA
->m_macThemeBackground
;
209 short wxBrush::MacGetTheme() const
211 return (M_BRUSHDATA
? ((M_BRUSHDATA
->m_macBrushKind
== kwxMacBrushTheme
) ? M_BRUSHDATA
->m_macThemeBrush
: kThemeBrushBlack
) : kThemeBrushBlack
);
214 wxColour
& wxBrush::GetColour() const
216 return (M_BRUSHDATA
? M_BRUSHDATA
->m_colour
: wxNullColour
);
219 int wxBrush::GetStyle() const
221 return (M_BRUSHDATA
? M_BRUSHDATA
->m_style
: 0);
224 wxBitmap
*wxBrush::GetStipple() const
226 return (M_BRUSHDATA
? & M_BRUSHDATA
->m_stipple
: 0);
229 wxMacBrushKind
wxBrush::MacGetBrushKind() const
231 return (M_BRUSHDATA
? M_BRUSHDATA
->m_macBrushKind
: kwxMacBrushColour
);