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