Updates to memcheck
[wxWidgets.git] / src / gtk1 / pen.cpp
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
22 class wxPenRefData: public wxObjectRefData
23 {
24 public:
25
26 wxPenRefData(void);
27
28 int m_width;
29 int m_style;
30 int m_joinStyle;
31 int m_capStyle;
32 wxColour m_colour;
33 };
34
35 wxPenRefData::wxPenRefData(void)
36 {
37 m_width = 1;
38 m_style = wxSOLID;
39 m_joinStyle = wxJOIN_ROUND;
40 m_capStyle = wxCAP_ROUND;
41 }
42
43 wxPenRefData::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
52 //-----------------------------------------------------------------------------
53
54 #define M_PENDATA ((wxPenRefData *)m_refData)
55
56 IMPLEMENT_DYNAMIC_CLASS(wxPen,wxGDIObject)
57
58 wxPen::wxPen(void)
59 {
60 if (wxThePenList) wxThePenList->AddPen( this );
61 }
62
63 wxPen::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;
69
70 if (wxThePenList) wxThePenList->AddPen( this );
71 }
72
73 wxPen::wxPen( const wxString &colourName, int width, int style )
74 {
75 m_refData = new wxPenRefData();
76 M_PENDATA->m_width = width;
77 M_PENDATA->m_style = style;
78 M_PENDATA->m_colour = colourName;
79
80 if (wxThePenList) wxThePenList->AddPen( this );
81 }
82
83 wxPen::wxPen( const wxPen& pen )
84 {
85 Ref( pen );
86 if (wxThePenList) wxThePenList->AddPen( this );
87 }
88
89 wxPen::wxPen( const wxPen* pen )
90 {
91 UnRef();
92 if (pen) Ref( *pen );
93
94 if (wxThePenList) wxThePenList->AddPen( this );
95 }
96
97 wxPen::~wxPen(void)
98 {
99 if (wxThePenList) wxThePenList->RemovePen( this );
100 }
101
102 wxPen& wxPen::operator = ( const wxPen& pen )
103 {
104 if (*this == pen) return (*this);
105 Ref( pen );
106 return *this;
107 }
108
109 bool wxPen::operator == ( const wxPen& pen )
110 {
111 return m_refData == pen.m_refData;
112 }
113
114 bool wxPen::operator != ( const wxPen& pen )
115 {
116 return m_refData != pen.m_refData;
117 }
118
119 void wxPen::SetColour( const wxColour &colour )
120 {
121 Unshare();
122 M_PENDATA->m_colour = colour;
123 }
124
125 void wxPen::SetColour( const wxString &colourName )
126 {
127 Unshare();
128 M_PENDATA->m_colour = colourName;
129 }
130
131 void wxPen::SetColour( int red, int green, int blue )
132 {
133 Unshare();
134 M_PENDATA->m_colour.Set( red, green, blue );
135 }
136
137 void wxPen::SetCap( int capStyle )
138 {
139 Unshare();
140 M_PENDATA->m_capStyle = capStyle;
141 }
142
143 void wxPen::SetJoin( int joinStyle )
144 {
145 Unshare();
146 M_PENDATA->m_joinStyle = joinStyle;
147 }
148
149 void wxPen::SetStyle( int style )
150 {
151 Unshare();
152 M_PENDATA->m_style = style;
153 }
154
155 void wxPen::SetWidth( int width )
156 {
157 Unshare();
158 M_PENDATA->m_width = width;
159 }
160
161 int wxPen::GetCap(void) const
162 {
163 if (!m_refData)
164 {
165 wxFAIL_MSG( "invalid pen" );
166 return -1;
167 }
168
169 return M_PENDATA->m_capStyle;
170 }
171
172 int wxPen::GetJoin(void) const
173 {
174 if (!m_refData)
175 {
176 wxFAIL_MSG( "invalid pen" );
177 return -1;
178 }
179
180 return M_PENDATA->m_joinStyle;
181 }
182
183 int wxPen::GetStyle(void) const
184 {
185 if (!m_refData)
186 {
187 wxFAIL_MSG( "invalid pen" );
188 return -1;
189 }
190
191 return M_PENDATA->m_style;
192 }
193
194 int wxPen::GetWidth(void) const
195 {
196 if (!m_refData)
197 {
198 wxFAIL_MSG( "invalid pen" );
199 return -1;
200 }
201
202 return M_PENDATA->m_width;
203 }
204
205 wxColour &wxPen::GetColour(void) const
206 {
207 if (!m_refData)
208 {
209 wxFAIL_MSG( "invalid pen" );
210 return wxNullColour;
211 }
212
213 return M_PENDATA->m_colour;
214 }
215
216 bool wxPen::Ok(void) const
217 {
218 return (m_refData != NULL);
219 }
220
221 void wxPen::Unshare(void)
222 {
223 if (!m_refData)
224 {
225 m_refData = new wxPenRefData();
226 }
227 else
228 {
229 wxPenRefData* ref = new wxPenRefData( *(wxPenRefData*)m_refData );
230 UnRef();
231 m_refData = ref;
232 }
233 }
234