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