]>
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 && | |
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)); | |
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 | { | |
63 | m_style = wxSOLID; | |
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 | ||
82cddbd9 FM |
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 | ||
e9576ca5 SC |
130 | wxPen::wxPen(const wxBitmap& stipple, int Width) |
131 | { | |
132 | m_refData = new wxPenRefData; | |
46562151 | 133 | |
e9576ca5 SC |
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 ; | |
2f1ae414 | 140 | M_PENDATA->m_dash = 0 ; |
46562151 | 141 | |
e9576ca5 | 142 | RealizeResource(); |
e9576ca5 SC |
143 | } |
144 | ||
8f884a0d VZ |
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 | |
46623e91 SC |
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 | ||
8f884a0d VZ |
163 | wxColour& wxPen::GetColour() const |
164 | { | |
165 | return (M_PENDATA ? M_PENDATA->m_colour : wxNullColour); | |
46623e91 SC |
166 | } |
167 | ||
8f884a0d VZ |
168 | int wxPen::GetWidth() const |
169 | { | |
170 | return (M_PENDATA ? M_PENDATA->m_width : 0); | |
46623e91 SC |
171 | } |
172 | ||
82cddbd9 | 173 | wxPenStyle wxPen::GetStyle() const |
8f884a0d VZ |
174 | { |
175 | return (M_PENDATA ? M_PENDATA->m_style : 0); | |
46623e91 SC |
176 | } |
177 | ||
82cddbd9 | 178 | wxPenJoin wxPen::GetJoin() const |
8f884a0d VZ |
179 | { |
180 | return (M_PENDATA ? M_PENDATA->m_join : 0); | |
46623e91 SC |
181 | } |
182 | ||
82cddbd9 | 183 | wxPenCap wxPen::GetCap() const |
8f884a0d VZ |
184 | { |
185 | return (M_PENDATA ? M_PENDATA->m_cap : 0); | |
46623e91 SC |
186 | } |
187 | ||
8f884a0d | 188 | int wxPen::GetDashes(wxDash **ptr) const |
46623e91 SC |
189 | { |
190 | *ptr = (M_PENDATA ? M_PENDATA->m_dash : (wxDash*) NULL); return (M_PENDATA ? M_PENDATA->m_nbDash : 0); | |
191 | } | |
192 | ||
8f884a0d VZ |
193 | wxBitmap *wxPen::GetStipple() const |
194 | { | |
195 | return (M_PENDATA ? (& M_PENDATA->m_stipple) : (wxBitmap*) NULL); | |
46623e91 SC |
196 | } |
197 | ||
83dcd781 | 198 | void wxPen::Unshare() |
e9576ca5 | 199 | { |
83dcd781 PC |
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 | } | |
e9576ca5 SC |
211 | } |
212 | ||
213 | void wxPen::SetColour(const wxColour& col) | |
214 | { | |
83dcd781 | 215 | Unshare(); |
46562151 | 216 | |
e9576ca5 | 217 | M_PENDATA->m_colour = col; |
46562151 | 218 | |
e9576ca5 SC |
219 | RealizeResource(); |
220 | } | |
221 | ||
1a1498c0 | 222 | void wxPen::SetColour(unsigned char r, unsigned char g, unsigned char b) |
e9576ca5 | 223 | { |
83dcd781 | 224 | Unshare(); |
46562151 | 225 | |
e9576ca5 | 226 | M_PENDATA->m_colour.Set(r, g, b); |
46562151 | 227 | |
e9576ca5 SC |
228 | RealizeResource(); |
229 | } | |
230 | ||
231 | void wxPen::SetWidth(int Width) | |
232 | { | |
83dcd781 | 233 | Unshare(); |
46562151 | 234 | |
e9576ca5 | 235 | M_PENDATA->m_width = Width; |
46562151 | 236 | |
e9576ca5 SC |
237 | RealizeResource(); |
238 | } | |
239 | ||
82cddbd9 | 240 | void wxPen::SetStyle(wxPenStyle Style) |
e9576ca5 | 241 | { |
83dcd781 | 242 | Unshare(); |
46562151 | 243 | |
e9576ca5 | 244 | M_PENDATA->m_style = Style; |
46562151 | 245 | |
e9576ca5 SC |
246 | RealizeResource(); |
247 | } | |
248 | ||
249 | void wxPen::SetStipple(const wxBitmap& Stipple) | |
250 | { | |
83dcd781 | 251 | Unshare(); |
46562151 | 252 | |
e9576ca5 SC |
253 | M_PENDATA->m_stipple = Stipple; |
254 | M_PENDATA->m_style = wxSTIPPLE; | |
46562151 | 255 | |
e9576ca5 SC |
256 | RealizeResource(); |
257 | } | |
258 | ||
259 | void wxPen::SetDashes(int nb_dashes, const wxDash *Dash) | |
260 | { | |
83dcd781 | 261 | Unshare(); |
46562151 | 262 | |
e9576ca5 | 263 | M_PENDATA->m_nbDash = nb_dashes; |
2f1ae414 | 264 | M_PENDATA->m_dash = (wxDash *)Dash; |
46562151 | 265 | |
e9576ca5 SC |
266 | RealizeResource(); |
267 | } | |
268 | ||
82cddbd9 | 269 | void wxPen::SetJoin(wxPenJoin Join) |
e9576ca5 | 270 | { |
83dcd781 | 271 | Unshare(); |
46562151 | 272 | |
e9576ca5 | 273 | M_PENDATA->m_join = Join; |
46562151 | 274 | |
e9576ca5 SC |
275 | RealizeResource(); |
276 | } | |
277 | ||
82cddbd9 | 278 | void wxPen::SetCap(wxPenCap Cap) |
e9576ca5 | 279 | { |
83dcd781 | 280 | Unshare(); |
46562151 | 281 | |
e9576ca5 | 282 | M_PENDATA->m_cap = Cap; |
46562151 | 283 | |
e9576ca5 SC |
284 | RealizeResource(); |
285 | } | |
286 | ||
287 | bool wxPen::RealizeResource() | |
288 | { | |
e40298d5 | 289 | // nothing to do here for mac |
46562151 | 290 | return true; |
e9576ca5 | 291 | } |