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