]> git.saurik.com Git - wxWidgets.git/blame - 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
e9576ca5 1/////////////////////////////////////////////////////////////////////////////
46562151 2// Name: src/mac/carbon/brush.cpp
e9576ca5 3// Purpose: wxBrush
a31a5f85 4// Author: Stefan Csomor
e9576ca5 5// Modified by:
a31a5f85 6// Created: 1998-01-01
e9576ca5 7// RCS-ID: $Id$
a31a5f85 8// Copyright: (c) Stefan Csomor
46562151 9// Licence: wxWindows licence
e9576ca5
SC
10/////////////////////////////////////////////////////////////////////////////
11
a8e9860d
SC
12#include "wx/wxprec.h"
13
e9576ca5
SC
14#include "wx/brush.h"
15
de6185e2
WS
16#ifndef WX_PRECOMP
17 #include "wx/utils.h"
18#endif
19
76a5e5d2
SC
20#include "wx/mac/private.h"
21
e9576ca5 22IMPLEMENT_DYNAMIC_CLASS(wxBrush, wxGDIObject)
e9576ca5 23
76a5e5d2
SC
24class WXDLLEXPORT wxBrushRefData: public wxGDIRefData
25{
26 friend class WXDLLEXPORT wxBrush;
172da31f 27
76a5e5d2
SC
28public:
29 wxBrushRefData();
30 wxBrushRefData(const wxBrushRefData& data);
d3c7fc99 31 virtual ~wxBrushRefData();
76a5e5d2 32
55ccdb93
VZ
33 bool operator == ( const wxBrushRefData& brush ) const
34 {
35 return m_style == brush.m_style &&
a3ab1c18 36 m_stipple.IsSameAs(brush.m_stipple) &&
55ccdb93
VZ
37 m_colour == brush.m_colour &&
38 m_macBrushKind == brush.m_macBrushKind &&
39 m_macThemeBrush == brush.m_macThemeBrush &&
40 m_macThemeBackground == brush.m_macThemeBackground &&
2e573683 41 EqualRect(&m_macThemeBackgroundExtent, &brush.m_macThemeBackgroundExtent);
55ccdb93
VZ
42 }
43
44
76a5e5d2
SC
45protected:
46 wxMacBrushKind m_macBrushKind ;
47 int m_style;
48 wxBitmap m_stipple ;
49 wxColour m_colour;
46562151 50
76a5e5d2 51 ThemeBrush m_macThemeBrush ;
46562151 52
76a5e5d2
SC
53 ThemeBackgroundKind m_macThemeBackground ;
54 Rect m_macThemeBackgroundExtent ;
55};
56
57#define M_BRUSHDATA ((wxBrushRefData *)m_refData)
58
172da31f 59
e9576ca5 60wxBrushRefData::wxBrushRefData()
d84afea9 61 : m_style(wxSOLID)
e9576ca5 62{
7d9d1fd7 63 m_macBrushKind = kwxMacBrushColour ;
e9576ca5
SC
64}
65
66wxBrushRefData::wxBrushRefData(const wxBrushRefData& data)
d84afea9
GD
67 : wxGDIRefData()
68 , m_style(data.m_style)
e9576ca5 69{
e9576ca5
SC
70 m_stipple = data.m_stipple;
71 m_colour = data.m_colour;
7d9d1fd7 72 m_macBrushKind = data.m_macBrushKind ;
1dcbbdcf 73 m_macThemeBrush = data.m_macThemeBrush ;
7d9d1fd7
SC
74 m_macThemeBackground = data.m_macThemeBackground ;
75 m_macThemeBackgroundExtent = data.m_macThemeBackgroundExtent ;
e9576ca5
SC
76}
77
78wxBrushRefData::~wxBrushRefData()
79{
e9576ca5
SC
80}
81
e9576ca5
SC
82wxBrush::wxBrush()
83{
e9576ca5
SC
84}
85
86wxBrush::~wxBrush()
87{
e9576ca5
SC
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();
e9576ca5
SC
98}
99
100wxBrush::wxBrush(const wxBitmap& stipple)
101{
102 m_refData = new wxBrushRefData;
103
2b65eb68 104 M_BRUSHDATA->m_colour = *wxBLACK;
e9576ca5 105 M_BRUSHDATA->m_stipple = stipple;
46562151 106
2b65eb68
SC
107 if (M_BRUSHDATA->m_stipple.GetMask())
108 M_BRUSHDATA->m_style = wxSTIPPLE_MASK_OPAQUE;
109 else
110 M_BRUSHDATA->m_style = wxSTIPPLE;
e9576ca5
SC
111
112 RealizeResource();
e9576ca5
SC
113}
114
172da31f 115wxBrush::wxBrush( ThemeBrush macThemeBrush )
1dcbbdcf
SC
116{
117 m_refData = new wxBrushRefData;
118
7d9d1fd7 119 M_BRUSHDATA->m_macBrushKind = kwxMacBrushTheme;
1dcbbdcf
SC
120 M_BRUSHDATA->m_macThemeBrush = macThemeBrush;
121
122 RealizeResource();
123}
172da31f 124
e9576ca5
SC
125void wxBrush::Unshare()
126{
e40298d5
JS
127 // Don't change shared data
128 if (!m_refData)
e9576ca5 129 {
e40298d5
JS
130 m_refData = new wxBrushRefData();
131 }
e9576ca5
SC
132 else
133 {
e40298d5
JS
134 wxBrushRefData* ref = new wxBrushRefData(*(wxBrushRefData*)m_refData);
135 UnRef();
136 m_refData = ref;
137 }
e9576ca5
SC
138}
139
140void wxBrush::SetColour(const wxColour& col)
141{
142 Unshare();
7d9d1fd7 143 M_BRUSHDATA->m_macBrushKind = kwxMacBrushColour;
e9576ca5
SC
144 M_BRUSHDATA->m_colour = col;
145
146 RealizeResource();
147}
148
1a1498c0 149void wxBrush::SetColour(unsigned char r, unsigned char g, unsigned char b)
e9576ca5
SC
150{
151 Unshare();
152
7d9d1fd7 153 M_BRUSHDATA->m_macBrushKind = kwxMacBrushColour;
e9576ca5
SC
154 M_BRUSHDATA->m_colour.Set(r, g, b);
155
156 RealizeResource();
157}
158
159void wxBrush::SetStyle(int Style)
160{
161 Unshare();
162
7d9d1fd7 163 M_BRUSHDATA->m_macBrushKind = kwxMacBrushColour;
e9576ca5
SC
164 M_BRUSHDATA->m_style = Style;
165
166 RealizeResource();
167}
168
169void wxBrush::SetStipple(const wxBitmap& Stipple)
170{
171 Unshare();
172
7d9d1fd7 173 M_BRUSHDATA->m_macBrushKind = kwxMacBrushColour;
e9576ca5
SC
174 M_BRUSHDATA->m_stipple = Stipple;
175
176 RealizeResource();
177}
178
facd6764 179void wxBrush::MacSetTheme(ThemeBrush macThemeBrush)
1dcbbdcf
SC
180{
181 Unshare();
182
7d9d1fd7 183 M_BRUSHDATA->m_macBrushKind = kwxMacBrushTheme;
1dcbbdcf 184 M_BRUSHDATA->m_macThemeBrush = macThemeBrush;
172da31f 185
ff38d8c1
SC
186 RGBColor color ;
187 GetThemeBrushAsColor( macThemeBrush , 32, true, &color );
172da31f 188 M_BRUSHDATA->m_colour.Set( color.red >> 8 , color.green >> 8 , color.blue >> 8 );
46562151 189
1dcbbdcf
SC
190 RealizeResource();
191}
192
facd6764 193void wxBrush::MacSetThemeBackground(unsigned long macThemeBackground, const WXRECTPTR extent)
1dcbbdcf
SC
194{
195 Unshare();
196
7d9d1fd7 197 M_BRUSHDATA->m_macBrushKind = kwxMacBrushThemeBackground;
1dcbbdcf 198 M_BRUSHDATA->m_macThemeBackground = macThemeBackground;
172da31f
DS
199 M_BRUSHDATA->m_macThemeBackgroundExtent = *(Rect*)extent;
200
1dcbbdcf
SC
201 RealizeResource();
202}
203
e9576ca5
SC
204bool wxBrush::RealizeResource()
205{
46562151 206 return true;
e9576ca5 207}
78606adf
DS
208
209unsigned long wxBrush::MacGetThemeBackground(WXRECTPTR extent) const
7d9d1fd7 210{
46562151
WS
211 if ( M_BRUSHDATA && M_BRUSHDATA->m_macBrushKind == kwxMacBrushThemeBackground )
212 {
213 if ( extent )
172da31f
DS
214 *(Rect*)extent = M_BRUSHDATA->m_macThemeBackgroundExtent;
215
216 return M_BRUSHDATA->m_macThemeBackground;
46562151
WS
217 }
218 else
219 {
172da31f 220 return 0;
46562151 221 }
7d9d1fd7
SC
222}
223
46562151
WS
224short wxBrush::MacGetTheme() const
225{
172da31f 226 return (M_BRUSHDATA ? ((M_BRUSHDATA->m_macBrushKind == kwxMacBrushTheme) ? M_BRUSHDATA->m_macThemeBrush : kThemeBrushBlack) : kThemeBrushBlack);
e40298d5 227}
76a5e5d2 228
46562151 229wxColour& wxBrush::GetColour() const
e40298d5
JS
230{
231 return (M_BRUSHDATA ? M_BRUSHDATA->m_colour : wxNullColour);
232}
76a5e5d2 233
46562151
WS
234int wxBrush::GetStyle() const
235{
236 return (M_BRUSHDATA ? M_BRUSHDATA->m_style : 0);
e40298d5 237}
76a5e5d2 238
46562151
WS
239wxBitmap *wxBrush::GetStipple() const
240{
241 return (M_BRUSHDATA ? & M_BRUSHDATA->m_stipple : 0);
e40298d5 242}
76a5e5d2 243
172da31f 244wxMacBrushKind wxBrush::MacGetBrushKind() const
46562151
WS
245{
246 return (M_BRUSHDATA ? M_BRUSHDATA->m_macBrushKind : kwxMacBrushColour);
a8e9860d 247}
55ccdb93
VZ
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}