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