]>
Commit | Line | Data |
---|---|---|
e9576ca5 | 1 | ///////////////////////////////////////////////////////////////////////////// |
46562151 | 2 | // Name: src/mac/carbon/pen.cpp |
e9576ca5 | 3 | // Purpose: wxPen |
a31a5f85 | 4 | // Author: Stefan Csomor |
e9576ca5 | 5 | // Modified by: |
a31a5f85 | 6 | // Created: 1998-01-01 |
e9576ca5 | 7 | // RCS-ID: $Id$ |
a31a5f85 | 8 | // Copyright: (c) Stefan Csomor |
46562151 | 9 | // Licence: wxWindows licence |
e9576ca5 SC |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
3d1a4878 SC |
12 | #include "wx/wxprec.h" |
13 | ||
e9576ca5 SC |
14 | #include "wx/pen.h" |
15 | ||
de6185e2 WS |
16 | #ifndef WX_PRECOMP |
17 | #include "wx/utils.h" | |
18 | #endif | |
19 | ||
e9576ca5 | 20 | IMPLEMENT_DYNAMIC_CLASS(wxPen, wxGDIObject) |
e9576ca5 | 21 | |
8f884a0d | 22 | class WXDLLEXPORT wxPenRefData : public wxGDIRefData |
46623e91 | 23 | { |
46623e91 SC |
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 && | |
8f884a0d VZ |
35 | m_width == data.m_width && |
36 | m_join == data.m_join && | |
37 | m_cap == data.m_cap && | |
38 | m_colour == data.m_colour && | |
ed7ec76d FM |
39 | (m_style != wxPENSTYLE_STIPPLE || m_stipple.IsSameAs(data.m_stipple)) && |
40 | (m_style != wxPENSTYLE_USER_DASH || | |
8f884a0d VZ |
41 | (m_nbDash == data.m_nbDash && |
42 | memcmp(m_dash, data.m_dash, m_nbDash*sizeof(wxDash)) == 0)); | |
46623e91 SC |
43 | } |
44 | ||
45 | protected: | |
8f884a0d | 46 | int m_width; |
82cddbd9 FM |
47 | wxPenStyle m_style; |
48 | wxPenJoin m_join ; | |
49 | wxPenCap m_cap ; | |
8f884a0d VZ |
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; | |
46623e91 SC |
59 | }; |
60 | ||
e9576ca5 SC |
61 | wxPenRefData::wxPenRefData() |
62 | { | |
ed7ec76d | 63 | m_style = wxPENSTYLE_SOLID; |
e9576ca5 SC |
64 | m_width = 1; |
65 | m_join = wxJOIN_ROUND ; | |
66 | m_cap = wxCAP_ROUND ; | |
67 | m_nbDash = 0 ; | |
2f1ae414 | 68 | m_dash = 0 ; |
e9576ca5 SC |
69 | } |
70 | ||
71 | wxPenRefData::wxPenRefData(const wxPenRefData& data) | |
e40298d5 | 72 | : wxGDIRefData() |
e9576ca5 SC |
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; | |
e9576ca5 SC |
81 | } |
82 | ||
83 | wxPenRefData::~wxPenRefData() | |
84 | { | |
e9576ca5 SC |
85 | } |
86 | ||
87 | // Pens | |
88 | ||
46623e91 SC |
89 | #define M_PENDATA ((wxPenRefData *)m_refData) |
90 | ||
e9576ca5 SC |
91 | wxPen::wxPen() |
92 | { | |
e9576ca5 SC |
93 | } |
94 | ||
95 | wxPen::~wxPen() | |
96 | { | |
e9576ca5 SC |
97 | } |
98 | ||
99 | // Should implement Create | |
82cddbd9 | 100 | wxPen::wxPen(const wxColour& col, int Width, wxPenStyle Style) |
e9576ca5 SC |
101 | { |
102 | m_refData = new wxPenRefData; | |
46562151 | 103 | |
e9576ca5 SC |
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 ; | |
2f1ae414 | 110 | M_PENDATA->m_dash = 0 ; |
46562151 | 111 | |
e9576ca5 | 112 | RealizeResource(); |
e9576ca5 SC |
113 | } |
114 | ||
ac3688c0 FM |
115 | #if FUTURE_WXWIN_COMPATIBILITY_3_0 |
116 | wxPen::wxPen(const wxColour& col, int Width, int Style) | |
82cddbd9 FM |
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 | } | |
ac3688c0 | 130 | #endif |
82cddbd9 | 131 | |
e9576ca5 SC |
132 | wxPen::wxPen(const wxBitmap& stipple, int Width) |
133 | { | |
134 | m_refData = new wxPenRefData; | |
46562151 | 135 | |
e9576ca5 SC |
136 | M_PENDATA->m_stipple = stipple; |
137 | M_PENDATA->m_width = Width; | |
ed7ec76d | 138 | M_PENDATA->m_style = wxPENSTYLE_STIPPLE; |
e9576ca5 SC |
139 | M_PENDATA->m_join = wxJOIN_ROUND ; |
140 | M_PENDATA->m_cap = wxCAP_ROUND ; | |
141 | M_PENDATA->m_nbDash = 0 ; | |
2f1ae414 | 142 | M_PENDATA->m_dash = 0 ; |
46562151 | 143 | |
e9576ca5 | 144 | RealizeResource(); |
e9576ca5 SC |
145 | } |
146 | ||
8f884a0d VZ |
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(*wx_static_cast(const wxPenRefData *, data)); | |
155 | } | |
156 | ||
157 | bool wxPen::operator==(const wxPen& pen) const | |
46623e91 SC |
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 | ||
8f884a0d VZ |
165 | wxColour& wxPen::GetColour() const |
166 | { | |
ac3688c0 FM |
167 | wxCHECK_MSG( Ok(), wxNullColour, wxT("invalid pen") ); |
168 | ||
169 | return M_PENDATA->m_colour; | |
46623e91 SC |
170 | } |
171 | ||
8f884a0d VZ |
172 | int wxPen::GetWidth() const |
173 | { | |
ac3688c0 FM |
174 | wxCHECK_MSG( Ok(), -1, wxT("invalid pen") ); |
175 | ||
176 | return M_PENDATA->m_width; | |
46623e91 SC |
177 | } |
178 | ||
82cddbd9 | 179 | wxPenStyle wxPen::GetStyle() const |
8f884a0d | 180 | { |
ac3688c0 FM |
181 | wxCHECK_MSG( Ok(), wxPENSTYLE_INVALID, wxT("invalid pen") ); |
182 | ||
183 | return M_PENDATA->m_style; | |
46623e91 SC |
184 | } |
185 | ||
82cddbd9 | 186 | wxPenJoin wxPen::GetJoin() const |
8f884a0d | 187 | { |
ac3688c0 FM |
188 | wxCHECK_MSG( Ok(), wxJOIN_INVALID, wxT("invalid pen") ); |
189 | ||
190 | return M_PENDATA->m_join; | |
46623e91 SC |
191 | } |
192 | ||
82cddbd9 | 193 | wxPenCap wxPen::GetCap() const |
8f884a0d | 194 | { |
ac3688c0 FM |
195 | wxCHECK_MSG( Ok(), wxCAP_INVALID, wxT("invalid pen") ); |
196 | ||
197 | return M_PENDATA->m_cap; | |
46623e91 SC |
198 | } |
199 | ||
8f884a0d | 200 | int wxPen::GetDashes(wxDash **ptr) const |
46623e91 | 201 | { |
ac3688c0 FM |
202 | wxCHECK_MSG( Ok(), -1, wxT("invalid pen") ); |
203 | ||
204 | *ptr = M_PENDATA->m_dash; | |
205 | return M_PENDATA->m_nbDash; | |
46623e91 SC |
206 | } |
207 | ||
8f884a0d VZ |
208 | wxBitmap *wxPen::GetStipple() const |
209 | { | |
ac3688c0 FM |
210 | wxCHECK_MSG( Ok(), NULL, wxT("invalid pen") ); |
211 | ||
212 | return &M_PENDATA->m_stipple; | |
46623e91 SC |
213 | } |
214 | ||
83dcd781 | 215 | void wxPen::Unshare() |
e9576ca5 | 216 | { |
83dcd781 PC |
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 | } | |
e9576ca5 SC |
228 | } |
229 | ||
230 | void wxPen::SetColour(const wxColour& col) | |
231 | { | |
83dcd781 | 232 | Unshare(); |
46562151 | 233 | |
e9576ca5 | 234 | M_PENDATA->m_colour = col; |
46562151 | 235 | |
e9576ca5 SC |
236 | RealizeResource(); |
237 | } | |
238 | ||
1a1498c0 | 239 | void wxPen::SetColour(unsigned char r, unsigned char g, unsigned char b) |
e9576ca5 | 240 | { |
83dcd781 | 241 | Unshare(); |
46562151 | 242 | |
e9576ca5 | 243 | M_PENDATA->m_colour.Set(r, g, b); |
46562151 | 244 | |
e9576ca5 SC |
245 | RealizeResource(); |
246 | } | |
247 | ||
248 | void wxPen::SetWidth(int Width) | |
249 | { | |
83dcd781 | 250 | Unshare(); |
46562151 | 251 | |
e9576ca5 | 252 | M_PENDATA->m_width = Width; |
46562151 | 253 | |
e9576ca5 SC |
254 | RealizeResource(); |
255 | } | |
256 | ||
82cddbd9 | 257 | void wxPen::SetStyle(wxPenStyle Style) |
e9576ca5 | 258 | { |
83dcd781 | 259 | Unshare(); |
46562151 | 260 | |
e9576ca5 | 261 | M_PENDATA->m_style = Style; |
46562151 | 262 | |
e9576ca5 SC |
263 | RealizeResource(); |
264 | } | |
265 | ||
266 | void wxPen::SetStipple(const wxBitmap& Stipple) | |
267 | { | |
83dcd781 | 268 | Unshare(); |
46562151 | 269 | |
e9576ca5 | 270 | M_PENDATA->m_stipple = Stipple; |
ed7ec76d | 271 | M_PENDATA->m_style = wxPENSTYLE_STIPPLE; |
46562151 | 272 | |
e9576ca5 SC |
273 | RealizeResource(); |
274 | } | |
275 | ||
276 | void wxPen::SetDashes(int nb_dashes, const wxDash *Dash) | |
277 | { | |
83dcd781 | 278 | Unshare(); |
46562151 | 279 | |
e9576ca5 | 280 | M_PENDATA->m_nbDash = nb_dashes; |
2f1ae414 | 281 | M_PENDATA->m_dash = (wxDash *)Dash; |
46562151 | 282 | |
e9576ca5 SC |
283 | RealizeResource(); |
284 | } | |
285 | ||
82cddbd9 | 286 | void wxPen::SetJoin(wxPenJoin Join) |
e9576ca5 | 287 | { |
83dcd781 | 288 | Unshare(); |
46562151 | 289 | |
e9576ca5 | 290 | M_PENDATA->m_join = Join; |
46562151 | 291 | |
e9576ca5 SC |
292 | RealizeResource(); |
293 | } | |
294 | ||
82cddbd9 | 295 | void wxPen::SetCap(wxPenCap Cap) |
e9576ca5 | 296 | { |
83dcd781 | 297 | Unshare(); |
46562151 | 298 | |
e9576ca5 | 299 | M_PENDATA->m_cap = Cap; |
46562151 | 300 | |
e9576ca5 SC |
301 | RealizeResource(); |
302 | } | |
303 | ||
304 | bool wxPen::RealizeResource() | |
305 | { | |
e40298d5 | 306 | // nothing to do here for mac |
46562151 | 307 | return true; |
e9576ca5 | 308 | } |