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