1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Stefan Csomor
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
13 #pragma implementation "brush.h"
16 #include "wx/wxprec.h"
21 #include "wx/mac/private.h"
23 #if !USE_SHARED_LIBRARIES
24 IMPLEMENT_DYNAMIC_CLASS(wxBrush
, wxGDIObject
)
27 class WXDLLEXPORT wxBrushRefData
: public wxGDIRefData
29 friend class WXDLLEXPORT wxBrush
;
32 wxBrushRefData(const wxBrushRefData
& data
);
36 wxMacBrushKind m_macBrushKind
;
41 ThemeBrush m_macThemeBrush
;
43 ThemeBackgroundKind m_macThemeBackground
;
44 Rect m_macThemeBackgroundExtent
;
47 #define M_BRUSHDATA ((wxBrushRefData *)m_refData)
49 wxBrushRefData::wxBrushRefData()
52 m_macBrushKind
= kwxMacBrushColour
;
55 wxBrushRefData::wxBrushRefData(const wxBrushRefData
& data
)
57 , m_style(data
.m_style
)
59 m_stipple
= data
.m_stipple
;
60 m_colour
= data
.m_colour
;
61 m_macBrushKind
= data
.m_macBrushKind
;
62 m_macThemeBrush
= data
.m_macThemeBrush
;
63 m_macThemeBackground
= data
.m_macThemeBackground
;
64 m_macThemeBackgroundExtent
= data
.m_macThemeBackgroundExtent
;
67 wxBrushRefData::~wxBrushRefData()
80 wxBrush::wxBrush(const wxColour
& col
, int Style
)
82 m_refData
= new wxBrushRefData
;
84 M_BRUSHDATA
->m_colour
= col
;
85 M_BRUSHDATA
->m_style
= Style
;
90 wxBrush::wxBrush(const wxBitmap
& stipple
)
92 m_refData
= new wxBrushRefData
;
94 M_BRUSHDATA
->m_colour
= *wxBLACK
;
95 M_BRUSHDATA
->m_stipple
= stipple
;
97 if (M_BRUSHDATA
->m_stipple
.GetMask())
98 M_BRUSHDATA
->m_style
= wxSTIPPLE_MASK_OPAQUE
;
100 M_BRUSHDATA
->m_style
= wxSTIPPLE
;
105 wxBrush::wxBrush(ThemeBrush macThemeBrush
)
107 m_refData
= new wxBrushRefData
;
109 M_BRUSHDATA
->m_macBrushKind
= kwxMacBrushTheme
;
110 M_BRUSHDATA
->m_macThemeBrush
= macThemeBrush
;
114 void wxBrush::Unshare()
116 // Don't change shared data
119 m_refData
= new wxBrushRefData();
123 wxBrushRefData
* ref
= new wxBrushRefData(*(wxBrushRefData
*)m_refData
);
129 void wxBrush::SetColour(const wxColour
& col
)
132 M_BRUSHDATA
->m_macBrushKind
= kwxMacBrushColour
;
133 M_BRUSHDATA
->m_colour
= col
;
138 void wxBrush::SetColour(unsigned char r
, unsigned char g
, unsigned char b
)
142 M_BRUSHDATA
->m_macBrushKind
= kwxMacBrushColour
;
143 M_BRUSHDATA
->m_colour
.Set(r
, g
, b
);
148 void wxBrush::SetStyle(int Style
)
152 M_BRUSHDATA
->m_macBrushKind
= kwxMacBrushColour
;
153 M_BRUSHDATA
->m_style
= Style
;
158 void wxBrush::SetStipple(const wxBitmap
& Stipple
)
162 M_BRUSHDATA
->m_macBrushKind
= kwxMacBrushColour
;
163 M_BRUSHDATA
->m_stipple
= Stipple
;
168 void wxBrush::MacSetTheme(ThemeBrush macThemeBrush
)
172 M_BRUSHDATA
->m_macBrushKind
= kwxMacBrushTheme
;
173 M_BRUSHDATA
->m_macThemeBrush
= macThemeBrush
;
175 GetThemeBrushAsColor( macThemeBrush
, 32, true, &color
);
176 M_BRUSHDATA
->m_colour
.Set( color
.red
>> 8 , color
.green
>> 8 , color
.blue
>> 8 ) ;
181 void wxBrush::MacSetThemeBackground(unsigned long macThemeBackground
, const WXRECTPTR extent
)
185 M_BRUSHDATA
->m_macBrushKind
= kwxMacBrushThemeBackground
;
186 M_BRUSHDATA
->m_macThemeBackground
= macThemeBackground
;
187 M_BRUSHDATA
->m_macThemeBackgroundExtent
= *(Rect
*)extent
;
191 bool wxBrush::RealizeResource()
196 unsigned long wxBrush::MacGetThemeBackground( WXRECTPTR extent
) const
198 if ( M_BRUSHDATA
&& M_BRUSHDATA
->m_macBrushKind
== kwxMacBrushThemeBackground
)
201 *(Rect
*)extent
= M_BRUSHDATA
->m_macThemeBackgroundExtent
;
202 return M_BRUSHDATA
->m_macThemeBackground
;
210 short wxBrush::MacGetTheme() const
212 return (M_BRUSHDATA
? ( M_BRUSHDATA
->m_macBrushKind
== kwxMacBrushTheme
? M_BRUSHDATA
->m_macThemeBrush
: kThemeBrushBlack
) : kThemeBrushBlack
);
215 wxColour
& wxBrush::GetColour() const
217 return (M_BRUSHDATA
? M_BRUSHDATA
->m_colour
: wxNullColour
);
220 int wxBrush::GetStyle() const
222 return (M_BRUSHDATA
? M_BRUSHDATA
->m_style
: 0);
225 wxBitmap
*wxBrush::GetStipple() const
227 return (M_BRUSHDATA
? & M_BRUSHDATA
->m_stipple
: 0);
230 wxMacBrushKind
wxBrush::MacGetBrushKind() const
232 return (M_BRUSHDATA
? M_BRUSHDATA
->m_macBrushKind
: kwxMacBrushColour
);