1 /////////////////////////////////////////////////////////////////////////////
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::MacSetTheme(ThemeBrush macThemeBrush
)
166 M_BRUSHDATA
->m_macBrushKind
= kwxMacBrushTheme
;
167 M_BRUSHDATA
->m_macThemeBrush
= macThemeBrush
;
169 GetThemeBrushAsColor( macThemeBrush
, 32, true, &color
);
170 M_BRUSHDATA
->m_colour
.Set( color
.red
>> 8 , color
.green
>> 8 , color
.blue
>> 8 ) ;
175 void wxBrush::MacSetThemeBackground(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::MacGetThemeBackground( 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::MacGetTheme() 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
);