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 wxObjectRefData
* wxBrush::CreateRefData() const
127 return new wxBrushRefData
;
130 wxObjectRefData
* wxBrush::CloneRefData(const wxObjectRefData
* data
) const
132 return new wxBrushRefData(*wx_static_cast(const wxBrushRefData
*, data
));
135 void wxBrush::SetColour(const wxColour
& col
)
138 M_BRUSHDATA
->m_macBrushKind
= kwxMacBrushColour
;
139 M_BRUSHDATA
->m_colour
= col
;
144 void wxBrush::SetColour(unsigned char r
, unsigned char g
, unsigned char b
)
148 M_BRUSHDATA
->m_macBrushKind
= kwxMacBrushColour
;
149 M_BRUSHDATA
->m_colour
.Set(r
, g
, b
);
154 void wxBrush::SetStyle(int Style
)
158 M_BRUSHDATA
->m_macBrushKind
= kwxMacBrushColour
;
159 M_BRUSHDATA
->m_style
= Style
;
164 void wxBrush::SetStipple(const wxBitmap
& Stipple
)
168 M_BRUSHDATA
->m_macBrushKind
= kwxMacBrushColour
;
169 M_BRUSHDATA
->m_stipple
= Stipple
;
174 void wxBrush::MacSetTheme(ThemeBrush macThemeBrush
)
178 M_BRUSHDATA
->m_macBrushKind
= kwxMacBrushTheme
;
179 M_BRUSHDATA
->m_macThemeBrush
= macThemeBrush
;
182 GetThemeBrushAsColor( macThemeBrush
, 32, true, &color
);
183 M_BRUSHDATA
->m_colour
= color
;
188 void wxBrush::MacSetThemeBackground(unsigned long macThemeBackground
, const WXRECTPTR extent
)
192 M_BRUSHDATA
->m_macBrushKind
= kwxMacBrushThemeBackground
;
193 M_BRUSHDATA
->m_macThemeBackground
= macThemeBackground
;
194 M_BRUSHDATA
->m_macThemeBackgroundExtent
= *(Rect
*)extent
;
199 bool wxBrush::RealizeResource()
204 unsigned long wxBrush::MacGetThemeBackground(WXRECTPTR extent
) const
206 if ( M_BRUSHDATA
&& M_BRUSHDATA
->m_macBrushKind
== kwxMacBrushThemeBackground
)
209 *(Rect
*)extent
= M_BRUSHDATA
->m_macThemeBackgroundExtent
;
211 return M_BRUSHDATA
->m_macThemeBackground
;
219 short wxBrush::MacGetTheme() const
221 return (M_BRUSHDATA
? ((M_BRUSHDATA
->m_macBrushKind
== kwxMacBrushTheme
) ? M_BRUSHDATA
->m_macThemeBrush
: kThemeBrushBlack
) : kThemeBrushBlack
);
224 wxColour
& wxBrush::GetColour() const
226 return (M_BRUSHDATA
? M_BRUSHDATA
->m_colour
: wxNullColour
);
229 int wxBrush::GetStyle() const
231 return (M_BRUSHDATA
? M_BRUSHDATA
->m_style
: 0);
234 wxBitmap
*wxBrush::GetStipple() const
236 return (M_BRUSHDATA
? & M_BRUSHDATA
->m_stipple
: 0);
239 wxMacBrushKind
wxBrush::MacGetBrushKind() const
241 return (M_BRUSHDATA
? M_BRUSHDATA
->m_macBrushKind
: kwxMacBrushColour
);
244 bool wxBrush::operator == ( const wxBrush
& brush
) const
246 if (m_refData
== brush
.m_refData
) return true;
248 if (!m_refData
|| !brush
.m_refData
) return false;
250 return ( *(wxBrushRefData
*)m_refData
== *(wxBrushRefData
*)brush
.m_refData
);