]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/gtk1/pen.cpp
Fix memory leak when a spacer is added, and crash when a window is added before wxSiz...
[wxWidgets.git] / src / gtk1 / pen.cpp
... / ...
CommitLineData
1/////////////////////////////////////////////////////////////////////////////
2// Name: pen.cpp
3// Purpose:
4// Author: Robert Roebling
5// Id: $Id$
6// Copyright: (c) 1998 Robert Roebling
7// Licence: wxWindows licence
8/////////////////////////////////////////////////////////////////////////////
9
10
11#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
12#pragma implementation "pen.h"
13#endif
14
15// For compilers that support precompilation, includes "wx.h".
16#include "wx/wxprec.h"
17
18#include "wx/pen.h"
19#include "wx/colour.h"
20
21#include <gdk/gdk.h>
22
23//-----------------------------------------------------------------------------
24// wxPen
25//-----------------------------------------------------------------------------
26
27class wxPenRefData: public wxObjectRefData
28{
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 = (wxGTKDash*) NULL;
37 m_countDashes = 0;
38 }
39
40 wxPenRefData( const wxPenRefData& data )
41 : wxObjectRefData()
42 {
43 m_style = data.m_style;
44 m_width = data.m_width;
45 m_joinStyle = data.m_joinStyle;
46 m_capStyle = data.m_capStyle;
47 m_colour = data.m_colour;
48 m_countDashes = data.m_countDashes;
49 m_dash = data.m_dash;
50 }
51
52 bool operator == (const wxPenRefData& data) const
53 {
54 if ( m_countDashes != data.m_countDashes )
55 return FALSE;
56
57 if ( m_dash )
58 {
59 if ( !data.m_dash ||
60 memcmp(m_dash, data.m_dash, m_countDashes*sizeof(wxGTKDash)) )
61 {
62 return FALSE;
63 }
64 }
65 else if ( data.m_dash )
66 {
67 return FALSE;
68 }
69
70
71 return m_style == data.m_style &&
72 m_width == data.m_width &&
73 m_joinStyle == data.m_joinStyle &&
74 m_capStyle == data.m_capStyle &&
75 m_colour == data.m_colour;
76 }
77
78 int m_width;
79 int m_style;
80 int m_joinStyle;
81 int m_capStyle;
82 wxColour m_colour;
83 int m_countDashes;
84 wxGTKDash *m_dash;
85};
86
87//-----------------------------------------------------------------------------
88
89#define M_PENDATA ((wxPenRefData *)m_refData)
90
91IMPLEMENT_DYNAMIC_CLASS(wxPen,wxGDIObject)
92
93wxPen::wxPen( const wxColour &colour, int width, int style )
94{
95 m_refData = new wxPenRefData();
96 M_PENDATA->m_width = width;
97 M_PENDATA->m_style = style;
98 M_PENDATA->m_colour = colour;
99}
100
101wxPen::~wxPen()
102{
103 // m_refData unrefed in ~wxObject
104}
105
106wxObjectRefData *wxPen::CreateRefData() const
107{
108 return new wxPenRefData;
109}
110
111wxObjectRefData *wxPen::CloneRefData(const wxObjectRefData *data) const
112{
113 return new wxPenRefData(*(wxPenRefData *)data);
114}
115
116bool wxPen::operator == ( const wxPen& pen ) const
117{
118 if (m_refData == pen.m_refData) return TRUE;
119
120 if (!m_refData || !pen.m_refData) return FALSE;
121
122 return ( *(wxPenRefData*)m_refData == *(wxPenRefData*)pen.m_refData );
123}
124
125void wxPen::SetColour( const wxColour &colour )
126{
127 AllocExclusive();
128
129 M_PENDATA->m_colour = colour;
130}
131
132void wxPen::SetDashes( int number_of_dashes, const wxDash *dash )
133{
134 AllocExclusive();
135
136 M_PENDATA->m_countDashes = number_of_dashes;
137 M_PENDATA->m_dash = (wxGTKDash *)dash;
138}
139
140void wxPen::SetColour( int red, int green, int blue )
141{
142 AllocExclusive();
143
144 M_PENDATA->m_colour.Set( red, green, blue );
145}
146
147void wxPen::SetCap( int capStyle )
148{
149 AllocExclusive();
150
151 M_PENDATA->m_capStyle = capStyle;
152}
153
154void wxPen::SetJoin( int joinStyle )
155{
156 AllocExclusive();
157
158 M_PENDATA->m_joinStyle = joinStyle;
159}
160
161void wxPen::SetStyle( int style )
162{
163 AllocExclusive();
164
165 M_PENDATA->m_style = style;
166}
167
168void wxPen::SetWidth( int width )
169{
170 AllocExclusive();
171
172 M_PENDATA->m_width = width;
173}
174
175int wxPen::GetDashes( wxDash **ptr ) const
176{
177 *ptr = (M_PENDATA ? (wxDash*)M_PENDATA->m_dash : (wxDash*) NULL);
178 return (M_PENDATA ? M_PENDATA->m_countDashes : 0);
179}
180
181int wxPen::GetDashCount() const
182{
183 return (M_PENDATA->m_countDashes);
184}
185
186wxDash* wxPen::GetDash() const
187{
188 return (wxDash*)M_PENDATA->m_dash;
189}
190
191int wxPen::GetCap() const
192{
193 wxCHECK_MSG( Ok(), -1, wxT("invalid pen") );
194
195 return M_PENDATA->m_capStyle;
196}
197
198int wxPen::GetJoin() const
199{
200 wxCHECK_MSG( Ok(), -1, wxT("invalid pen") );
201
202 return M_PENDATA->m_joinStyle;
203}
204
205int wxPen::GetStyle() const
206{
207 wxCHECK_MSG( Ok(), -1, wxT("invalid pen") );
208
209 return M_PENDATA->m_style;
210}
211
212int wxPen::GetWidth() const
213{
214 wxCHECK_MSG( Ok(), -1, wxT("invalid pen") );
215
216 return M_PENDATA->m_width;
217}
218
219wxColour &wxPen::GetColour() const
220{
221 wxCHECK_MSG( Ok(), wxNullColour, wxT("invalid pen") );
222
223 return M_PENDATA->m_colour;
224}
225