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