]> git.saurik.com Git - wxWidgets.git/blame - src/x11/pen.cpp
cleanup
[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
74dc5eb6 27class wxPenRefData: public wxObjectRefData
83df96d6 28{
74dc5eb6
RR
29public:
30 wxPenRefData()
31 {
32 m_width = 1;
33 m_style = wxSOLID;
34 m_joinStyle = wxJOIN_ROUND;
35 m_capStyle = wxCAP_ROUND;
36 m_dash = (wxX11Dash*) NULL;
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
RR
65 int m_width;
66 int m_style;
67 int m_joinStyle;
68 int m_capStyle;
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
74dc5eb6 81wxPen::wxPen( const wxColour &colour, int width, int 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
89wxPen::~wxPen()
90{
74dc5eb6 91 // m_refData unrefed in ~wxObject
83df96d6
JS
92}
93
74dc5eb6 94wxObjectRefData *wxPen::CreateRefData() const
83df96d6 95{
74dc5eb6 96 return new wxPenRefData;
83df96d6
JS
97}
98
74dc5eb6 99wxObjectRefData *wxPen::CloneRefData(const wxObjectRefData *data) const
83df96d6 100{
74dc5eb6 101 return new wxPenRefData(*(wxPenRefData *)data);
83df96d6
JS
102}
103
74dc5eb6 104bool wxPen::operator == ( const wxPen& pen ) const
83df96d6 105{
55034339
WS
106 if (m_refData == pen.m_refData) return true;
107
108 if (!m_refData || !pen.m_refData) return false;
109
74dc5eb6 110 return ( *(wxPenRefData*)m_refData == *(wxPenRefData*)pen.m_refData );
83df96d6
JS
111}
112
74dc5eb6 113void wxPen::SetColour( const wxColour &colour )
83df96d6 114{
74dc5eb6 115 AllocExclusive();
55034339 116
74dc5eb6 117 M_PENDATA->m_colour = colour;
83df96d6
JS
118}
119
74dc5eb6 120void wxPen::SetDashes( int number_of_dashes, const wxDash *dash )
83df96d6 121{
74dc5eb6 122 AllocExclusive();
55034339 123
74dc5eb6
RR
124 M_PENDATA->m_countDashes = number_of_dashes;
125 M_PENDATA->m_dash = (wxX11Dash *)dash; // TODO
126}
83df96d6 127
1a1498c0 128void wxPen::SetColour( unsigned char red, unsigned char green, unsigned char blue )
74dc5eb6
RR
129{
130 AllocExclusive();
55034339 131
74dc5eb6 132 M_PENDATA->m_colour.Set( red, green, blue );
83df96d6
JS
133}
134
74dc5eb6 135void wxPen::SetCap( int capStyle )
83df96d6 136{
74dc5eb6 137 AllocExclusive();
55034339 138
74dc5eb6
RR
139 M_PENDATA->m_capStyle = capStyle;
140}
83df96d6 141
74dc5eb6
RR
142void wxPen::SetJoin( int joinStyle )
143{
144 AllocExclusive();
55034339 145
74dc5eb6
RR
146 M_PENDATA->m_joinStyle = joinStyle;
147}
83df96d6 148
69c44812
MB
149void wxPen::SetStipple( wxBitmap *stipple )
150{
151 AllocExclusive();
55034339 152
1c4cd9e0 153 M_PENDATA->m_stipple = *stipple;
69c44812
MB
154}
155
74dc5eb6
RR
156void wxPen::SetStyle( int style )
157{
158 AllocExclusive();
55034339 159
74dc5eb6 160 M_PENDATA->m_style = style;
83df96d6
JS
161}
162
74dc5eb6 163void wxPen::SetWidth( int width )
83df96d6 164{
74dc5eb6 165 AllocExclusive();
55034339 166
74dc5eb6
RR
167 M_PENDATA->m_width = width;
168}
83df96d6 169
74dc5eb6
RR
170int wxPen::GetDashes( wxDash **ptr ) const
171{
172 *ptr = (M_PENDATA ? (wxDash*)M_PENDATA->m_dash : (wxDash*) NULL);
173 return (M_PENDATA ? M_PENDATA->m_countDashes : 0);
174}
83df96d6 175
74dc5eb6
RR
176int wxPen::GetDashCount() const
177{
178 return (M_PENDATA->m_countDashes);
83df96d6
JS
179}
180
74dc5eb6 181wxDash* wxPen::GetDash() const
83df96d6 182{
74dc5eb6
RR
183 return (wxDash*)M_PENDATA->m_dash;
184}
83df96d6 185
74dc5eb6
RR
186int wxPen::GetCap() const
187{
188 wxCHECK_MSG( Ok(), -1, wxT("invalid pen") );
83df96d6 189
74dc5eb6 190 return M_PENDATA->m_capStyle;
83df96d6
JS
191}
192
74dc5eb6 193int wxPen::GetJoin() const
83df96d6 194{
74dc5eb6 195 wxCHECK_MSG( Ok(), -1, wxT("invalid pen") );
83df96d6 196
74dc5eb6 197 return M_PENDATA->m_joinStyle;
83df96d6
JS
198}
199
74dc5eb6 200int wxPen::GetStyle() const
83df96d6 201{
74dc5eb6 202 wxCHECK_MSG( Ok(), -1, wxT("invalid pen") );
83df96d6 203
74dc5eb6 204 return M_PENDATA->m_style;
83df96d6
JS
205}
206
74dc5eb6 207int wxPen::GetWidth() const
83df96d6 208{
74dc5eb6 209 wxCHECK_MSG( Ok(), -1, wxT("invalid pen") );
83df96d6 210
74dc5eb6 211 return M_PENDATA->m_width;
83df96d6
JS
212}
213
74dc5eb6 214wxColour &wxPen::GetColour() const
83df96d6 215{
74dc5eb6 216 wxCHECK_MSG( Ok(), wxNullColour, wxT("invalid pen") );
83df96d6 217
74dc5eb6
RR
218 return M_PENDATA->m_colour;
219}
69c44812
MB
220
221wxBitmap *wxPen::GetStipple() const
222{
223 wxCHECK_MSG( Ok(), &wxNullBitmap, wxT("invalid pen") );
224
225 return &M_PENDATA->m_stipple;
226}