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
!= wxPENSTYLE_STIPPLE
|| m_stipple
.IsSameAs(data
.m_stipple
)) &&
40 (m_style
!= wxPENSTYLE_USER_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()
63 m_style
= wxPENSTYLE_SOLID
;
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
, wxPenStyle 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 wxColour
& col
, int Width
, wxBrushStyle Style
)
117 m_refData
= new wxPenRefData
;
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 ;
130 wxPen::wxPen(const wxBitmap
& stipple
, int Width
)
132 m_refData
= new wxPenRefData
;
134 M_PENDATA
->m_stipple
= stipple
;
135 M_PENDATA
->m_width
= Width
;
136 M_PENDATA
->m_style
= wxPENSTYLE_STIPPLE
;
137 M_PENDATA
->m_join
= wxJOIN_ROUND
;
138 M_PENDATA
->m_cap
= wxCAP_ROUND
;
139 M_PENDATA
->m_nbDash
= 0 ;
140 M_PENDATA
->m_dash
= 0 ;
145 wxGDIRefData
*wxPen::CreateGDIRefData() const
147 return new wxPenRefData
;
150 wxGDIRefData
*wxPen::CloneGDIRefData(const wxGDIRefData
*data
) const
152 return new wxPenRefData(*wx_static_cast(const wxPenRefData
*, data
));
155 bool wxPen::operator==(const wxPen
& pen
) const
157 const wxPenRefData
*penData
= (wxPenRefData
*)pen
.m_refData
;
159 // an invalid pen is only equal to another invalid pen
160 return m_refData
? penData
&& *M_PENDATA
== *penData
: !penData
;
163 wxColour
& wxPen::GetColour() const
165 return (M_PENDATA
? M_PENDATA
->m_colour
: wxNullColour
);
168 int wxPen::GetWidth() const
170 return (M_PENDATA
? M_PENDATA
->m_width
: 0);
173 wxPenStyle
wxPen::GetStyle() const
175 return (M_PENDATA
? M_PENDATA
->m_style
: wxPENSTYLE_SOLID
);
178 wxPenJoin
wxPen::GetJoin() const
180 return (M_PENDATA
? M_PENDATA
->m_join
: wxJOIN_INVALID
);
183 wxPenCap
wxPen::GetCap() const
185 return (M_PENDATA
? M_PENDATA
->m_cap
: wxCAP_INVALID
);
188 int wxPen::GetDashes(wxDash
**ptr
) const
190 *ptr
= (M_PENDATA
? M_PENDATA
->m_dash
: (wxDash
*) NULL
); return (M_PENDATA
? M_PENDATA
->m_nbDash
: 0);
193 wxBitmap
*wxPen::GetStipple() const
195 return (M_PENDATA
? (& M_PENDATA
->m_stipple
) : (wxBitmap
*) NULL
);
198 void wxPen::Unshare()
200 // Don't change shared data
203 m_refData
= new wxPenRefData();
207 wxPenRefData
* ref
= new wxPenRefData(*(wxPenRefData
*)m_refData
);
213 void wxPen::SetColour(const wxColour
& col
)
217 M_PENDATA
->m_colour
= col
;
222 void wxPen::SetColour(unsigned char r
, unsigned char g
, unsigned char b
)
226 M_PENDATA
->m_colour
.Set(r
, g
, b
);
231 void wxPen::SetWidth(int Width
)
235 M_PENDATA
->m_width
= Width
;
240 void wxPen::SetStyle(wxPenStyle Style
)
244 M_PENDATA
->m_style
= Style
;
249 void wxPen::SetStipple(const wxBitmap
& Stipple
)
253 M_PENDATA
->m_stipple
= Stipple
;
254 M_PENDATA
->m_style
= wxPENSTYLE_STIPPLE
;
259 void wxPen::SetDashes(int nb_dashes
, const wxDash
*Dash
)
263 M_PENDATA
->m_nbDash
= nb_dashes
;
264 M_PENDATA
->m_dash
= (wxDash
*)Dash
;
269 void wxPen::SetJoin(wxPenJoin Join
)
273 M_PENDATA
->m_join
= Join
;
278 void wxPen::SetCap(wxPenCap Cap
)
282 M_PENDATA
->m_cap
= Cap
;
287 bool wxPen::RealizeResource()
289 // nothing to do here for mac