]>
Commit | Line | Data |
---|---|---|
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 | 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 ; | |
187 | GetThemeBrushAsColor( macThemeBrush , 32, true, &color ); | |
188 | M_BRUSHDATA->m_colour = color; | |
189 | ||
190 | RealizeResource(); | |
191 | } | |
192 | ||
193 | void wxBrush::MacSetThemeBackground(unsigned long macThemeBackground, const WXRECTPTR extent) | |
194 | { | |
195 | Unshare(); | |
196 | ||
197 | M_BRUSHDATA->m_macBrushKind = kwxMacBrushThemeBackground; | |
198 | M_BRUSHDATA->m_macThemeBackground = macThemeBackground; | |
199 | M_BRUSHDATA->m_macThemeBackgroundExtent = *(Rect*)extent; | |
200 | ||
201 | RealizeResource(); | |
202 | } | |
203 | ||
204 | bool wxBrush::RealizeResource() | |
205 | { | |
206 | return true; | |
207 | } | |
208 | ||
209 | unsigned long wxBrush::MacGetThemeBackground(WXRECTPTR extent) const | |
210 | { | |
211 | if ( M_BRUSHDATA && M_BRUSHDATA->m_macBrushKind == kwxMacBrushThemeBackground ) | |
212 | { | |
213 | if ( extent ) | |
214 | *(Rect*)extent = M_BRUSHDATA->m_macThemeBackgroundExtent; | |
215 | ||
216 | return M_BRUSHDATA->m_macThemeBackground; | |
217 | } | |
218 | else | |
219 | { | |
220 | return 0; | |
221 | } | |
222 | } | |
223 | ||
224 | short wxBrush::MacGetTheme() const | |
225 | { | |
226 | return (M_BRUSHDATA ? ((M_BRUSHDATA->m_macBrushKind == kwxMacBrushTheme) ? M_BRUSHDATA->m_macThemeBrush : kThemeBrushBlack) : kThemeBrushBlack); | |
227 | } | |
228 | ||
229 | wxColour& wxBrush::GetColour() const | |
230 | { | |
231 | return (M_BRUSHDATA ? M_BRUSHDATA->m_colour : wxNullColour); | |
232 | } | |
233 | ||
234 | int wxBrush::GetStyle() const | |
235 | { | |
236 | return (M_BRUSHDATA ? M_BRUSHDATA->m_style : 0); | |
237 | } | |
238 | ||
239 | wxBitmap *wxBrush::GetStipple() const | |
240 | { | |
241 | return (M_BRUSHDATA ? & M_BRUSHDATA->m_stipple : 0); | |
242 | } | |
243 | ||
244 | wxMacBrushKind wxBrush::MacGetBrushKind() const | |
245 | { | |
246 | return (M_BRUSHDATA ? M_BRUSHDATA->m_macBrushKind : kwxMacBrushColour); | |
247 | } | |
248 | ||
249 | bool wxBrush::operator == ( const wxBrush& brush ) const | |
250 | { | |
251 | if (m_refData == brush.m_refData) return true; | |
252 | ||
253 | if (!m_refData || !brush.m_refData) return false; | |
254 | ||
255 | return ( *(wxBrushRefData*)m_refData == *(wxBrushRefData*)brush.m_refData ); | |
256 | } |