]> git.saurik.com Git - wxWidgets.git/blob - src/osx/pen.cpp
minor fixes; replace references to Windows95 with references to wxMSW where possible
[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( Ok(), wxNullColour, wxT("invalid pen") );
168
169 return M_PENDATA->m_colour;
170 }
171
172 int wxPen::GetWidth() const
173 {
174 wxCHECK_MSG( Ok(), -1, wxT("invalid pen") );
175
176 return M_PENDATA->m_width;
177 }
178
179 wxPenStyle wxPen::GetStyle() const
180 {
181 wxCHECK_MSG( Ok(), wxPENSTYLE_INVALID, wxT("invalid pen") );
182
183 return M_PENDATA->m_style;
184 }
185
186 wxPenJoin wxPen::GetJoin() const
187 {
188 wxCHECK_MSG( Ok(), wxJOIN_INVALID, wxT("invalid pen") );
189
190 return M_PENDATA->m_join;
191 }
192
193 wxPenCap wxPen::GetCap() const
194 {
195 wxCHECK_MSG( Ok(), 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( Ok(), -1, wxT("invalid pen") );
203
204 *ptr = M_PENDATA->m_dash;
205 return M_PENDATA->m_nbDash;
206 }
207
208 wxBitmap *wxPen::GetStipple() const
209 {
210 wxCHECK_MSG( Ok(), NULL, wxT("invalid pen") );
211
212 return &M_PENDATA->m_stipple;
213 }
214
215 void wxPen::Unshare()
216 {
217 // Don't change shared data
218 if (!m_refData)
219 {
220 m_refData = new wxPenRefData();
221 }
222 else
223 {
224 wxPenRefData* ref = new wxPenRefData(*(wxPenRefData*)m_refData);
225 UnRef();
226 m_refData = ref;
227 }
228 }
229
230 void wxPen::SetColour(const wxColour& col)
231 {
232 Unshare();
233
234 M_PENDATA->m_colour = col;
235
236 RealizeResource();
237 }
238
239 void wxPen::SetColour(unsigned char r, unsigned char g, unsigned char b)
240 {
241 Unshare();
242
243 M_PENDATA->m_colour.Set(r, g, b);
244
245 RealizeResource();
246 }
247
248 void wxPen::SetWidth(int Width)
249 {
250 Unshare();
251
252 M_PENDATA->m_width = Width;
253
254 RealizeResource();
255 }
256
257 void wxPen::SetStyle(wxPenStyle Style)
258 {
259 Unshare();
260
261 M_PENDATA->m_style = Style;
262
263 RealizeResource();
264 }
265
266 void wxPen::SetStipple(const wxBitmap& Stipple)
267 {
268 Unshare();
269
270 M_PENDATA->m_stipple = Stipple;
271 M_PENDATA->m_style = wxPENSTYLE_STIPPLE;
272
273 RealizeResource();
274 }
275
276 void wxPen::SetDashes(int nb_dashes, const wxDash *Dash)
277 {
278 Unshare();
279
280 M_PENDATA->m_nbDash = nb_dashes;
281 M_PENDATA->m_dash = (wxDash *)Dash;
282
283 RealizeResource();
284 }
285
286 void wxPen::SetJoin(wxPenJoin Join)
287 {
288 Unshare();
289
290 M_PENDATA->m_join = Join;
291
292 RealizeResource();
293 }
294
295 void wxPen::SetCap(wxPenCap Cap)
296 {
297 Unshare();
298
299 M_PENDATA->m_cap = Cap;
300
301 RealizeResource();
302 }
303
304 bool wxPen::RealizeResource()
305 {
306 // nothing to do here for mac
307 return true;
308 }