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