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