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