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 IMPLEMENT_DYNAMIC_CLASS(wxBrush
, wxGDIObject
)
25 class WXDLLEXPORT wxBrushRefData
: public wxGDIRefData
27 friend class WXDLLEXPORT wxBrush
;
30 wxBrushRefData(const wxBrushRefData
& data
);
34 wxMacBrushKind m_macBrushKind
;
39 ThemeBrush m_macThemeBrush
;
41 ThemeBackgroundKind m_macThemeBackground
;
42 Rect m_macThemeBackgroundExtent
;
45 #define M_BRUSHDATA ((wxBrushRefData *)m_refData)
47 wxBrushRefData::wxBrushRefData()
50 m_macBrushKind
= kwxMacBrushColour
;
53 wxBrushRefData::wxBrushRefData(const wxBrushRefData
& data
)
55 , m_style(data
.m_style
)
57 m_stipple
= data
.m_stipple
;
58 m_colour
= data
.m_colour
;
59 m_macBrushKind
= data
.m_macBrushKind
;
60 m_macThemeBrush
= data
.m_macThemeBrush
;
61 m_macThemeBackground
= data
.m_macThemeBackground
;
62 m_macThemeBackgroundExtent
= data
.m_macThemeBackgroundExtent
;
65 wxBrushRefData::~wxBrushRefData()
78 wxBrush::wxBrush(const wxColour
& col
, int Style
)
80 m_refData
= new wxBrushRefData
;
82 M_BRUSHDATA
->m_colour
= col
;
83 M_BRUSHDATA
->m_style
= Style
;
88 wxBrush::wxBrush(const wxBitmap
& stipple
)
90 m_refData
= new wxBrushRefData
;
92 M_BRUSHDATA
->m_colour
= *wxBLACK
;
93 M_BRUSHDATA
->m_stipple
= stipple
;
95 if (M_BRUSHDATA
->m_stipple
.GetMask())
96 M_BRUSHDATA
->m_style
= wxSTIPPLE_MASK_OPAQUE
;
98 M_BRUSHDATA
->m_style
= wxSTIPPLE
;
103 wxBrush::wxBrush(ThemeBrush macThemeBrush
)
105 m_refData
= new wxBrushRefData
;
107 M_BRUSHDATA
->m_macBrushKind
= kwxMacBrushTheme
;
108 M_BRUSHDATA
->m_macThemeBrush
= macThemeBrush
;
112 void wxBrush::Unshare()
114 // Don't change shared data
117 m_refData
= new wxBrushRefData();
121 wxBrushRefData
* ref
= new wxBrushRefData(*(wxBrushRefData
*)m_refData
);
127 void wxBrush::SetColour(const wxColour
& col
)
130 M_BRUSHDATA
->m_macBrushKind
= kwxMacBrushColour
;
131 M_BRUSHDATA
->m_colour
= col
;
136 void wxBrush::SetColour(unsigned char r
, unsigned char g
, unsigned char b
)
140 M_BRUSHDATA
->m_macBrushKind
= kwxMacBrushColour
;
141 M_BRUSHDATA
->m_colour
.Set(r
, g
, b
);
146 void wxBrush::SetStyle(int Style
)
150 M_BRUSHDATA
->m_macBrushKind
= kwxMacBrushColour
;
151 M_BRUSHDATA
->m_style
= Style
;
156 void wxBrush::SetStipple(const wxBitmap
& Stipple
)
160 M_BRUSHDATA
->m_macBrushKind
= kwxMacBrushColour
;
161 M_BRUSHDATA
->m_stipple
= Stipple
;
166 void wxBrush::MacSetTheme(ThemeBrush macThemeBrush
)
170 M_BRUSHDATA
->m_macBrushKind
= kwxMacBrushTheme
;
171 M_BRUSHDATA
->m_macThemeBrush
= macThemeBrush
;
173 GetThemeBrushAsColor( macThemeBrush
, 32, true, &color
);
174 M_BRUSHDATA
->m_colour
.Set( color
.red
>> 8 , color
.green
>> 8 , color
.blue
>> 8 ) ;
179 void wxBrush::MacSetThemeBackground(unsigned long macThemeBackground
, const WXRECTPTR extent
)
183 M_BRUSHDATA
->m_macBrushKind
= kwxMacBrushThemeBackground
;
184 M_BRUSHDATA
->m_macThemeBackground
= macThemeBackground
;
185 M_BRUSHDATA
->m_macThemeBackgroundExtent
= *(Rect
*)extent
;
189 bool wxBrush::RealizeResource()
194 unsigned long wxBrush::MacGetThemeBackground( WXRECTPTR extent
) const
196 if ( M_BRUSHDATA
&& M_BRUSHDATA
->m_macBrushKind
== kwxMacBrushThemeBackground
)
199 *(Rect
*)extent
= M_BRUSHDATA
->m_macThemeBackgroundExtent
;
200 return M_BRUSHDATA
->m_macThemeBackground
;
208 short wxBrush::MacGetTheme() const
210 return (M_BRUSHDATA
? ( M_BRUSHDATA
->m_macBrushKind
== kwxMacBrushTheme
? M_BRUSHDATA
->m_macThemeBrush
: kThemeBrushBlack
) : kThemeBrushBlack
);
213 wxColour
& wxBrush::GetColour() const
215 return (M_BRUSHDATA
? M_BRUSHDATA
->m_colour
: wxNullColour
);
218 int wxBrush::GetStyle() const
220 return (M_BRUSHDATA
? M_BRUSHDATA
->m_style
: 0);
223 wxBitmap
*wxBrush::GetStipple() const
225 return (M_BRUSHDATA
? & M_BRUSHDATA
->m_stipple
: 0);
228 wxMacBrushKind
wxBrush::MacGetBrushKind() const
230 return (M_BRUSHDATA
? M_BRUSHDATA
->m_macBrushKind
: kwxMacBrushColour
);