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"
17 #include "wx/mac/private.h"
19 IMPLEMENT_DYNAMIC_CLASS(wxBrush
, wxGDIObject
)
21 class WXDLLEXPORT wxBrushRefData
: public wxGDIRefData
23 friend class WXDLLEXPORT wxBrush
;
26 wxBrushRefData(const wxBrushRefData
& data
);
30 wxMacBrushKind m_macBrushKind
;
35 ThemeBrush m_macThemeBrush
;
37 ThemeBackgroundKind m_macThemeBackground
;
38 Rect m_macThemeBackgroundExtent
;
41 #define M_BRUSHDATA ((wxBrushRefData *)m_refData)
43 wxBrushRefData::wxBrushRefData()
46 m_macBrushKind
= kwxMacBrushColour
;
49 wxBrushRefData::wxBrushRefData(const wxBrushRefData
& data
)
51 , m_style(data
.m_style
)
53 m_stipple
= data
.m_stipple
;
54 m_colour
= data
.m_colour
;
55 m_macBrushKind
= data
.m_macBrushKind
;
56 m_macThemeBrush
= data
.m_macThemeBrush
;
57 m_macThemeBackground
= data
.m_macThemeBackground
;
58 m_macThemeBackgroundExtent
= data
.m_macThemeBackgroundExtent
;
61 wxBrushRefData::~wxBrushRefData()
74 wxBrush::wxBrush(const wxColour
& col
, int Style
)
76 m_refData
= new wxBrushRefData
;
78 M_BRUSHDATA
->m_colour
= col
;
79 M_BRUSHDATA
->m_style
= Style
;
84 wxBrush::wxBrush(const wxBitmap
& stipple
)
86 m_refData
= new wxBrushRefData
;
88 M_BRUSHDATA
->m_colour
= *wxBLACK
;
89 M_BRUSHDATA
->m_stipple
= stipple
;
91 if (M_BRUSHDATA
->m_stipple
.GetMask())
92 M_BRUSHDATA
->m_style
= wxSTIPPLE_MASK_OPAQUE
;
94 M_BRUSHDATA
->m_style
= wxSTIPPLE
;
99 wxBrush::wxBrush(ThemeBrush macThemeBrush
)
101 m_refData
= new wxBrushRefData
;
103 M_BRUSHDATA
->m_macBrushKind
= kwxMacBrushTheme
;
104 M_BRUSHDATA
->m_macThemeBrush
= macThemeBrush
;
108 void wxBrush::Unshare()
110 // Don't change shared data
113 m_refData
= new wxBrushRefData();
117 wxBrushRefData
* ref
= new wxBrushRefData(*(wxBrushRefData
*)m_refData
);
123 void wxBrush::SetColour(const wxColour
& col
)
126 M_BRUSHDATA
->m_macBrushKind
= kwxMacBrushColour
;
127 M_BRUSHDATA
->m_colour
= col
;
132 void wxBrush::SetColour(unsigned char r
, unsigned char g
, unsigned char b
)
136 M_BRUSHDATA
->m_macBrushKind
= kwxMacBrushColour
;
137 M_BRUSHDATA
->m_colour
.Set(r
, g
, b
);
142 void wxBrush::SetStyle(int Style
)
146 M_BRUSHDATA
->m_macBrushKind
= kwxMacBrushColour
;
147 M_BRUSHDATA
->m_style
= Style
;
152 void wxBrush::SetStipple(const wxBitmap
& Stipple
)
156 M_BRUSHDATA
->m_macBrushKind
= kwxMacBrushColour
;
157 M_BRUSHDATA
->m_stipple
= Stipple
;
162 void wxBrush::SetMacTheme(ThemeBrush macThemeBrush
)
166 M_BRUSHDATA
->m_macBrushKind
= kwxMacBrushTheme
;
167 M_BRUSHDATA
->m_macThemeBrush
= macThemeBrush
;
172 void wxBrush::SetMacThemeBackground(unsigned long macThemeBackground
, const WXRECTPTR extent
)
176 M_BRUSHDATA
->m_macBrushKind
= kwxMacBrushThemeBackground
;
177 M_BRUSHDATA
->m_macThemeBackground
= macThemeBackground
;
178 M_BRUSHDATA
->m_macThemeBackgroundExtent
= *(Rect
*)extent
;
182 bool wxBrush::RealizeResource()
187 unsigned long wxBrush::GetMacThemeBackground( WXRECTPTR extent
) const
189 if ( M_BRUSHDATA
&& M_BRUSHDATA
->m_macBrushKind
== kwxMacBrushThemeBackground
)
192 *(Rect
*)extent
= M_BRUSHDATA
->m_macThemeBackgroundExtent
;
193 return M_BRUSHDATA
->m_macThemeBackground
;
201 short wxBrush::GetMacTheme() const
203 return (M_BRUSHDATA
? ( M_BRUSHDATA
->m_macBrushKind
== kwxMacBrushTheme
? M_BRUSHDATA
->m_macThemeBrush
: kThemeBrushBlack
) : kThemeBrushBlack
);
206 wxColour
& wxBrush::GetColour() const
208 return (M_BRUSHDATA
? M_BRUSHDATA
->m_colour
: wxNullColour
);
211 int wxBrush::GetStyle() const
213 return (M_BRUSHDATA
? M_BRUSHDATA
->m_style
: 0);
216 wxBitmap
*wxBrush::GetStipple() const
218 return (M_BRUSHDATA
? & M_BRUSHDATA
->m_stipple
: 0);
221 wxMacBrushKind
wxBrush::MacGetBrushKind() const
223 return (M_BRUSHDATA
? M_BRUSHDATA
->m_macBrushKind
: kwxMacBrushColour
);