]> git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/brush.cpp
make sure we catch invalid control refs better
[wxWidgets.git] / src / mac / carbon / brush.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/mac/carbon/brush.cpp
3 // Purpose: wxBrush
4 // Author: Stefan Csomor
5 // Modified by:
6 // Created: 1998-01-01
7 // RCS-ID: $Id$
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #include "wx/wxprec.h"
13
14 #include "wx/brush.h"
15
16 #ifndef WX_PRECOMP
17 #include "wx/utils.h"
18 #endif
19
20 #include "wx/mac/private.h"
21
22 IMPLEMENT_DYNAMIC_CLASS(wxBrush, wxGDIObject)
23
24 class WXDLLEXPORT wxBrushRefData: public wxGDIRefData
25 {
26 friend class WXDLLEXPORT wxBrush;
27
28 public:
29 wxBrushRefData();
30 wxBrushRefData(const wxBrushRefData& data);
31 virtual ~wxBrushRefData();
32
33 protected:
34 wxMacBrushKind m_macBrushKind ;
35 int m_style;
36 wxBitmap m_stipple ;
37 wxColour m_colour;
38
39 ThemeBrush m_macThemeBrush ;
40
41 ThemeBackgroundKind m_macThemeBackground ;
42 Rect m_macThemeBackgroundExtent ;
43 };
44
45 #define M_BRUSHDATA ((wxBrushRefData *)m_refData)
46
47
48 wxBrushRefData::wxBrushRefData()
49 : m_style(wxSOLID)
50 {
51 m_macBrushKind = kwxMacBrushColour ;
52 }
53
54 wxBrushRefData::wxBrushRefData(const wxBrushRefData& data)
55 : wxGDIRefData()
56 , m_style(data.m_style)
57 {
58 m_stipple = data.m_stipple;
59 m_colour = data.m_colour;
60 m_macBrushKind = data.m_macBrushKind ;
61 m_macThemeBrush = data.m_macThemeBrush ;
62 m_macThemeBackground = data.m_macThemeBackground ;
63 m_macThemeBackgroundExtent = data.m_macThemeBackgroundExtent ;
64 }
65
66 wxBrushRefData::~wxBrushRefData()
67 {
68 }
69
70 wxBrush::wxBrush()
71 {
72 }
73
74 wxBrush::~wxBrush()
75 {
76 }
77
78 wxBrush::wxBrush(const wxColour& col, int Style)
79 {
80 m_refData = new wxBrushRefData;
81
82 M_BRUSHDATA->m_colour = col;
83 M_BRUSHDATA->m_style = Style;
84
85 RealizeResource();
86 }
87
88 wxBrush::wxBrush(const wxBitmap& stipple)
89 {
90 m_refData = new wxBrushRefData;
91
92 M_BRUSHDATA->m_colour = *wxBLACK;
93 M_BRUSHDATA->m_stipple = stipple;
94
95 if (M_BRUSHDATA->m_stipple.GetMask())
96 M_BRUSHDATA->m_style = wxSTIPPLE_MASK_OPAQUE;
97 else
98 M_BRUSHDATA->m_style = wxSTIPPLE;
99
100 RealizeResource();
101 }
102
103 wxBrush::wxBrush( ThemeBrush macThemeBrush )
104 {
105 m_refData = new wxBrushRefData;
106
107 M_BRUSHDATA->m_macBrushKind = kwxMacBrushTheme;
108 M_BRUSHDATA->m_macThemeBrush = macThemeBrush;
109
110 RealizeResource();
111 }
112
113 void wxBrush::Unshare()
114 {
115 // Don't change shared data
116 if (!m_refData)
117 {
118 m_refData = new wxBrushRefData();
119 }
120 else
121 {
122 wxBrushRefData* ref = new wxBrushRefData(*(wxBrushRefData*)m_refData);
123 UnRef();
124 m_refData = ref;
125 }
126 }
127
128 void wxBrush::SetColour(const wxColour& col)
129 {
130 Unshare();
131 M_BRUSHDATA->m_macBrushKind = kwxMacBrushColour;
132 M_BRUSHDATA->m_colour = col;
133
134 RealizeResource();
135 }
136
137 void wxBrush::SetColour(unsigned char r, unsigned char g, unsigned char b)
138 {
139 Unshare();
140
141 M_BRUSHDATA->m_macBrushKind = kwxMacBrushColour;
142 M_BRUSHDATA->m_colour.Set(r, g, b);
143
144 RealizeResource();
145 }
146
147 void wxBrush::SetStyle(int Style)
148 {
149 Unshare();
150
151 M_BRUSHDATA->m_macBrushKind = kwxMacBrushColour;
152 M_BRUSHDATA->m_style = Style;
153
154 RealizeResource();
155 }
156
157 void wxBrush::SetStipple(const wxBitmap& Stipple)
158 {
159 Unshare();
160
161 M_BRUSHDATA->m_macBrushKind = kwxMacBrushColour;
162 M_BRUSHDATA->m_stipple = Stipple;
163
164 RealizeResource();
165 }
166
167 void wxBrush::MacSetTheme(ThemeBrush macThemeBrush)
168 {
169 Unshare();
170
171 M_BRUSHDATA->m_macBrushKind = kwxMacBrushTheme;
172 M_BRUSHDATA->m_macThemeBrush = macThemeBrush;
173
174 RGBColor color ;
175 GetThemeBrushAsColor( macThemeBrush , 32, true, &color );
176 M_BRUSHDATA->m_colour.Set( color.red >> 8 , color.green >> 8 , color.blue >> 8 );
177
178 RealizeResource();
179 }
180
181 void wxBrush::MacSetThemeBackground(unsigned long macThemeBackground, const WXRECTPTR extent)
182 {
183 Unshare();
184
185 M_BRUSHDATA->m_macBrushKind = kwxMacBrushThemeBackground;
186 M_BRUSHDATA->m_macThemeBackground = macThemeBackground;
187 M_BRUSHDATA->m_macThemeBackgroundExtent = *(Rect*)extent;
188
189 RealizeResource();
190 }
191
192 bool wxBrush::RealizeResource()
193 {
194 return true;
195 }
196
197 unsigned long wxBrush::MacGetThemeBackground(WXRECTPTR extent) const
198 {
199 if ( M_BRUSHDATA && M_BRUSHDATA->m_macBrushKind == kwxMacBrushThemeBackground )
200 {
201 if ( extent )
202 *(Rect*)extent = M_BRUSHDATA->m_macThemeBackgroundExtent;
203
204 return M_BRUSHDATA->m_macThemeBackground;
205 }
206 else
207 {
208 return 0;
209 }
210 }
211
212 short wxBrush::MacGetTheme() const
213 {
214 return (M_BRUSHDATA ? ((M_BRUSHDATA->m_macBrushKind == kwxMacBrushTheme) ? M_BRUSHDATA->m_macThemeBrush : kThemeBrushBlack) : kThemeBrushBlack);
215 }
216
217 wxColour& wxBrush::GetColour() const
218 {
219 return (M_BRUSHDATA ? M_BRUSHDATA->m_colour : wxNullColour);
220 }
221
222 int wxBrush::GetStyle() const
223 {
224 return (M_BRUSHDATA ? M_BRUSHDATA->m_style : 0);
225 }
226
227 wxBitmap *wxBrush::GetStipple() const
228 {
229 return (M_BRUSHDATA ? & M_BRUSHDATA->m_stipple : 0);
230 }
231
232 wxMacBrushKind wxBrush::MacGetBrushKind() const
233 {
234 return (M_BRUSHDATA ? M_BRUSHDATA->m_macBrushKind : kwxMacBrushColour);
235 }