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 #if FUTURE_WXWIN_COMPATIBILITY_3_0
116 wxPen::wxPen(const wxColour
& col
, int Width
, int Style
)
118 m_refData
= new wxPenRefData
;
120 M_PENDATA
->m_colour
= col
;
121 M_PENDATA
->m_width
= Width
;
122 M_PENDATA
->m_style
= (wxPenStyle
)Style
;
123 M_PENDATA
->m_join
= wxJOIN_ROUND
;
124 M_PENDATA
->m_cap
= wxCAP_ROUND
;
125 M_PENDATA
->m_nbDash
= 0 ;
126 M_PENDATA
->m_dash
= 0 ;
132 wxPen::wxPen(const wxBitmap
& stipple
, int Width
)
134 m_refData
= new wxPenRefData
;
136 M_PENDATA
->m_stipple
= stipple
;
137 M_PENDATA
->m_width
= Width
;
138 M_PENDATA
->m_style
= wxPENSTYLE_STIPPLE
;
139 M_PENDATA
->m_join
= wxJOIN_ROUND
;
140 M_PENDATA
->m_cap
= wxCAP_ROUND
;
141 M_PENDATA
->m_nbDash
= 0 ;
142 M_PENDATA
->m_dash
= 0 ;
147 wxGDIRefData
*wxPen::CreateGDIRefData() const
149 return new wxPenRefData
;
152 wxGDIRefData
*wxPen::CloneGDIRefData(const wxGDIRefData
*data
) const
154 return new wxPenRefData(*wx_static_cast(const wxPenRefData
*, data
));
157 bool wxPen::operator==(const wxPen
& pen
) const
159 const wxPenRefData
*penData
= (wxPenRefData
*)pen
.m_refData
;
161 // an invalid pen is only equal to another invalid pen
162 return m_refData
? penData
&& *M_PENDATA
== *penData
: !penData
;
165 wxColour
& wxPen::GetColour() const
167 wxCHECK_MSG( Ok(), wxNullColour
, wxT("invalid pen") );
169 return M_PENDATA
->m_colour
;
172 int wxPen::GetWidth() const
174 wxCHECK_MSG( Ok(), -1, wxT("invalid pen") );
176 return M_PENDATA
->m_width
;
179 wxPenStyle
wxPen::GetStyle() const
181 wxCHECK_MSG( Ok(), wxPENSTYLE_INVALID
, wxT("invalid pen") );
183 return M_PENDATA
->m_style
;
186 wxPenJoin
wxPen::GetJoin() const
188 wxCHECK_MSG( Ok(), wxJOIN_INVALID
, wxT("invalid pen") );
190 return M_PENDATA
->m_join
;
193 wxPenCap
wxPen::GetCap() const
195 wxCHECK_MSG( Ok(), wxCAP_INVALID
, wxT("invalid pen") );
197 return M_PENDATA
->m_cap
;
200 int wxPen::GetDashes(wxDash
**ptr
) const
202 wxCHECK_MSG( Ok(), -1, wxT("invalid pen") );
204 *ptr
= M_PENDATA
->m_dash
;
205 return M_PENDATA
->m_nbDash
;
208 wxBitmap
*wxPen::GetStipple() const
210 wxCHECK_MSG( Ok(), NULL
, wxT("invalid pen") );
212 return &M_PENDATA
->m_stipple
;
215 void wxPen::Unshare()
217 // Don't change shared data
220 m_refData
= new wxPenRefData();
224 wxPenRefData
* ref
= new wxPenRefData(*(wxPenRefData
*)m_refData
);
230 void wxPen::SetColour(const wxColour
& col
)
234 M_PENDATA
->m_colour
= col
;
239 void wxPen::SetColour(unsigned char r
, unsigned char g
, unsigned char b
)
243 M_PENDATA
->m_colour
.Set(r
, g
, b
);
248 void wxPen::SetWidth(int Width
)
252 M_PENDATA
->m_width
= Width
;
257 void wxPen::SetStyle(wxPenStyle Style
)
261 M_PENDATA
->m_style
= Style
;
266 void wxPen::SetStipple(const wxBitmap
& Stipple
)
270 M_PENDATA
->m_stipple
= Stipple
;
271 M_PENDATA
->m_style
= wxPENSTYLE_STIPPLE
;
276 void wxPen::SetDashes(int nb_dashes
, const wxDash
*Dash
)
280 M_PENDATA
->m_nbDash
= nb_dashes
;
281 M_PENDATA
->m_dash
= (wxDash
*)Dash
;
286 void wxPen::SetJoin(wxPenJoin Join
)
290 M_PENDATA
->m_join
= Join
;
295 void wxPen::SetCap(wxPenCap Cap
)
299 M_PENDATA
->m_cap
= Cap
;
304 bool wxPen::RealizeResource()
306 // nothing to do here for mac