1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/mac/classic/brush.cpp
4 // Author: Stefan Csomor
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
16 #include "wx/mac/private.h"
18 IMPLEMENT_DYNAMIC_CLASS(wxBrush
, wxGDIObject
)
20 class WXDLLEXPORT wxBrushRefData
: public wxGDIRefData
22 friend class WXDLLEXPORT wxBrush
;
25 wxBrushRefData(const wxBrushRefData
& data
);
29 wxMacBrushKind m_macBrushKind
;
34 ThemeBrush m_macThemeBrush
;
36 ThemeBackgroundKind m_macThemeBackground
;
37 Rect m_macThemeBackgroundExtent
;
40 #define M_BRUSHDATA ((wxBrushRefData *)m_refData)
42 wxBrushRefData::wxBrushRefData()
45 m_macBrushKind
= kwxMacBrushColour
;
48 wxBrushRefData::wxBrushRefData(const wxBrushRefData
& data
)
50 , m_style(data
.m_style
)
52 m_stipple
= data
.m_stipple
;
53 m_colour
= data
.m_colour
;
54 m_macBrushKind
= data
.m_macBrushKind
;
55 m_macThemeBrush
= data
.m_macThemeBrush
;
56 m_macThemeBackground
= data
.m_macThemeBackground
;
57 m_macThemeBackgroundExtent
= data
.m_macThemeBackgroundExtent
;
60 wxBrushRefData::~wxBrushRefData()
73 wxBrush::wxBrush(const wxColour
& col
, int Style
)
75 m_refData
= new wxBrushRefData
;
77 M_BRUSHDATA
->m_colour
= col
;
78 M_BRUSHDATA
->m_style
= Style
;
83 wxBrush::wxBrush(const wxBitmap
& stipple
)
85 m_refData
= new wxBrushRefData
;
87 M_BRUSHDATA
->m_colour
= *wxBLACK
;
88 M_BRUSHDATA
->m_stipple
= stipple
;
90 if (M_BRUSHDATA
->m_stipple
.GetMask())
91 M_BRUSHDATA
->m_style
= wxSTIPPLE_MASK_OPAQUE
;
93 M_BRUSHDATA
->m_style
= wxSTIPPLE
;
98 wxBrush::wxBrush(ThemeBrush macThemeBrush
)
100 m_refData
= new wxBrushRefData
;
102 M_BRUSHDATA
->m_macBrushKind
= kwxMacBrushTheme
;
103 M_BRUSHDATA
->m_macThemeBrush
= macThemeBrush
;
107 void wxBrush::Unshare()
109 // Don't change shared data
112 m_refData
= new wxBrushRefData();
116 wxBrushRefData
* ref
= new wxBrushRefData(*(wxBrushRefData
*)m_refData
);
122 void wxBrush::SetColour(const wxColour
& col
)
125 M_BRUSHDATA
->m_macBrushKind
= kwxMacBrushColour
;
126 M_BRUSHDATA
->m_colour
= col
;
131 void wxBrush::SetColour(unsigned char r
, unsigned char g
, unsigned char b
)
135 M_BRUSHDATA
->m_macBrushKind
= kwxMacBrushColour
;
136 M_BRUSHDATA
->m_colour
.Set(r
, g
, b
);
141 void wxBrush::SetStyle(int Style
)
145 M_BRUSHDATA
->m_macBrushKind
= kwxMacBrushColour
;
146 M_BRUSHDATA
->m_style
= Style
;
151 void wxBrush::SetStipple(const wxBitmap
& Stipple
)
155 M_BRUSHDATA
->m_macBrushKind
= kwxMacBrushColour
;
156 M_BRUSHDATA
->m_stipple
= Stipple
;
161 void wxBrush::SetMacTheme(ThemeBrush macThemeBrush
)
165 M_BRUSHDATA
->m_macBrushKind
= kwxMacBrushTheme
;
166 M_BRUSHDATA
->m_macThemeBrush
= macThemeBrush
;
171 void wxBrush::SetMacThemeBackground(unsigned long macThemeBackground
, const WXRECTPTR extent
)
175 M_BRUSHDATA
->m_macBrushKind
= kwxMacBrushThemeBackground
;
176 M_BRUSHDATA
->m_macThemeBackground
= macThemeBackground
;
177 M_BRUSHDATA
->m_macThemeBackgroundExtent
= *(Rect
*)extent
;
181 bool wxBrush::RealizeResource()
186 unsigned long wxBrush::GetMacThemeBackground( WXRECTPTR extent
) const
188 if ( M_BRUSHDATA
&& M_BRUSHDATA
->m_macBrushKind
== kwxMacBrushThemeBackground
)
191 *(Rect
*)extent
= M_BRUSHDATA
->m_macThemeBackgroundExtent
;
192 return M_BRUSHDATA
->m_macThemeBackground
;
200 short wxBrush::GetMacTheme() const
202 return (M_BRUSHDATA
? ( M_BRUSHDATA
->m_macBrushKind
== kwxMacBrushTheme
? M_BRUSHDATA
->m_macThemeBrush
: kThemeBrushBlack
) : kThemeBrushBlack
);
205 wxColour
& wxBrush::GetColour() const
207 return (M_BRUSHDATA
? M_BRUSHDATA
->m_colour
: wxNullColour
);
210 int wxBrush::GetStyle() const
212 return (M_BRUSHDATA
? M_BRUSHDATA
->m_style
: 0);
215 wxBitmap
*wxBrush::GetStipple() const
217 return (M_BRUSHDATA
? & M_BRUSHDATA
->m_stipple
: 0);
220 wxMacBrushKind
wxBrush::MacGetBrushKind() const
222 return (M_BRUSHDATA
? M_BRUSHDATA
->m_macBrushKind
: kwxMacBrushColour
);