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