]> git.saurik.com Git - wxWidgets.git/blob - src/osx/pen.cpp
defer calling SetCanFocus() on wxGTK until after creation
[wxWidgets.git] / src / osx / pen.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/osx/pen.cpp
3 // Purpose: wxPen
4 // Author: Stefan Csomor
5 // Modified by:
6 // Created: 1998-01-01
7 // Copyright: (c) Stefan Csomor
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
10
11 #include "wx/wxprec.h"
12
13 #include "wx/pen.h"
14
15 #ifndef WX_PRECOMP
16 #include "wx/utils.h"
17 #endif
18
19 IMPLEMENT_DYNAMIC_CLASS(wxPen, wxGDIObject)
20
21 class WXDLLEXPORT wxPenRefData : public wxGDIRefData
22 {
23 public:
24 wxPenRefData();
25 wxPenRefData(const wxPenRefData& data);
26 virtual ~wxPenRefData();
27
28 wxPenRefData& operator=(const wxPenRefData& data);
29
30 bool operator==(const wxPenRefData& data) const
31 {
32 // we intentionally don't compare m_hPen fields here
33 return m_style == data.m_style &&
34 m_width == data.m_width &&
35 m_join == data.m_join &&
36 m_cap == data.m_cap &&
37 m_colour == data.m_colour &&
38 (m_style != wxPENSTYLE_STIPPLE || m_stipple.IsSameAs(data.m_stipple)) &&
39 (m_style != wxPENSTYLE_USER_DASH ||
40 (m_nbDash == data.m_nbDash &&
41 memcmp(m_dash, data.m_dash, m_nbDash*sizeof(wxDash)) == 0));
42 }
43
44 protected:
45 int m_width;
46 wxPenStyle m_style;
47 wxPenJoin m_join ;
48 wxPenCap m_cap ;
49 wxBitmap m_stipple ;
50 int m_nbDash ;
51 wxDash * m_dash ;
52 wxColour m_colour;
53 /* TODO: implementation
54 WXHPEN m_hPen;
55 */
56
57 friend class WXDLLIMPEXP_FWD_CORE wxPen;
58 };
59
60 wxPenRefData::wxPenRefData()
61 {
62 m_style = wxPENSTYLE_SOLID;
63 m_width = 1;
64 m_join = wxJOIN_ROUND ;
65 m_cap = wxCAP_ROUND ;
66 m_nbDash = 0 ;
67 m_dash = 0 ;
68 }
69
70 wxPenRefData::wxPenRefData(const wxPenRefData& data)
71 : wxGDIRefData()
72 {
73 m_style = data.m_style;
74 m_width = data.m_width;
75 m_join = data.m_join;
76 m_cap = data.m_cap;
77 m_nbDash = data.m_nbDash;
78 m_dash = data.m_dash;
79 m_colour = data.m_colour;
80 }
81
82 wxPenRefData::~wxPenRefData()
83 {
84 }
85
86 // Pens
87
88 #define M_PENDATA ((wxPenRefData *)m_refData)
89
90 wxPen::wxPen()
91 {
92 }
93
94 wxPen::~wxPen()
95 {
96 }
97
98 // Should implement Create
99 wxPen::wxPen(const wxColour& col, int Width, wxPenStyle Style)
100 {
101 m_refData = new wxPenRefData;
102
103 M_PENDATA->m_colour = col;
104 M_PENDATA->m_width = Width;
105 M_PENDATA->m_style = Style;
106 M_PENDATA->m_join = wxJOIN_ROUND ;
107 M_PENDATA->m_cap = wxCAP_ROUND ;
108 M_PENDATA->m_nbDash = 0 ;
109 M_PENDATA->m_dash = 0 ;
110
111 RealizeResource();
112 }
113
114 #if FUTURE_WXWIN_COMPATIBILITY_3_0
115 wxPen::wxPen(const wxColour& col, int Width, int Style)
116 {
117 m_refData = new wxPenRefData;
118
119 M_PENDATA->m_colour = col;
120 M_PENDATA->m_width = Width;
121 M_PENDATA->m_style = (wxPenStyle)Style;
122 M_PENDATA->m_join = wxJOIN_ROUND ;
123 M_PENDATA->m_cap = wxCAP_ROUND ;
124 M_PENDATA->m_nbDash = 0 ;
125 M_PENDATA->m_dash = 0 ;
126
127 RealizeResource();
128 }
129 #endif
130
131 wxPen::wxPen(const wxBitmap& stipple, int Width)
132 {
133 m_refData = new wxPenRefData;
134
135 M_PENDATA->m_stipple = stipple;
136 M_PENDATA->m_width = Width;
137 M_PENDATA->m_style = wxPENSTYLE_STIPPLE;
138 M_PENDATA->m_join = wxJOIN_ROUND ;
139 M_PENDATA->m_cap = wxCAP_ROUND ;
140 M_PENDATA->m_nbDash = 0 ;
141 M_PENDATA->m_dash = 0 ;
142
143 RealizeResource();
144 }
145
146 wxGDIRefData *wxPen::CreateGDIRefData() const
147 {
148 return new wxPenRefData;
149 }
150
151 wxGDIRefData *wxPen::CloneGDIRefData(const wxGDIRefData *data) const
152 {
153 return new wxPenRefData(*static_cast<const wxPenRefData *>(data));
154 }
155
156 bool wxPen::operator==(const wxPen& pen) const
157 {
158 const wxPenRefData *penData = (wxPenRefData *)pen.m_refData;
159
160 // an invalid pen is only equal to another invalid pen
161 return m_refData ? penData && *M_PENDATA == *penData : !penData;
162 }
163
164 wxColour wxPen::GetColour() const
165 {
166 wxCHECK_MSG( IsOk(), wxNullColour, wxT("invalid pen") );
167
168 return M_PENDATA->m_colour;
169 }
170
171 int wxPen::GetWidth() const
172 {
173 wxCHECK_MSG( IsOk(), -1, wxT("invalid pen") );
174
175 return M_PENDATA->m_width;
176 }
177
178 wxPenStyle wxPen::GetStyle() const
179 {
180 wxCHECK_MSG( IsOk(), wxPENSTYLE_INVALID, wxT("invalid pen") );
181
182 return M_PENDATA->m_style;
183 }
184
185 wxPenJoin wxPen::GetJoin() const
186 {
187 wxCHECK_MSG( IsOk(), wxJOIN_INVALID, wxT("invalid pen") );
188
189 return M_PENDATA->m_join;
190 }
191
192 wxPenCap wxPen::GetCap() const
193 {
194 wxCHECK_MSG( IsOk(), wxCAP_INVALID, wxT("invalid pen") );
195
196 return M_PENDATA->m_cap;
197 }
198
199 int wxPen::GetDashes(wxDash **ptr) const
200 {
201 wxCHECK_MSG( IsOk(), -1, wxT("invalid pen") );
202
203 *ptr = M_PENDATA->m_dash;
204 return M_PENDATA->m_nbDash;
205 }
206
207 int wxPen::GetDashCount() const
208 {
209 return M_PENDATA->m_nbDash;
210 }
211
212 wxBitmap *wxPen::GetStipple() const
213 {
214 wxCHECK_MSG( IsOk(), NULL, wxT("invalid pen") );
215
216 return &M_PENDATA->m_stipple;
217 }
218
219 void wxPen::Unshare()
220 {
221 // Don't change shared data
222 if (!m_refData)
223 {
224 m_refData = new wxPenRefData();
225 }
226 else
227 {
228 wxPenRefData* ref = new wxPenRefData(*(wxPenRefData*)m_refData);
229 UnRef();
230 m_refData = ref;
231 }
232 }
233
234 void wxPen::SetColour(const wxColour& col)
235 {
236 Unshare();
237
238 M_PENDATA->m_colour = col;
239
240 RealizeResource();
241 }
242
243 void wxPen::SetColour(unsigned char r, unsigned char g, unsigned char b)
244 {
245 Unshare();
246
247 M_PENDATA->m_colour.Set(r, g, b);
248
249 RealizeResource();
250 }
251
252 void wxPen::SetWidth(int Width)
253 {
254 Unshare();
255
256 M_PENDATA->m_width = Width;
257
258 RealizeResource();
259 }
260
261 void wxPen::SetStyle(wxPenStyle Style)
262 {
263 Unshare();
264
265 M_PENDATA->m_style = Style;
266
267 RealizeResource();
268 }
269
270 void wxPen::SetStipple(const wxBitmap& Stipple)
271 {
272 Unshare();
273
274 M_PENDATA->m_stipple = Stipple;
275 M_PENDATA->m_style = wxPENSTYLE_STIPPLE;
276
277 RealizeResource();
278 }
279
280 void wxPen::SetDashes(int nb_dashes, const wxDash *Dash)
281 {
282 Unshare();
283
284 M_PENDATA->m_nbDash = nb_dashes;
285 M_PENDATA->m_dash = (wxDash *)Dash;
286
287 RealizeResource();
288 }
289
290 void wxPen::SetJoin(wxPenJoin Join)
291 {
292 Unshare();
293
294 M_PENDATA->m_join = Join;
295
296 RealizeResource();
297 }
298
299 void wxPen::SetCap(wxPenCap Cap)
300 {
301 Unshare();
302
303 M_PENDATA->m_cap = Cap;
304
305 RealizeResource();
306 }
307
308 bool wxPen::RealizeResource()
309 {
310 // nothing to do here for mac
311 return true;
312 }