]> git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/brush.cpp
fix extra indentation in wxHTML_ALIGN_JUSTIFY display (patch 1565375)
[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 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 wxObjectRefData* wxBrush::CreateRefData() const
126 {
127 return new wxBrushRefData;
128 }
129
130 wxObjectRefData* wxBrush::CloneRefData(const wxObjectRefData* data) const
131 {
132 return new wxBrushRefData(*wx_static_cast(const wxBrushRefData*, data));
133 }
134
135 void wxBrush::SetColour(const wxColour& col)
136 {
137 AllocExclusive();
138 M_BRUSHDATA->m_macBrushKind = kwxMacBrushColour;
139 M_BRUSHDATA->m_colour = col;
140
141 RealizeResource();
142 }
143
144 void wxBrush::SetColour(unsigned char r, unsigned char g, unsigned char b)
145 {
146 AllocExclusive();
147
148 M_BRUSHDATA->m_macBrushKind = kwxMacBrushColour;
149 M_BRUSHDATA->m_colour.Set(r, g, b);
150
151 RealizeResource();
152 }
153
154 void wxBrush::SetStyle(int Style)
155 {
156 AllocExclusive();
157
158 M_BRUSHDATA->m_macBrushKind = kwxMacBrushColour;
159 M_BRUSHDATA->m_style = Style;
160
161 RealizeResource();
162 }
163
164 void wxBrush::SetStipple(const wxBitmap& Stipple)
165 {
166 AllocExclusive();
167
168 M_BRUSHDATA->m_macBrushKind = kwxMacBrushColour;
169 M_BRUSHDATA->m_stipple = Stipple;
170
171 RealizeResource();
172 }
173
174 void wxBrush::MacSetTheme(ThemeBrush macThemeBrush)
175 {
176 AllocExclusive();
177
178 M_BRUSHDATA->m_macBrushKind = kwxMacBrushTheme;
179 M_BRUSHDATA->m_macThemeBrush = macThemeBrush;
180
181 RGBColor color ;
182 GetThemeBrushAsColor( macThemeBrush , 32, true, &color );
183 M_BRUSHDATA->m_colour = color;
184
185 RealizeResource();
186 }
187
188 void wxBrush::MacSetThemeBackground(unsigned long macThemeBackground, const WXRECTPTR extent)
189 {
190 AllocExclusive();
191
192 M_BRUSHDATA->m_macBrushKind = kwxMacBrushThemeBackground;
193 M_BRUSHDATA->m_macThemeBackground = macThemeBackground;
194 M_BRUSHDATA->m_macThemeBackgroundExtent = *(Rect*)extent;
195
196 RealizeResource();
197 }
198
199 bool wxBrush::RealizeResource()
200 {
201 return true;
202 }
203
204 unsigned long wxBrush::MacGetThemeBackground(WXRECTPTR extent) const
205 {
206 if ( M_BRUSHDATA && M_BRUSHDATA->m_macBrushKind == kwxMacBrushThemeBackground )
207 {
208 if ( extent )
209 *(Rect*)extent = M_BRUSHDATA->m_macThemeBackgroundExtent;
210
211 return M_BRUSHDATA->m_macThemeBackground;
212 }
213 else
214 {
215 return 0;
216 }
217 }
218
219 short wxBrush::MacGetTheme() const
220 {
221 return (M_BRUSHDATA ? ((M_BRUSHDATA->m_macBrushKind == kwxMacBrushTheme) ? M_BRUSHDATA->m_macThemeBrush : kThemeBrushBlack) : kThemeBrushBlack);
222 }
223
224 wxColour& wxBrush::GetColour() const
225 {
226 return (M_BRUSHDATA ? M_BRUSHDATA->m_colour : wxNullColour);
227 }
228
229 int wxBrush::GetStyle() const
230 {
231 return (M_BRUSHDATA ? M_BRUSHDATA->m_style : 0);
232 }
233
234 wxBitmap *wxBrush::GetStipple() const
235 {
236 return (M_BRUSHDATA ? & M_BRUSHDATA->m_stipple : 0);
237 }
238
239 wxMacBrushKind wxBrush::MacGetBrushKind() const
240 {
241 return (M_BRUSHDATA ? M_BRUSHDATA->m_macBrushKind : kwxMacBrushColour);
242 }
243
244 bool wxBrush::operator == ( const wxBrush& brush ) const
245 {
246 if (m_refData == brush.m_refData) return true;
247
248 if (!m_refData || !brush.m_refData) return false;
249
250 return ( *(wxBrushRefData*)m_refData == *(wxBrushRefData*)brush.m_refData );
251 }