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