]> git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/pen.cpp
Use IsOk() instead of Ok()
[wxWidgets.git] / src / mac / carbon / pen.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/mac/carbon/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 != wxSTIPPLE || m_stipple.IsSameAs(data.m_stipple)) &&
40 (m_style != wxUSER_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 int m_style;
48 int m_join ;
49 int 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 = wxSOLID;
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, int 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 wxPen::wxPen(const wxBitmap& stipple, int Width)
116 {
117 m_refData = new wxPenRefData;
118
119 M_PENDATA->m_stipple = stipple;
120 M_PENDATA->m_width = Width;
121 M_PENDATA->m_style = wxSTIPPLE;
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
130 wxGDIRefData *wxPen::CreateGDIRefData() const
131 {
132 return new wxPenRefData;
133 }
134
135 wxGDIRefData *wxPen::CloneGDIRefData(const wxGDIRefData *data) const
136 {
137 return new wxPenRefData(*wx_static_cast(const wxPenRefData *, data));
138 }
139
140 bool wxPen::operator==(const wxPen& pen) const
141 {
142 const wxPenRefData *penData = (wxPenRefData *)pen.m_refData;
143
144 // an invalid pen is only equal to another invalid pen
145 return m_refData ? penData && *M_PENDATA == *penData : !penData;
146 }
147
148 wxColour& wxPen::GetColour() const
149 {
150 return (M_PENDATA ? M_PENDATA->m_colour : wxNullColour);
151 }
152
153 int wxPen::GetWidth() const
154 {
155 return (M_PENDATA ? M_PENDATA->m_width : 0);
156 }
157
158 int wxPen::GetStyle() const
159 {
160 return (M_PENDATA ? M_PENDATA->m_style : 0);
161 }
162
163 int wxPen::GetJoin() const
164 {
165 return (M_PENDATA ? M_PENDATA->m_join : 0);
166 }
167
168 int wxPen::GetCap() const
169 {
170 return (M_PENDATA ? M_PENDATA->m_cap : 0);
171 }
172
173 int wxPen::GetDashes(wxDash **ptr) const
174 {
175 *ptr = (M_PENDATA ? M_PENDATA->m_dash : (wxDash*) NULL); return (M_PENDATA ? M_PENDATA->m_nbDash : 0);
176 }
177
178 wxBitmap *wxPen::GetStipple() const
179 {
180 return (M_PENDATA ? (& M_PENDATA->m_stipple) : (wxBitmap*) NULL);
181 }
182
183 void wxPen::Unshare()
184 {
185 // Don't change shared data
186 if (!m_refData)
187 {
188 m_refData = new wxPenRefData();
189 }
190 else
191 {
192 wxPenRefData* ref = new wxPenRefData(*(wxPenRefData*)m_refData);
193 UnRef();
194 m_refData = ref;
195 }
196 }
197
198 void wxPen::SetColour(const wxColour& col)
199 {
200 Unshare();
201
202 M_PENDATA->m_colour = col;
203
204 RealizeResource();
205 }
206
207 void wxPen::SetColour(unsigned char r, unsigned char g, unsigned char b)
208 {
209 Unshare();
210
211 M_PENDATA->m_colour.Set(r, g, b);
212
213 RealizeResource();
214 }
215
216 void wxPen::SetWidth(int Width)
217 {
218 Unshare();
219
220 M_PENDATA->m_width = Width;
221
222 RealizeResource();
223 }
224
225 void wxPen::SetStyle(int Style)
226 {
227 Unshare();
228
229 M_PENDATA->m_style = Style;
230
231 RealizeResource();
232 }
233
234 void wxPen::SetStipple(const wxBitmap& Stipple)
235 {
236 Unshare();
237
238 M_PENDATA->m_stipple = Stipple;
239 M_PENDATA->m_style = wxSTIPPLE;
240
241 RealizeResource();
242 }
243
244 void wxPen::SetDashes(int nb_dashes, const wxDash *Dash)
245 {
246 Unshare();
247
248 M_PENDATA->m_nbDash = nb_dashes;
249 M_PENDATA->m_dash = (wxDash *)Dash;
250
251 RealizeResource();
252 }
253
254 void wxPen::SetJoin(int Join)
255 {
256 Unshare();
257
258 M_PENDATA->m_join = Join;
259
260 RealizeResource();
261 }
262
263 void wxPen::SetCap(int Cap)
264 {
265 Unshare();
266
267 M_PENDATA->m_cap = Cap;
268
269 RealizeResource();
270 }
271
272 bool wxPen::RealizeResource()
273 {
274 // nothing to do here for mac
275 return true;
276 }