]> git.saurik.com Git - wxWidgets.git/blame - src/x11/pen.cpp
missing commit
[wxWidgets.git] / src / x11 / pen.cpp
CommitLineData
83df96d6 1/////////////////////////////////////////////////////////////////////////////
7266b672 2// Name: src/x11/pen.cpp
83df96d6
JS
3// Purpose: wxPen
4// Author: Julian Smart
5// Modified by:
6// Created: 17/09/98
7// RCS-ID: $Id$
8// Copyright: (c) Julian Smart
65571936 9// Licence: wxWindows licence
83df96d6
JS
10/////////////////////////////////////////////////////////////////////////////
11
55034339
WS
12// for compilers that support precompilation, includes "wx.h".
13#include "wx/wxprec.h"
14
83df96d6 15#include "wx/pen.h"
de6185e2
WS
16
17#ifndef WX_PRECOMP
18 #include "wx/utils.h"
0bca0373 19 #include "wx/bitmap.h"
7cf41a5d 20 #include "wx/colour.h"
de6185e2
WS
21#endif
22
74dc5eb6
RR
23//-----------------------------------------------------------------------------
24// wxPen
25//-----------------------------------------------------------------------------
83df96d6 26
8f884a0d 27class wxPenRefData : public wxGDIRefData
83df96d6 28{
74dc5eb6
RR
29public:
30 wxPenRefData()
31 {
32 m_width = 1;
ed7ec76d 33 m_style = wxPENSTYLE_SOLID;
74dc5eb6
RR
34 m_joinStyle = wxJOIN_ROUND;
35 m_capStyle = wxCAP_ROUND;
d3b9f782 36 m_dash = NULL;
74dc5eb6
RR
37 m_countDashes = 0;
38 }
55034339 39
74dc5eb6
RR
40 wxPenRefData( const wxPenRefData& data )
41 {
42 m_style = data.m_style;
43 m_width = data.m_width;
44 m_joinStyle = data.m_joinStyle;
45 m_capStyle = data.m_capStyle;
46 m_colour = data.m_colour;
47 m_countDashes = data.m_countDashes;
48/*
49 if (data.m_dash) TODO
50 m_dash = new
51*/
52 m_dash = data.m_dash;
69c44812 53 m_stipple = data.m_stipple;
74dc5eb6 54 }
83df96d6 55
74dc5eb6
RR
56 bool operator == (const wxPenRefData& data) const
57 {
58 return (m_style == data.m_style &&
59 m_width == data.m_width &&
60 m_joinStyle == data.m_joinStyle &&
61 m_capStyle == data.m_capStyle &&
62 m_colour == data.m_colour);
63 }
55034339 64
74dc5eb6 65 int m_width;
82cddbd9
FM
66 wxPenStyle m_style;
67 wxPenJoin m_joinStyle;
68 wxPenCap m_capStyle;
74dc5eb6
RR
69 wxColour m_colour;
70 int m_countDashes;
69c44812 71 wxBitmap m_stipple;
74dc5eb6
RR
72 wxX11Dash *m_dash;
73};
83df96d6 74
74dc5eb6
RR
75//-----------------------------------------------------------------------------
76
77#define M_PENDATA ((wxPenRefData *)m_refData)
83df96d6 78
74dc5eb6 79IMPLEMENT_DYNAMIC_CLASS(wxPen,wxGDIObject)
83df96d6 80
82cddbd9 81wxPen::wxPen( const wxColour &colour, int width, wxPenStyle style )
83df96d6 82{
74dc5eb6
RR
83 m_refData = new wxPenRefData();
84 M_PENDATA->m_width = width;
85 M_PENDATA->m_style = style;
86 M_PENDATA->m_colour = colour;
83df96d6
JS
87}
88
ac3688c0
FM
89#if FUTURE_WXWIN_COMPATIBILITY_3_0
90wxPen::wxPen(const wxColour& colour, int width, int style)
82cddbd9
FM
91{
92 m_refData = new wxPenRefData();
93 M_PENDATA->m_width = width;
94 M_PENDATA->m_style = (wxPenStyle)style;
95 M_PENDATA->m_colour = colour;
96}
ac3688c0 97#endif
82cddbd9 98
83df96d6
JS
99wxPen::~wxPen()
100{
74dc5eb6 101 // m_refData unrefed in ~wxObject
83df96d6
JS
102}
103
8f884a0d 104wxGDIRefData *wxPen::CreateGDIRefData() const
83df96d6 105{
74dc5eb6 106 return new wxPenRefData;
83df96d6
JS
107}
108
8f884a0d 109wxGDIRefData *wxPen::CloneGDIRefData(const wxGDIRefData *data) const
83df96d6 110{
74dc5eb6 111 return new wxPenRefData(*(wxPenRefData *)data);
83df96d6
JS
112}
113
74dc5eb6 114bool wxPen::operator == ( const wxPen& pen ) const
83df96d6 115{
55034339
WS
116 if (m_refData == pen.m_refData) return true;
117
118 if (!m_refData || !pen.m_refData) return false;
119
74dc5eb6 120 return ( *(wxPenRefData*)m_refData == *(wxPenRefData*)pen.m_refData );
83df96d6
JS
121}
122
74dc5eb6 123void wxPen::SetColour( const wxColour &colour )
83df96d6 124{
74dc5eb6 125 AllocExclusive();
55034339 126
74dc5eb6 127 M_PENDATA->m_colour = colour;
83df96d6
JS
128}
129
74dc5eb6 130void wxPen::SetDashes( int number_of_dashes, const wxDash *dash )
83df96d6 131{
74dc5eb6 132 AllocExclusive();
55034339 133
74dc5eb6
RR
134 M_PENDATA->m_countDashes = number_of_dashes;
135 M_PENDATA->m_dash = (wxX11Dash *)dash; // TODO
136}
83df96d6 137
1a1498c0 138void wxPen::SetColour( unsigned char red, unsigned char green, unsigned char blue )
74dc5eb6
RR
139{
140 AllocExclusive();
55034339 141
74dc5eb6 142 M_PENDATA->m_colour.Set( red, green, blue );
83df96d6
JS
143}
144
82cddbd9 145void wxPen::SetCap( wxPenCap capStyle )
83df96d6 146{
74dc5eb6 147 AllocExclusive();
55034339 148
74dc5eb6
RR
149 M_PENDATA->m_capStyle = capStyle;
150}
83df96d6 151
82cddbd9 152void wxPen::SetJoin( wxPenJoin joinStyle )
74dc5eb6
RR
153{
154 AllocExclusive();
55034339 155
74dc5eb6
RR
156 M_PENDATA->m_joinStyle = joinStyle;
157}
83df96d6 158
2051c39f 159void wxPen::SetStipple( const wxBitmap& stipple )
69c44812
MB
160{
161 AllocExclusive();
55034339 162
2051c39f 163 M_PENDATA->m_stipple = stipple;
69c44812
MB
164}
165
82cddbd9 166void wxPen::SetStyle( wxPenStyle style )
74dc5eb6
RR
167{
168 AllocExclusive();
55034339 169
74dc5eb6 170 M_PENDATA->m_style = style;
83df96d6
JS
171}
172
74dc5eb6 173void wxPen::SetWidth( int width )
83df96d6 174{
74dc5eb6 175 AllocExclusive();
55034339 176
74dc5eb6
RR
177 M_PENDATA->m_width = width;
178}
83df96d6 179
74dc5eb6
RR
180int wxPen::GetDashes( wxDash **ptr ) const
181{
a1b806b9 182 wxCHECK_MSG( IsOk(), -1, wxT("invalid pen") );
ac3688c0
FM
183
184 *ptr = (wxDash*)M_PENDATA->m_dash;
185 return M_PENDATA->m_countDashes;
74dc5eb6 186}
83df96d6 187
74dc5eb6
RR
188int wxPen::GetDashCount() const
189{
190 return (M_PENDATA->m_countDashes);
83df96d6
JS
191}
192
74dc5eb6 193wxDash* wxPen::GetDash() const
83df96d6 194{
74dc5eb6
RR
195 return (wxDash*)M_PENDATA->m_dash;
196}
83df96d6 197
82cddbd9 198wxPenCap wxPen::GetCap() const
74dc5eb6 199{
a1b806b9 200 wxCHECK_MSG( IsOk(), wxCAP_INVALID, wxT("invalid pen") );
83df96d6 201
74dc5eb6 202 return M_PENDATA->m_capStyle;
83df96d6
JS
203}
204
82cddbd9 205wxPenJoin wxPen::GetJoin() const
83df96d6 206{
a1b806b9 207 wxCHECK_MSG( IsOk(), wxJOIN_INVALID, wxT("invalid pen") );
83df96d6 208
74dc5eb6 209 return M_PENDATA->m_joinStyle;
83df96d6
JS
210}
211
82cddbd9 212wxPenStyle wxPen::GetStyle() const
83df96d6 213{
a1b806b9 214 wxCHECK_MSG( IsOk(), wxPENSTYLE_INVALID, wxT("invalid pen") );
83df96d6 215
74dc5eb6 216 return M_PENDATA->m_style;
83df96d6
JS
217}
218
74dc5eb6 219int wxPen::GetWidth() const
83df96d6 220{
a1b806b9 221 wxCHECK_MSG( IsOk(), -1, wxT("invalid pen") );
83df96d6 222
74dc5eb6 223 return M_PENDATA->m_width;
83df96d6
JS
224}
225
231b9591 226wxColour wxPen::GetColour() const
83df96d6 227{
a1b806b9 228 wxCHECK_MSG( IsOk(), wxNullColour, wxT("invalid pen") );
83df96d6 229
74dc5eb6
RR
230 return M_PENDATA->m_colour;
231}
69c44812
MB
232
233wxBitmap *wxPen::GetStipple() const
234{
a1b806b9 235 wxCHECK_MSG( IsOk(), &wxNullBitmap, wxT("invalid pen") );
69c44812
MB
236
237 return &M_PENDATA->m_stipple;
238}