]> git.saurik.com Git - wxWidgets.git/blame - src/mac/carbon/pen.cpp
remove leading dots from .ini/.conf in AddConfFileExtIfNeeded() as this results in...
[wxWidgets.git] / src / mac / carbon / pen.cpp
CommitLineData
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 20IMPLEMENT_DYNAMIC_CLASS(wxPen, wxGDIObject)
e9576ca5 21
8f884a0d 22class WXDLLEXPORT wxPenRefData : public wxGDIRefData
46623e91 23{
46623e91
SC
24public:
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
45protected:
8f884a0d
VZ
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;
46623e91
SC
59};
60
e9576ca5
SC
61wxPenRefData::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
71wxPenRefData::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
83wxPenRefData::~wxPenRefData()
84{
e9576ca5
SC
85}
86
87// Pens
88
46623e91
SC
89#define M_PENDATA ((wxPenRefData *)m_refData)
90
e9576ca5
SC
91wxPen::wxPen()
92{
e9576ca5
SC
93}
94
95wxPen::~wxPen()
96{
e9576ca5
SC
97}
98
99// Should implement Create
100wxPen::wxPen(const wxColour& col, int Width, int Style)
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
115wxPen::wxPen(const wxBitmap& stipple, int Width)
116{
117 m_refData = new wxPenRefData;
46562151 118
e9576ca5
SC
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 ;
2f1ae414 125 M_PENDATA->m_dash = 0 ;
46562151 126
e9576ca5 127 RealizeResource();
e9576ca5
SC
128}
129
8f884a0d
VZ
130wxGDIRefData *wxPen::CreateGDIRefData() const
131{
132 return new wxPenRefData;
133}
134
135wxGDIRefData *wxPen::CloneGDIRefData(const wxGDIRefData *data) const
136{
137 return new wxPenRefData(*wx_static_cast(const wxPenRefData *, data));
138}
139
140bool wxPen::operator==(const wxPen& pen) const
46623e91
SC
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
8f884a0d
VZ
148wxColour& wxPen::GetColour() const
149{
150 return (M_PENDATA ? M_PENDATA->m_colour : wxNullColour);
46623e91
SC
151}
152
8f884a0d
VZ
153int wxPen::GetWidth() const
154{
155 return (M_PENDATA ? M_PENDATA->m_width : 0);
46623e91
SC
156}
157
8f884a0d
VZ
158int wxPen::GetStyle() const
159{
160 return (M_PENDATA ? M_PENDATA->m_style : 0);
46623e91
SC
161}
162
8f884a0d
VZ
163int wxPen::GetJoin() const
164{
165 return (M_PENDATA ? M_PENDATA->m_join : 0);
46623e91
SC
166}
167
8f884a0d
VZ
168int wxPen::GetCap() const
169{
170 return (M_PENDATA ? M_PENDATA->m_cap : 0);
46623e91
SC
171}
172
8f884a0d 173int wxPen::GetDashes(wxDash **ptr) const
46623e91
SC
174{
175 *ptr = (M_PENDATA ? M_PENDATA->m_dash : (wxDash*) NULL); return (M_PENDATA ? M_PENDATA->m_nbDash : 0);
176}
177
8f884a0d
VZ
178wxBitmap *wxPen::GetStipple() const
179{
180 return (M_PENDATA ? (& M_PENDATA->m_stipple) : (wxBitmap*) NULL);
46623e91
SC
181}
182
83dcd781 183void wxPen::Unshare()
e9576ca5 184{
83dcd781
PC
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 }
e9576ca5
SC
196}
197
198void wxPen::SetColour(const wxColour& col)
199{
83dcd781 200 Unshare();
46562151 201
e9576ca5 202 M_PENDATA->m_colour = col;
46562151 203
e9576ca5
SC
204 RealizeResource();
205}
206
1a1498c0 207void wxPen::SetColour(unsigned char r, unsigned char g, unsigned char b)
e9576ca5 208{
83dcd781 209 Unshare();
46562151 210
e9576ca5 211 M_PENDATA->m_colour.Set(r, g, b);
46562151 212
e9576ca5
SC
213 RealizeResource();
214}
215
216void wxPen::SetWidth(int Width)
217{
83dcd781 218 Unshare();
46562151 219
e9576ca5 220 M_PENDATA->m_width = Width;
46562151 221
e9576ca5
SC
222 RealizeResource();
223}
224
225void wxPen::SetStyle(int Style)
226{
83dcd781 227 Unshare();
46562151 228
e9576ca5 229 M_PENDATA->m_style = Style;
46562151 230
e9576ca5
SC
231 RealizeResource();
232}
233
234void wxPen::SetStipple(const wxBitmap& Stipple)
235{
83dcd781 236 Unshare();
46562151 237
e9576ca5
SC
238 M_PENDATA->m_stipple = Stipple;
239 M_PENDATA->m_style = wxSTIPPLE;
46562151 240
e9576ca5
SC
241 RealizeResource();
242}
243
244void wxPen::SetDashes(int nb_dashes, const wxDash *Dash)
245{
83dcd781 246 Unshare();
46562151 247
e9576ca5 248 M_PENDATA->m_nbDash = nb_dashes;
2f1ae414 249 M_PENDATA->m_dash = (wxDash *)Dash;
46562151 250
e9576ca5
SC
251 RealizeResource();
252}
253
254void wxPen::SetJoin(int Join)
255{
83dcd781 256 Unshare();
46562151 257
e9576ca5 258 M_PENDATA->m_join = Join;
46562151 259
e9576ca5
SC
260 RealizeResource();
261}
262
263void wxPen::SetCap(int Cap)
264{
83dcd781 265 Unshare();
46562151 266
e9576ca5 267 M_PENDATA->m_cap = Cap;
46562151 268
e9576ca5
SC
269 RealizeResource();
270}
271
272bool wxPen::RealizeResource()
273{
e40298d5 274 // nothing to do here for mac
46562151 275 return true;
e9576ca5 276}