]> git.saurik.com Git - wxWidgets.git/blob - src/gtk/pen.cpp
Fix bug in Unix wxFileSystemWatcher implementation when watch is deleted.
[wxWidgets.git] / src / gtk / pen.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/gtk/pen.cpp
3 // Purpose:
4 // Author: Robert Roebling
5 // Id: $Id$
6 // Copyright: (c) 1998 Robert Roebling
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
9
10 // For compilers that support precompilation, includes "wx.h".
11 #include "wx/wxprec.h"
12
13 #include "wx/pen.h"
14
15 #ifndef WX_PRECOMP
16 #include "wx/colour.h"
17 #endif
18
19 #include <gdk/gdk.h>
20
21 //-----------------------------------------------------------------------------
22 // wxPen
23 //-----------------------------------------------------------------------------
24
25 class wxPenRefData: public wxGDIRefData
26 {
27 public:
28 wxPenRefData()
29 {
30 m_width = 1;
31 m_style = wxPENSTYLE_SOLID;
32 m_joinStyle = wxJOIN_ROUND;
33 m_capStyle = wxCAP_ROUND;
34 m_dash = NULL;
35 m_countDashes = 0;
36 }
37
38 wxPenRefData( const wxPenRefData& data )
39 : wxGDIRefData()
40 {
41 m_style = data.m_style;
42 m_width = data.m_width;
43 m_joinStyle = data.m_joinStyle;
44 m_capStyle = data.m_capStyle;
45 m_colour = data.m_colour;
46 m_countDashes = data.m_countDashes;
47 m_dash = data.m_dash;
48 }
49
50 bool operator == (const wxPenRefData& data) const
51 {
52 if ( m_countDashes != data.m_countDashes )
53 return false;
54
55 if ( m_dash )
56 {
57 if ( !data.m_dash ||
58 memcmp(m_dash, data.m_dash, m_countDashes*sizeof(wxGTKDash)) )
59 {
60 return false;
61 }
62 }
63 else if ( data.m_dash )
64 {
65 return false;
66 }
67
68
69 return m_style == data.m_style &&
70 m_width == data.m_width &&
71 m_joinStyle == data.m_joinStyle &&
72 m_capStyle == data.m_capStyle &&
73 m_colour == data.m_colour;
74 }
75
76 int m_width;
77 wxPenStyle m_style;
78 wxPenJoin m_joinStyle;
79 wxPenCap m_capStyle;
80 wxColour m_colour;
81 int m_countDashes;
82 wxGTKDash *m_dash;
83 };
84
85 //-----------------------------------------------------------------------------
86
87 #define M_PENDATA ((wxPenRefData *)m_refData)
88
89 IMPLEMENT_DYNAMIC_CLASS(wxPen,wxGDIObject)
90
91 wxPen::wxPen( const wxColour &colour, int width, wxPenStyle style )
92 {
93 m_refData = new wxPenRefData();
94 M_PENDATA->m_width = width;
95 M_PENDATA->m_style = style;
96 M_PENDATA->m_colour = colour;
97 }
98
99 #if FUTURE_WXWIN_COMPATIBILITY_3_0
100 wxPen::wxPen(const wxColour& colour, int width, int style)
101 {
102 m_refData = new wxPenRefData();
103 M_PENDATA->m_width = width;
104 M_PENDATA->m_style = (wxPenStyle)style;
105 M_PENDATA->m_colour = colour;
106 }
107 #endif
108
109 wxPen::~wxPen()
110 {
111 // m_refData unrefed in ~wxObject
112 }
113
114 wxGDIRefData *wxPen::CreateGDIRefData() const
115 {
116 return new wxPenRefData;
117 }
118
119 wxGDIRefData *wxPen::CloneGDIRefData(const wxGDIRefData *data) const
120 {
121 return new wxPenRefData(*(wxPenRefData *)data);
122 }
123
124 bool wxPen::operator == ( const wxPen& pen ) const
125 {
126 if (m_refData == pen.m_refData) return true;
127
128 if (!m_refData || !pen.m_refData) return false;
129
130 return ( *(wxPenRefData*)m_refData == *(wxPenRefData*)pen.m_refData );
131 }
132
133 void wxPen::SetColour( const wxColour &colour )
134 {
135 AllocExclusive();
136
137 M_PENDATA->m_colour = colour;
138 }
139
140 void wxPen::SetDashes( int number_of_dashes, const wxDash *dash )
141 {
142 AllocExclusive();
143
144 M_PENDATA->m_countDashes = number_of_dashes;
145 M_PENDATA->m_dash = (wxGTKDash *)dash;
146 }
147
148 void wxPen::SetColour( unsigned char red, unsigned char green, unsigned char blue )
149 {
150 AllocExclusive();
151
152 M_PENDATA->m_colour.Set( red, green, blue );
153 }
154
155 void wxPen::SetCap( wxPenCap capStyle )
156 {
157 AllocExclusive();
158
159 M_PENDATA->m_capStyle = capStyle;
160 }
161
162 void wxPen::SetJoin( wxPenJoin joinStyle )
163 {
164 AllocExclusive();
165
166 M_PENDATA->m_joinStyle = joinStyle;
167 }
168
169 void wxPen::SetStyle( wxPenStyle style )
170 {
171 AllocExclusive();
172
173 M_PENDATA->m_style = style;
174 }
175
176 void wxPen::SetWidth( int width )
177 {
178 AllocExclusive();
179
180 M_PENDATA->m_width = width;
181 }
182
183 int wxPen::GetDashes( wxDash **ptr ) const
184 {
185 wxCHECK_MSG( IsOk(), -1, wxT("invalid pen") );
186
187 *ptr = (wxDash*)M_PENDATA->m_dash;
188 return M_PENDATA->m_countDashes;
189 }
190
191 int wxPen::GetDashCount() const
192 {
193 wxCHECK_MSG( IsOk(), -1, wxT("invalid pen") );
194
195 return (M_PENDATA->m_countDashes);
196 }
197
198 wxDash* wxPen::GetDash() const
199 {
200 wxCHECK_MSG( IsOk(), NULL, wxT("invalid pen") );
201
202 return (wxDash*)M_PENDATA->m_dash;
203 }
204
205 wxPenCap wxPen::GetCap() const
206 {
207 wxCHECK_MSG( IsOk(), wxCAP_INVALID, wxT("invalid pen") );
208
209 return M_PENDATA->m_capStyle;
210 }
211
212 wxPenJoin wxPen::GetJoin() const
213 {
214 wxCHECK_MSG( IsOk(), wxJOIN_INVALID, wxT("invalid pen") );
215
216 return M_PENDATA->m_joinStyle;
217 }
218
219 wxPenStyle wxPen::GetStyle() const
220 {
221 wxCHECK_MSG( IsOk(), wxPENSTYLE_INVALID, wxT("invalid pen") );
222
223 return M_PENDATA->m_style;
224 }
225
226 int wxPen::GetWidth() const
227 {
228 wxCHECK_MSG( IsOk(), -1, wxT("invalid pen") );
229
230 return M_PENDATA->m_width;
231 }
232
233 wxColour wxPen::GetColour() const
234 {
235 wxCHECK_MSG( IsOk(), wxNullColour, wxT("invalid pen") );
236
237 return M_PENDATA->m_colour;
238 }
239
240 // stippled pens are not supported by wxGTK
241 void wxPen::SetStipple(const wxBitmap& WXUNUSED(stipple))
242 {
243 wxFAIL_MSG( "stippled pens not supported" );
244 }
245
246 wxBitmap *wxPen::GetStipple() const
247 {
248 return NULL;
249 }
250