]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/mac/carbon/brush.cpp
Fix for incorrect error message report that caused wxMediaCtrl not to play MPEGs.
[wxWidgets.git] / src / mac / carbon / brush.cpp
... / ...
CommitLineData
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
22IMPLEMENT_DYNAMIC_CLASS(wxBrush, wxGDIObject)
23
24class WXDLLEXPORT wxBrushRefData: public wxGDIRefData
25{
26 friend class WXDLLEXPORT wxBrush;
27
28public:
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
45protected:
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
60wxBrushRefData::wxBrushRefData()
61 : m_style(wxSOLID)
62{
63 m_macBrushKind = kwxMacBrushColour ;
64}
65
66wxBrushRefData::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
78wxBrushRefData::~wxBrushRefData()
79{
80}
81
82wxBrush::wxBrush()
83{
84}
85
86wxBrush::~wxBrush()
87{
88}
89
90wxBrush::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
100wxBrush::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
115wxBrush::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
125void 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
140void 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
149void 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
159void 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
169void 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
179void 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.Set( color.red >> 8 , color.green >> 8 , color.blue >> 8 );
189
190 RealizeResource();
191}
192
193void 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
204bool wxBrush::RealizeResource()
205{
206 return true;
207}
208
209unsigned 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
224short wxBrush::MacGetTheme() const
225{
226 return (M_BRUSHDATA ? ((M_BRUSHDATA->m_macBrushKind == kwxMacBrushTheme) ? M_BRUSHDATA->m_macThemeBrush : kThemeBrushBlack) : kThemeBrushBlack);
227}
228
229wxColour& wxBrush::GetColour() const
230{
231 return (M_BRUSHDATA ? M_BRUSHDATA->m_colour : wxNullColour);
232}
233
234int wxBrush::GetStyle() const
235{
236 return (M_BRUSHDATA ? M_BRUSHDATA->m_style : 0);
237}
238
239wxBitmap *wxBrush::GetStipple() const
240{
241 return (M_BRUSHDATA ? & M_BRUSHDATA->m_stipple : 0);
242}
243
244wxMacBrushKind wxBrush::MacGetBrushKind() const
245{
246 return (M_BRUSHDATA ? M_BRUSHDATA->m_macBrushKind : kwxMacBrushColour);
247}
248
249bool 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}