1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/osx/pen.cpp
4 // Author: Stefan Csomor
7 // Copyright: (c) Stefan Csomor
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 #include "wx/wxprec.h"
19 IMPLEMENT_DYNAMIC_CLASS(wxPen
, wxGDIObject
)
21 class WXDLLEXPORT wxPenRefData
: public wxGDIRefData
25 wxPenRefData(const wxPenRefData
& data
);
26 virtual ~wxPenRefData();
28 wxPenRefData
& operator=(const wxPenRefData
& data
);
30 bool operator==(const wxPenRefData
& data
) const
32 // we intentionally don't compare m_hPen fields here
33 return m_style
== data
.m_style
&&
34 m_width
== data
.m_width
&&
35 m_join
== data
.m_join
&&
36 m_cap
== data
.m_cap
&&
37 m_colour
== data
.m_colour
&&
38 (m_style
!= wxPENSTYLE_STIPPLE
|| m_stipple
.IsSameAs(data
.m_stipple
)) &&
39 (m_style
!= wxPENSTYLE_USER_DASH
||
40 (m_nbDash
== data
.m_nbDash
&&
41 memcmp(m_dash
, data
.m_dash
, m_nbDash
*sizeof(wxDash
)) == 0));
53 /* TODO: implementation
57 friend class WXDLLIMPEXP_FWD_CORE wxPen
;
60 wxPenRefData::wxPenRefData()
62 m_style
= wxPENSTYLE_SOLID
;
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
, wxPenStyle 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 #if FUTURE_WXWIN_COMPATIBILITY_3_0
115 wxPen::wxPen(const wxColour
& col
, int Width
, int 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 ;
131 wxPen::wxPen(const wxBitmap
& stipple
, int Width
)
133 m_refData
= new wxPenRefData
;
135 M_PENDATA
->m_stipple
= stipple
;
136 M_PENDATA
->m_width
= Width
;
137 M_PENDATA
->m_style
= wxPENSTYLE_STIPPLE
;
138 M_PENDATA
->m_join
= wxJOIN_ROUND
;
139 M_PENDATA
->m_cap
= wxCAP_ROUND
;
140 M_PENDATA
->m_nbDash
= 0 ;
141 M_PENDATA
->m_dash
= 0 ;
146 wxGDIRefData
*wxPen::CreateGDIRefData() const
148 return new wxPenRefData
;
151 wxGDIRefData
*wxPen::CloneGDIRefData(const wxGDIRefData
*data
) const
153 return new wxPenRefData(*static_cast<const wxPenRefData
*>(data
));
156 bool wxPen::operator==(const wxPen
& pen
) const
158 const wxPenRefData
*penData
= (wxPenRefData
*)pen
.m_refData
;
160 // an invalid pen is only equal to another invalid pen
161 return m_refData
? penData
&& *M_PENDATA
== *penData
: !penData
;
164 wxColour
wxPen::GetColour() const
166 wxCHECK_MSG( IsOk(), wxNullColour
, wxT("invalid pen") );
168 return M_PENDATA
->m_colour
;
171 int wxPen::GetWidth() const
173 wxCHECK_MSG( IsOk(), -1, wxT("invalid pen") );
175 return M_PENDATA
->m_width
;
178 wxPenStyle
wxPen::GetStyle() const
180 wxCHECK_MSG( IsOk(), wxPENSTYLE_INVALID
, wxT("invalid pen") );
182 return M_PENDATA
->m_style
;
185 wxPenJoin
wxPen::GetJoin() const
187 wxCHECK_MSG( IsOk(), wxJOIN_INVALID
, wxT("invalid pen") );
189 return M_PENDATA
->m_join
;
192 wxPenCap
wxPen::GetCap() const
194 wxCHECK_MSG( IsOk(), wxCAP_INVALID
, wxT("invalid pen") );
196 return M_PENDATA
->m_cap
;
199 int wxPen::GetDashes(wxDash
**ptr
) const
201 wxCHECK_MSG( IsOk(), -1, wxT("invalid pen") );
203 *ptr
= M_PENDATA
->m_dash
;
204 return M_PENDATA
->m_nbDash
;
207 int wxPen::GetDashCount() const
209 return M_PENDATA
->m_nbDash
;
212 wxBitmap
*wxPen::GetStipple() const
214 wxCHECK_MSG( IsOk(), NULL
, wxT("invalid pen") );
216 return &M_PENDATA
->m_stipple
;
219 void wxPen::Unshare()
221 // Don't change shared data
224 m_refData
= new wxPenRefData();
228 wxPenRefData
* ref
= new wxPenRefData(*(wxPenRefData
*)m_refData
);
234 void wxPen::SetColour(const wxColour
& col
)
238 M_PENDATA
->m_colour
= col
;
243 void wxPen::SetColour(unsigned char r
, unsigned char g
, unsigned char b
)
247 M_PENDATA
->m_colour
.Set(r
, g
, b
);
252 void wxPen::SetWidth(int Width
)
256 M_PENDATA
->m_width
= Width
;
261 void wxPen::SetStyle(wxPenStyle Style
)
265 M_PENDATA
->m_style
= Style
;
270 void wxPen::SetStipple(const wxBitmap
& Stipple
)
274 M_PENDATA
->m_stipple
= Stipple
;
275 M_PENDATA
->m_style
= wxPENSTYLE_STIPPLE
;
280 void wxPen::SetDashes(int nb_dashes
, const wxDash
*Dash
)
284 M_PENDATA
->m_nbDash
= nb_dashes
;
285 M_PENDATA
->m_dash
= (wxDash
*)Dash
;
290 void wxPen::SetJoin(wxPenJoin Join
)
294 M_PENDATA
->m_join
= Join
;
299 void wxPen::SetCap(wxPenCap Cap
)
303 M_PENDATA
->m_cap
= Cap
;
308 bool wxPen::RealizeResource()
310 // nothing to do here for mac