]> git.saurik.com Git - wxWidgets.git/blob - src/mac/classic/brush.cpp
Unicode compilation fixes
[wxWidgets.git] / src / mac / classic / brush.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/mac/classic/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 public:
28 wxBrushRefData();
29 wxBrushRefData(const wxBrushRefData& data);
30 virtual ~wxBrushRefData();
31
32 protected:
33 wxMacBrushKind m_macBrushKind ;
34 int m_style;
35 wxBitmap m_stipple ;
36 wxColour m_colour;
37
38 ThemeBrush m_macThemeBrush ;
39
40 ThemeBackgroundKind m_macThemeBackground ;
41 Rect m_macThemeBackgroundExtent ;
42 };
43
44 #define M_BRUSHDATA ((wxBrushRefData *)m_refData)
45
46 wxBrushRefData::wxBrushRefData()
47 : m_style(wxSOLID)
48 {
49 m_macBrushKind = kwxMacBrushColour ;
50 }
51
52 wxBrushRefData::wxBrushRefData(const wxBrushRefData& data)
53 : wxGDIRefData()
54 , m_style(data.m_style)
55 {
56 m_stipple = data.m_stipple;
57 m_colour = data.m_colour;
58 m_macBrushKind = data.m_macBrushKind ;
59 m_macThemeBrush = data.m_macThemeBrush ;
60 m_macThemeBackground = data.m_macThemeBackground ;
61 m_macThemeBackgroundExtent = data.m_macThemeBackgroundExtent ;
62 }
63
64 wxBrushRefData::~wxBrushRefData()
65 {
66 }
67
68 // Brushes
69 wxBrush::wxBrush()
70 {
71 }
72
73 wxBrush::~wxBrush()
74 {
75 }
76
77 wxBrush::wxBrush(const wxColour& col, int Style)
78 {
79 m_refData = new wxBrushRefData;
80
81 M_BRUSHDATA->m_colour = col;
82 M_BRUSHDATA->m_style = Style;
83
84 RealizeResource();
85 }
86
87 wxBrush::wxBrush(const wxBitmap& stipple)
88 {
89 m_refData = new wxBrushRefData;
90
91 M_BRUSHDATA->m_colour = *wxBLACK;
92 M_BRUSHDATA->m_stipple = stipple;
93
94 if (M_BRUSHDATA->m_stipple.GetMask())
95 M_BRUSHDATA->m_style = wxSTIPPLE_MASK_OPAQUE;
96 else
97 M_BRUSHDATA->m_style = wxSTIPPLE;
98
99 RealizeResource();
100 }
101
102 wxBrush::wxBrush(ThemeBrush macThemeBrush )
103 {
104 m_refData = new wxBrushRefData;
105
106 M_BRUSHDATA->m_macBrushKind = kwxMacBrushTheme;
107 M_BRUSHDATA->m_macThemeBrush = macThemeBrush;
108
109 RealizeResource();
110 }
111 void wxBrush::Unshare()
112 {
113 // Don't change shared data
114 if (!m_refData)
115 {
116 m_refData = new wxBrushRefData();
117 }
118 else
119 {
120 wxBrushRefData* ref = new wxBrushRefData(*(wxBrushRefData*)m_refData);
121 UnRef();
122 m_refData = ref;
123 }
124 }
125
126 void wxBrush::SetColour(const wxColour& col)
127 {
128 Unshare();
129 M_BRUSHDATA->m_macBrushKind = kwxMacBrushColour;
130 M_BRUSHDATA->m_colour = col;
131
132 RealizeResource();
133 }
134
135 void wxBrush::SetColour(unsigned char r, unsigned char g, unsigned char b)
136 {
137 Unshare();
138
139 M_BRUSHDATA->m_macBrushKind = kwxMacBrushColour;
140 M_BRUSHDATA->m_colour.Set(r, g, b);
141
142 RealizeResource();
143 }
144
145 void wxBrush::SetStyle(int Style)
146 {
147 Unshare();
148
149 M_BRUSHDATA->m_macBrushKind = kwxMacBrushColour;
150 M_BRUSHDATA->m_style = Style;
151
152 RealizeResource();
153 }
154
155 void wxBrush::SetStipple(const wxBitmap& Stipple)
156 {
157 Unshare();
158
159 M_BRUSHDATA->m_macBrushKind = kwxMacBrushColour;
160 M_BRUSHDATA->m_stipple = Stipple;
161
162 RealizeResource();
163 }
164
165 void wxBrush::SetMacTheme(ThemeBrush macThemeBrush)
166 {
167 Unshare();
168
169 M_BRUSHDATA->m_macBrushKind = kwxMacBrushTheme;
170 M_BRUSHDATA->m_macThemeBrush = macThemeBrush;
171
172 RealizeResource();
173 }
174
175 void wxBrush::SetMacThemeBackground(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::GetMacThemeBackground( 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::GetMacTheme() 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 }