]> git.saurik.com Git - wxWidgets.git/blob - src/osx/pen.cpp
re-enable drawing our own resize grip with GTK3, themes can (and do) disable the...
[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 // 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
20 IMPLEMENT_DYNAMIC_CLASS(wxPen, wxGDIObject)
21
22 class WXDLLEXPORT wxPenRefData : public wxGDIRefData
23 {
24 public:
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
45 protected:
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
61 wxPenRefData::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
71 wxPenRefData::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
83 wxPenRefData::~wxPenRefData()
84 {
85 }
86
87 // Pens
88
89 #define M_PENDATA ((wxPenRefData *)m_refData)
90
91 wxPen::wxPen()
92 {
93 }
94
95 wxPen::~wxPen()
96 {
97 }
98
99 // Should implement Create
100 wxPen::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
116 wxPen::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
132 wxPen::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
147 wxGDIRefData *wxPen::CreateGDIRefData() const
148 {
149 return new wxPenRefData;
150 }
151
152 wxGDIRefData *wxPen::CloneGDIRefData(const wxGDIRefData *data) const
153 {
154 return new wxPenRefData(*static_cast<const wxPenRefData *>(data));
155 }
156
157 bool 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
165 wxColour wxPen::GetColour() const
166 {
167 wxCHECK_MSG( IsOk(), wxNullColour, wxT("invalid pen") );
168
169 return M_PENDATA->m_colour;
170 }
171
172 int wxPen::GetWidth() const
173 {
174 wxCHECK_MSG( IsOk(), -1, wxT("invalid pen") );
175
176 return M_PENDATA->m_width;
177 }
178
179 wxPenStyle wxPen::GetStyle() const
180 {
181 wxCHECK_MSG( IsOk(), wxPENSTYLE_INVALID, wxT("invalid pen") );
182
183 return M_PENDATA->m_style;
184 }
185
186 wxPenJoin wxPen::GetJoin() const
187 {
188 wxCHECK_MSG( IsOk(), wxJOIN_INVALID, wxT("invalid pen") );
189
190 return M_PENDATA->m_join;
191 }
192
193 wxPenCap wxPen::GetCap() const
194 {
195 wxCHECK_MSG( IsOk(), wxCAP_INVALID, wxT("invalid pen") );
196
197 return M_PENDATA->m_cap;
198 }
199
200 int wxPen::GetDashes(wxDash **ptr) const
201 {
202 wxCHECK_MSG( IsOk(), -1, wxT("invalid pen") );
203
204 *ptr = M_PENDATA->m_dash;
205 return M_PENDATA->m_nbDash;
206 }
207
208 int wxPen::GetDashCount() const
209 {
210 return M_PENDATA->m_nbDash;
211 }
212
213 wxBitmap *wxPen::GetStipple() const
214 {
215 wxCHECK_MSG( IsOk(), NULL, wxT("invalid pen") );
216
217 return &M_PENDATA->m_stipple;
218 }
219
220 void 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
235 void wxPen::SetColour(const wxColour& col)
236 {
237 Unshare();
238
239 M_PENDATA->m_colour = col;
240
241 RealizeResource();
242 }
243
244 void 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
253 void wxPen::SetWidth(int Width)
254 {
255 Unshare();
256
257 M_PENDATA->m_width = Width;
258
259 RealizeResource();
260 }
261
262 void wxPen::SetStyle(wxPenStyle Style)
263 {
264 Unshare();
265
266 M_PENDATA->m_style = Style;
267
268 RealizeResource();
269 }
270
271 void 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
281 void 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
291 void wxPen::SetJoin(wxPenJoin Join)
292 {
293 Unshare();
294
295 M_PENDATA->m_join = Join;
296
297 RealizeResource();
298 }
299
300 void wxPen::SetCap(wxPenCap Cap)
301 {
302 Unshare();
303
304 M_PENDATA->m_cap = Cap;
305
306 RealizeResource();
307 }
308
309 bool wxPen::RealizeResource()
310 {
311 // nothing to do here for mac
312 return true;
313 }