]> git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/brush.cpp
cleanup and cgcolor changeds
[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 wxBrush;
27
28 public:
29 wxBrushRefData();
30 wxBrushRefData(const wxBrushRefData& data);
31 virtual ~wxBrushRefData();
32
33 bool operator == ( const wxBrushRefData& brush ) const
34 {
35 return m_style == brush.m_style &&
36 m_stipple.IsSameAs(brush.m_stipple) &&
37 m_colour == brush.m_colour &&
38 m_macBrushKind == brush.m_macBrushKind &&
39 m_macThemeBrush == brush.m_macThemeBrush &&
40 m_macThemeBackground == brush.m_macThemeBackground &&
41 EqualRect(&m_macThemeBackgroundExtent, &brush.m_macThemeBackgroundExtent);
42 }
43
44
45 protected:
46 wxMacBrushKind m_macBrushKind ;
47 int m_style;
48 wxBitmap m_stipple ;
49 wxColour m_colour;
50
51 ThemeBrush m_macThemeBrush ;
52
53 ThemeBackgroundKind m_macThemeBackground ;
54 Rect m_macThemeBackgroundExtent ;
55 };
56
57 #define M_BRUSHDATA ((wxBrushRefData *)m_refData)
58
59
60 wxBrushRefData::wxBrushRefData()
61 : m_style(wxSOLID)
62 {
63 m_macBrushKind = kwxMacBrushColour ;
64 }
65
66 wxBrushRefData::wxBrushRefData(const wxBrushRefData& data)
67 : wxGDIRefData()
68 , m_style(data.m_style)
69 {
70 m_stipple = data.m_stipple;
71 m_colour = data.m_colour;
72 m_macBrushKind = data.m_macBrushKind ;
73 m_macThemeBrush = data.m_macThemeBrush ;
74 m_macThemeBackground = data.m_macThemeBackground ;
75 m_macThemeBackgroundExtent = data.m_macThemeBackgroundExtent ;
76 }
77
78 wxBrushRefData::~wxBrushRefData()
79 {
80 }
81
82 wxBrush::wxBrush()
83 {
84 }
85
86 wxBrush::~wxBrush()
87 {
88 }
89
90 wxBrush::wxBrush(const wxColour& col, int Style)
91 {
92 m_refData = new wxBrushRefData;
93
94 M_BRUSHDATA->m_colour = col;
95 M_BRUSHDATA->m_style = Style;
96
97 RealizeResource();
98 }
99
100 wxBrush::wxBrush(const wxBitmap& stipple)
101 {
102 m_refData = new wxBrushRefData;
103
104 M_BRUSHDATA->m_colour = *wxBLACK;
105 M_BRUSHDATA->m_stipple = stipple;
106
107 if (M_BRUSHDATA->m_stipple.GetMask())
108 M_BRUSHDATA->m_style = wxSTIPPLE_MASK_OPAQUE;
109 else
110 M_BRUSHDATA->m_style = wxSTIPPLE;
111
112 RealizeResource();
113 }
114
115 wxBrush::wxBrush( ThemeBrush macThemeBrush )
116 {
117 m_refData = new wxBrushRefData;
118
119 M_BRUSHDATA->m_macBrushKind = kwxMacBrushTheme;
120 M_BRUSHDATA->m_macThemeBrush = macThemeBrush;
121
122 RealizeResource();
123 }
124
125 void wxBrush::Unshare()
126 {
127 // Don't change shared data
128 if (!m_refData)
129 {
130 m_refData = new wxBrushRefData();
131 }
132 else
133 {
134 wxBrushRefData* ref = new wxBrushRefData(*(wxBrushRefData*)m_refData);
135 UnRef();
136 m_refData = ref;
137 }
138 }
139
140 void wxBrush::SetColour(const wxColour& col)
141 {
142 Unshare();
143 M_BRUSHDATA->m_macBrushKind = kwxMacBrushColour;
144 M_BRUSHDATA->m_colour = col;
145
146 RealizeResource();
147 }
148
149 void wxBrush::SetColour(unsigned char r, unsigned char g, unsigned char b)
150 {
151 Unshare();
152
153 M_BRUSHDATA->m_macBrushKind = kwxMacBrushColour;
154 M_BRUSHDATA->m_colour.Set(r, g, b);
155
156 RealizeResource();
157 }
158
159 void wxBrush::SetStyle(int Style)
160 {
161 Unshare();
162
163 M_BRUSHDATA->m_macBrushKind = kwxMacBrushColour;
164 M_BRUSHDATA->m_style = Style;
165
166 RealizeResource();
167 }
168
169 void wxBrush::SetStipple(const wxBitmap& Stipple)
170 {
171 Unshare();
172
173 M_BRUSHDATA->m_macBrushKind = kwxMacBrushColour;
174 M_BRUSHDATA->m_stipple = Stipple;
175
176 RealizeResource();
177 }
178
179 void wxBrush::MacSetTheme(ThemeBrush macThemeBrush)
180 {
181 Unshare();
182
183 M_BRUSHDATA->m_macBrushKind = kwxMacBrushTheme;
184 M_BRUSHDATA->m_macThemeBrush = macThemeBrush;
185
186 RGBColor color = { 0,0,0 } ;
187 #ifdef __LP64__
188 CGColorRef colorref = 0;
189 HIThemeBrushCreateCGColor( macThemeBrush, &colorref );
190 size_t noComp = CGColorGetNumberOfComponents( colorref );
191 if ( noComp >=3 && noComp <= 4 )
192 {
193 // TODO verify whether we really are on a RGB color space
194 const CGFloat *components = CGColorGetComponents( colorref );
195 color.red = (int)(components[0]*255+0.5);
196 color.green = (int)(components[1]*255+0.5);
197 color.blue = (int)(components[2]*255+0.5);
198 }
199 CFRelease( colorref );
200 #else
201 GetThemeBrushAsColor( macThemeBrush , 32, true, &color );
202 #endif
203 M_BRUSHDATA->m_colour = color;
204
205 RealizeResource();
206 }
207
208 /* TODO REMOVE
209 void wxBrush::MacSetThemeBackground(unsigned long macThemeBackground, const WXRECTPTR extent)
210 {
211 Unshare();
212
213 M_BRUSHDATA->m_macBrushKind = kwxMacBrushThemeBackground;
214 M_BRUSHDATA->m_macThemeBackground = macThemeBackground;
215 M_BRUSHDATA->m_macThemeBackgroundExtent = *(Rect*)extent;
216
217 RealizeResource();
218 }
219 */
220
221 bool wxBrush::RealizeResource()
222 {
223 return true;
224 }
225
226 /*
227 unsigned long wxBrush::MacGetThemeBackground(WXRECTPTR extent) const
228 {
229 if ( M_BRUSHDATA && M_BRUSHDATA->m_macBrushKind == kwxMacBrushThemeBackground )
230 {
231 if ( extent )
232 *(Rect*)extent = M_BRUSHDATA->m_macThemeBackgroundExtent;
233
234 return M_BRUSHDATA->m_macThemeBackground;
235 }
236 else
237 {
238 return 0;
239 }
240 }
241 */
242
243 short wxBrush::MacGetTheme() const
244 {
245 return (M_BRUSHDATA ? ((M_BRUSHDATA->m_macBrushKind == kwxMacBrushTheme) ? M_BRUSHDATA->m_macThemeBrush : kThemeBrushBlack) : kThemeBrushBlack);
246 }
247
248 wxColour& wxBrush::GetColour() const
249 {
250 return (M_BRUSHDATA ? M_BRUSHDATA->m_colour : wxNullColour);
251 }
252
253 int wxBrush::GetStyle() const
254 {
255 return (M_BRUSHDATA ? M_BRUSHDATA->m_style : 0);
256 }
257
258 wxBitmap *wxBrush::GetStipple() const
259 {
260 return (M_BRUSHDATA ? & M_BRUSHDATA->m_stipple : 0);
261 }
262
263 wxMacBrushKind wxBrush::MacGetBrushKind() const
264 {
265 return (M_BRUSHDATA ? M_BRUSHDATA->m_macBrushKind : kwxMacBrushColour);
266 }
267
268 bool wxBrush::operator == ( const wxBrush& brush ) const
269 {
270 if (m_refData == brush.m_refData) return true;
271
272 if (!m_refData || !brush.m_refData) return false;
273
274 return ( *(wxBrushRefData*)m_refData == *(wxBrushRefData*)brush.m_refData );
275 }