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
24 friend class WXDLLIMPEXP_FWD_CORE wxPen
;
27 wxPenRefData(const wxPenRefData
& data
);
28 virtual ~wxPenRefData();
30 wxPenRefData
& operator=(const wxPenRefData
& data
);
32 bool operator==(const wxPenRefData
& data
) const
34 // we intentionally don't compare m_hPen fields here
35 return m_style
== data
.m_style
&&
36 m_width
== data
.m_width
&&
37 m_join
== data
.m_join
&&
38 m_cap
== data
.m_cap
&&
39 m_colour
== data
.m_colour
&&
40 (m_style
!= wxSTIPPLE
|| m_stipple
.IsSameAs(data
.m_stipple
)) &&
41 (m_style
!= wxUSER_DASH
||
42 (m_nbDash
== data
.m_nbDash
&&
43 memcmp(m_dash
, data
.m_dash
, m_nbDash
*sizeof(wxDash
)) == 0));
55 /* TODO: implementation
60 wxPenRefData::wxPenRefData()
64 m_join
= wxJOIN_ROUND
;
70 wxPenRefData::wxPenRefData(const wxPenRefData
& data
)
73 m_style
= data
.m_style
;
74 m_width
= data
.m_width
;
77 m_nbDash
= data
.m_nbDash
;
79 m_colour
= data
.m_colour
;
82 wxPenRefData::~wxPenRefData()
88 #define M_PENDATA ((wxPenRefData *)m_refData)
98 // Should implement Create
99 wxPen::wxPen(const wxColour
& col
, int Width
, int Style
)
101 m_refData
= new wxPenRefData
;
103 M_PENDATA
->m_colour
= col
;
104 M_PENDATA
->m_width
= Width
;
105 M_PENDATA
->m_style
= Style
;
106 M_PENDATA
->m_join
= wxJOIN_ROUND
;
107 M_PENDATA
->m_cap
= wxCAP_ROUND
;
108 M_PENDATA
->m_nbDash
= 0 ;
109 M_PENDATA
->m_dash
= 0 ;
114 wxPen::wxPen(const wxBitmap
& stipple
, int Width
)
116 m_refData
= new wxPenRefData
;
118 M_PENDATA
->m_stipple
= stipple
;
119 M_PENDATA
->m_width
= Width
;
120 M_PENDATA
->m_style
= wxSTIPPLE
;
121 M_PENDATA
->m_join
= wxJOIN_ROUND
;
122 M_PENDATA
->m_cap
= wxCAP_ROUND
;
123 M_PENDATA
->m_nbDash
= 0 ;
124 M_PENDATA
->m_dash
= 0 ;
129 bool wxPen::operator == (const wxPen
& pen
) const
131 const wxPenRefData
*penData
= (wxPenRefData
*)pen
.m_refData
;
133 // an invalid pen is only equal to another invalid pen
134 return m_refData
? penData
&& *M_PENDATA
== *penData
: !penData
;
137 wxColour
& wxPen::GetColour() const
139 return (M_PENDATA
? M_PENDATA
->m_colour
: wxNullColour
);
142 int wxPen::GetWidth() const
144 return (M_PENDATA
? M_PENDATA
->m_width
: 0);
147 int wxPen::GetStyle() const
149 return (M_PENDATA
? M_PENDATA
->m_style
: 0);
152 int wxPen::GetJoin() const
154 return (M_PENDATA
? M_PENDATA
->m_join
: 0);
157 int wxPen::GetCap() const
159 return (M_PENDATA
? M_PENDATA
->m_cap
: 0);
162 int wxPen::GetDashes(wxDash
**ptr
) const
164 *ptr
= (M_PENDATA
? M_PENDATA
->m_dash
: (wxDash
*) NULL
); return (M_PENDATA
? M_PENDATA
->m_nbDash
: 0);
167 wxBitmap
*wxPen::GetStipple() const
169 return (M_PENDATA
? (& M_PENDATA
->m_stipple
) : (wxBitmap
*) NULL
);
172 void wxPen::Unshare()
174 // Don't change shared data
177 m_refData
= new wxPenRefData();
181 wxPenRefData
* ref
= new wxPenRefData(*(wxPenRefData
*)m_refData
);
187 void wxPen::SetColour(const wxColour
& col
)
191 M_PENDATA
->m_colour
= col
;
196 void wxPen::SetColour(unsigned char r
, unsigned char g
, unsigned char b
)
200 M_PENDATA
->m_colour
.Set(r
, g
, b
);
205 void wxPen::SetWidth(int Width
)
209 M_PENDATA
->m_width
= Width
;
214 void wxPen::SetStyle(int Style
)
218 M_PENDATA
->m_style
= Style
;
223 void wxPen::SetStipple(const wxBitmap
& Stipple
)
227 M_PENDATA
->m_stipple
= Stipple
;
228 M_PENDATA
->m_style
= wxSTIPPLE
;
233 void wxPen::SetDashes(int nb_dashes
, const wxDash
*Dash
)
237 M_PENDATA
->m_nbDash
= nb_dashes
;
238 M_PENDATA
->m_dash
= (wxDash
*)Dash
;
243 void wxPen::SetJoin(int Join
)
247 M_PENDATA
->m_join
= Join
;
252 void wxPen::SetCap(int Cap
)
256 M_PENDATA
->m_cap
= Cap
;
261 bool wxPen::RealizeResource()
263 // nothing to do here for mac