1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/mac/classic/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
;
29 wxBrushRefData(const wxBrushRefData
& data
);
33 wxMacBrushKind m_macBrushKind
;
38 ThemeBrush m_macThemeBrush
;
40 ThemeBackgroundKind m_macThemeBackground
;
41 Rect m_macThemeBackgroundExtent
;
44 #define M_BRUSHDATA ((wxBrushRefData *)m_refData)
46 wxBrushRefData::wxBrushRefData()
49 m_macBrushKind
= kwxMacBrushColour
;
52 wxBrushRefData::wxBrushRefData(const wxBrushRefData
& data
)
54 , m_style(data
.m_style
)
56 m_stipple
= data
.m_stipple
;
57 m_colour
= data
.m_colour
;
58 m_macBrushKind
= data
.m_macBrushKind
;
59 m_macThemeBrush
= data
.m_macThemeBrush
;
60 m_macThemeBackground
= data
.m_macThemeBackground
;
61 m_macThemeBackgroundExtent
= data
.m_macThemeBackgroundExtent
;
64 wxBrushRefData::~wxBrushRefData()
77 wxBrush::wxBrush(const wxColour
& col
, int Style
)
79 m_refData
= new wxBrushRefData
;
81 M_BRUSHDATA
->m_colour
= col
;
82 M_BRUSHDATA
->m_style
= Style
;
87 wxBrush::wxBrush(const wxBitmap
& stipple
)
89 m_refData
= new wxBrushRefData
;
91 M_BRUSHDATA
->m_colour
= *wxBLACK
;
92 M_BRUSHDATA
->m_stipple
= stipple
;
94 if (M_BRUSHDATA
->m_stipple
.GetMask())
95 M_BRUSHDATA
->m_style
= wxSTIPPLE_MASK_OPAQUE
;
97 M_BRUSHDATA
->m_style
= wxSTIPPLE
;
102 wxBrush::wxBrush(ThemeBrush macThemeBrush
)
104 m_refData
= new wxBrushRefData
;
106 M_BRUSHDATA
->m_macBrushKind
= kwxMacBrushTheme
;
107 M_BRUSHDATA
->m_macThemeBrush
= macThemeBrush
;
111 void wxBrush::Unshare()
113 // Don't change shared data
116 m_refData
= new wxBrushRefData();
120 wxBrushRefData
* ref
= new wxBrushRefData(*(wxBrushRefData
*)m_refData
);
126 void wxBrush::SetColour(const wxColour
& col
)
129 M_BRUSHDATA
->m_macBrushKind
= kwxMacBrushColour
;
130 M_BRUSHDATA
->m_colour
= col
;
135 void wxBrush::SetColour(unsigned char r
, unsigned char g
, unsigned char b
)
139 M_BRUSHDATA
->m_macBrushKind
= kwxMacBrushColour
;
140 M_BRUSHDATA
->m_colour
.Set(r
, g
, b
);
145 void wxBrush::SetStyle(int Style
)
149 M_BRUSHDATA
->m_macBrushKind
= kwxMacBrushColour
;
150 M_BRUSHDATA
->m_style
= Style
;
155 void wxBrush::SetStipple(const wxBitmap
& Stipple
)
159 M_BRUSHDATA
->m_macBrushKind
= kwxMacBrushColour
;
160 M_BRUSHDATA
->m_stipple
= Stipple
;
165 void wxBrush::SetMacTheme(ThemeBrush macThemeBrush
)
169 M_BRUSHDATA
->m_macBrushKind
= kwxMacBrushTheme
;
170 M_BRUSHDATA
->m_macThemeBrush
= macThemeBrush
;
175 void wxBrush::SetMacThemeBackground(unsigned long macThemeBackground
, const WXRECTPTR extent
)
179 M_BRUSHDATA
->m_macBrushKind
= kwxMacBrushThemeBackground
;
180 M_BRUSHDATA
->m_macThemeBackground
= macThemeBackground
;
181 M_BRUSHDATA
->m_macThemeBackgroundExtent
= *(Rect
*)extent
;
185 bool wxBrush::RealizeResource()
190 unsigned long wxBrush::GetMacThemeBackground( WXRECTPTR extent
) const
192 if ( M_BRUSHDATA
&& M_BRUSHDATA
->m_macBrushKind
== kwxMacBrushThemeBackground
)
195 *(Rect
*)extent
= M_BRUSHDATA
->m_macThemeBackgroundExtent
;
196 return M_BRUSHDATA
->m_macThemeBackground
;
204 short wxBrush::GetMacTheme() const
206 return (M_BRUSHDATA
? ( M_BRUSHDATA
->m_macBrushKind
== kwxMacBrushTheme
? M_BRUSHDATA
->m_macThemeBrush
: kThemeBrushBlack
) : kThemeBrushBlack
);
209 wxColour
& wxBrush::GetColour() const
211 return (M_BRUSHDATA
? M_BRUSHDATA
->m_colour
: wxNullColour
);
214 int wxBrush::GetStyle() const
216 return (M_BRUSHDATA
? M_BRUSHDATA
->m_style
: 0);
219 wxBitmap
*wxBrush::GetStipple() const
221 return (M_BRUSHDATA
? & M_BRUSHDATA
->m_stipple
: 0);
224 wxMacBrushKind
wxBrush::MacGetBrushKind() const
226 return (M_BRUSHDATA
? M_BRUSHDATA
->m_macBrushKind
: kwxMacBrushColour
);