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