1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/mac/carbon/pen.cpp
4 // Author: Stefan Csomor
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #include "wx/wxprec.h"
20 IMPLEMENT_DYNAMIC_CLASS(wxPen
, wxGDIObject
)
22 class WXDLLEXPORT wxPenRefData
: public wxGDIRefData
26 wxPenRefData(const wxPenRefData
& data
);
27 virtual ~wxPenRefData();
29 wxPenRefData
& operator=(const wxPenRefData
& data
);
31 bool operator==(const wxPenRefData
& data
) const
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));
54 /* TODO: implementation
58 friend class WXDLLIMPEXP_FWD_CORE wxPen
;
61 wxPenRefData::wxPenRefData()
65 m_join
= wxJOIN_ROUND
;
71 wxPenRefData::wxPenRefData(const wxPenRefData
& data
)
74 m_style
= data
.m_style
;
75 m_width
= data
.m_width
;
78 m_nbDash
= data
.m_nbDash
;
80 m_colour
= data
.m_colour
;
83 wxPenRefData::~wxPenRefData()
89 #define M_PENDATA ((wxPenRefData *)m_refData)
99 // Should implement Create
100 wxPen::wxPen(const wxColour
& col
, int Width
, int Style
)
102 m_refData
= new wxPenRefData
;
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 ;
115 wxPen::wxPen(const wxBitmap
& stipple
, int Width
)
117 m_refData
= new wxPenRefData
;
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 ;
130 wxGDIRefData
*wxPen::CreateGDIRefData() const
132 return new wxPenRefData
;
135 wxGDIRefData
*wxPen::CloneGDIRefData(const wxGDIRefData
*data
) const
137 return new wxPenRefData(*wx_static_cast(const wxPenRefData
*, data
));
140 bool wxPen::operator==(const wxPen
& pen
) const
142 const wxPenRefData
*penData
= (wxPenRefData
*)pen
.m_refData
;
144 // an invalid pen is only equal to another invalid pen
145 return m_refData
? penData
&& *M_PENDATA
== *penData
: !penData
;
148 wxColour
& wxPen::GetColour() const
150 return (M_PENDATA
? M_PENDATA
->m_colour
: wxNullColour
);
153 int wxPen::GetWidth() const
155 return (M_PENDATA
? M_PENDATA
->m_width
: 0);
158 int wxPen::GetStyle() const
160 return (M_PENDATA
? M_PENDATA
->m_style
: 0);
163 int wxPen::GetJoin() const
165 return (M_PENDATA
? M_PENDATA
->m_join
: 0);
168 int wxPen::GetCap() const
170 return (M_PENDATA
? M_PENDATA
->m_cap
: 0);
173 int wxPen::GetDashes(wxDash
**ptr
) const
175 *ptr
= (M_PENDATA
? M_PENDATA
->m_dash
: (wxDash
*) NULL
); return (M_PENDATA
? M_PENDATA
->m_nbDash
: 0);
178 wxBitmap
*wxPen::GetStipple() const
180 return (M_PENDATA
? (& M_PENDATA
->m_stipple
) : (wxBitmap
*) NULL
);
183 void wxPen::Unshare()
185 // Don't change shared data
188 m_refData
= new wxPenRefData();
192 wxPenRefData
* ref
= new wxPenRefData(*(wxPenRefData
*)m_refData
);
198 void wxPen::SetColour(const wxColour
& col
)
202 M_PENDATA
->m_colour
= col
;
207 void wxPen::SetColour(unsigned char r
, unsigned char g
, unsigned char b
)
211 M_PENDATA
->m_colour
.Set(r
, g
, b
);
216 void wxPen::SetWidth(int Width
)
220 M_PENDATA
->m_width
= Width
;
225 void wxPen::SetStyle(int Style
)
229 M_PENDATA
->m_style
= Style
;
234 void wxPen::SetStipple(const wxBitmap
& Stipple
)
238 M_PENDATA
->m_stipple
= Stipple
;
239 M_PENDATA
->m_style
= wxSTIPPLE
;
244 void wxPen::SetDashes(int nb_dashes
, const wxDash
*Dash
)
248 M_PENDATA
->m_nbDash
= nb_dashes
;
249 M_PENDATA
->m_dash
= (wxDash
*)Dash
;
254 void wxPen::SetJoin(int Join
)
258 M_PENDATA
->m_join
= Join
;
263 void wxPen::SetCap(int Cap
)
267 M_PENDATA
->m_cap
= Cap
;
272 bool wxPen::RealizeResource()
274 // nothing to do here for mac