]> git.saurik.com Git - wxWidgets.git/blame - src/gtk/pen.cpp
wxSize/wxPoint/wxRect versions of functions added to wxMSW, wxMotif;
[wxWidgets.git] / src / gtk / pen.cpp
CommitLineData
c801d85f
KB
1/////////////////////////////////////////////////////////////////////////////
2// Name: pen.cpp
3// Purpose:
4// Author: Robert Roebling
a81258be
RR
5// Id: $Id$
6// Copyright: (c) 1998 Robert Roebling
c801d85f
KB
7// Licence: wxWindows licence
8/////////////////////////////////////////////////////////////////////////////
9
10
11#ifdef __GNUG__
12#pragma implementation "pen.h"
13#endif
14
15#include "wx/pen.h"
16
17//-----------------------------------------------------------------------------
18// wxPen
19//-----------------------------------------------------------------------------
20
21class wxPenRefData: public wxObjectRefData
22{
23 public:
24
25 wxPenRefData(void);
335a8b43 26 wxPenRefData(const wxPenRefData& data);
c801d85f
KB
27
28 int m_width;
29 int m_style;
30 int m_joinStyle;
31 int m_capStyle;
32 wxColour m_colour;
33};
34
35wxPenRefData::wxPenRefData(void)
36{
37 m_width = 1;
38 m_style = wxSOLID;
39 m_joinStyle = wxJOIN_ROUND;
40 m_capStyle = wxCAP_ROUND;
ff7b1510 41}
c801d85f 42
e55ad60e
RR
43wxPenRefData::wxPenRefData( const wxPenRefData& data )
44{
45 m_style = data.m_style;
46 m_width = data.m_width;
47 m_joinStyle = data.m_joinStyle;
48 m_capStyle = data.m_capStyle;
49 m_colour = data.m_colour;
50}
51
c801d85f
KB
52//-----------------------------------------------------------------------------
53
54#define M_PENDATA ((wxPenRefData *)m_refData)
55
56IMPLEMENT_DYNAMIC_CLASS(wxPen,wxGDIObject)
57
58wxPen::wxPen(void)
59{
60 if (wxThePenList) wxThePenList->AddPen( this );
ff7b1510 61}
c801d85f
KB
62
63wxPen::wxPen( const wxColour &colour, int width, int style )
64{
65 m_refData = new wxPenRefData();
66 M_PENDATA->m_width = width;
67 M_PENDATA->m_style = style;
68 M_PENDATA->m_colour = colour;
52cbfcf0 69
c801d85f 70 if (wxThePenList) wxThePenList->AddPen( this );
ff7b1510 71}
c801d85f 72
c801d85f
KB
73wxPen::wxPen( const wxPen& pen )
74{
75 Ref( pen );
76 if (wxThePenList) wxThePenList->AddPen( this );
ff7b1510 77}
c801d85f
KB
78
79wxPen::wxPen( const wxPen* pen )
80{
81 UnRef();
82 if (pen) Ref( *pen );
52cbfcf0 83
c801d85f 84 if (wxThePenList) wxThePenList->AddPen( this );
ff7b1510 85}
c801d85f
KB
86
87wxPen::~wxPen(void)
88{
89 if (wxThePenList) wxThePenList->RemovePen( this );
ff7b1510 90}
c801d85f
KB
91
92wxPen& wxPen::operator = ( const wxPen& pen )
93{
94 if (*this == pen) return (*this);
95 Ref( pen );
96 return *this;
ff7b1510 97}
c801d85f
KB
98
99bool wxPen::operator == ( const wxPen& pen )
100{
101 return m_refData == pen.m_refData;
ff7b1510 102}
c801d85f
KB
103
104bool wxPen::operator != ( const wxPen& pen )
105{
106 return m_refData != pen.m_refData;
ff7b1510 107}
c801d85f
KB
108
109void wxPen::SetColour( const wxColour &colour )
110{
e55ad60e 111 Unshare();
c801d85f 112 M_PENDATA->m_colour = colour;
ff7b1510 113}
c801d85f 114
debe6624 115void wxPen::SetColour( int red, int green, int blue )
c801d85f 116{
e55ad60e 117 Unshare();
c801d85f 118 M_PENDATA->m_colour.Set( red, green, blue );
ff7b1510 119}
c801d85f
KB
120
121void wxPen::SetCap( int capStyle )
122{
e55ad60e 123 Unshare();
c801d85f 124 M_PENDATA->m_capStyle = capStyle;
ff7b1510 125}
c801d85f
KB
126
127void wxPen::SetJoin( int joinStyle )
128{
e55ad60e 129 Unshare();
c801d85f 130 M_PENDATA->m_joinStyle = joinStyle;
ff7b1510 131}
c801d85f
KB
132
133void wxPen::SetStyle( int style )
134{
e55ad60e 135 Unshare();
c801d85f 136 M_PENDATA->m_style = style;
ff7b1510 137}
c801d85f
KB
138
139void wxPen::SetWidth( int width )
140{
e55ad60e 141 Unshare();
c801d85f 142 M_PENDATA->m_width = width;
ff7b1510 143}
c801d85f
KB
144
145int wxPen::GetCap(void) const
146{
e55ad60e
RR
147 if (!m_refData)
148 {
149 wxFAIL_MSG( "invalid pen" );
150 return -1;
151 }
152
c801d85f 153 return M_PENDATA->m_capStyle;
ff7b1510 154}
c801d85f
KB
155
156int wxPen::GetJoin(void) const
157{
158 if (!m_refData)
e55ad60e
RR
159 {
160 wxFAIL_MSG( "invalid pen" );
161 return -1;
162 }
163
164 return M_PENDATA->m_joinStyle;
ff7b1510 165}
c801d85f
KB
166
167int wxPen::GetStyle(void) const
168{
169 if (!m_refData)
e55ad60e
RR
170 {
171 wxFAIL_MSG( "invalid pen" );
172 return -1;
173 }
174
175 return M_PENDATA->m_style;
ff7b1510 176}
c801d85f
KB
177
178int wxPen::GetWidth(void) const
179{
180 if (!m_refData)
e55ad60e
RR
181 {
182 wxFAIL_MSG( "invalid pen" );
183 return -1;
184 }
185
186 return M_PENDATA->m_width;
ff7b1510 187}
c801d85f
KB
188
189wxColour &wxPen::GetColour(void) const
190{
191 if (!m_refData)
e55ad60e
RR
192 {
193 wxFAIL_MSG( "invalid pen" );
c801d85f 194 return wxNullColour;
e55ad60e
RR
195 }
196
197 return M_PENDATA->m_colour;
ff7b1510 198}
c801d85f
KB
199
200bool wxPen::Ok(void) const
201{
e55ad60e
RR
202 return (m_refData != NULL);
203}
204
205void wxPen::Unshare(void)
206{
207 if (!m_refData)
208 {
209 m_refData = new wxPenRefData();
210 }
211 else
212 {
213 wxPenRefData* ref = new wxPenRefData( *(wxPenRefData*)m_refData );
214 UnRef();
215 m_refData = ref;
216 }
ff7b1510 217}
c801d85f 218