fix also wxPen to use wxPenStyle,wxPenJoin,wxPenCap enums instead of plain int; remov...
[wxWidgets.git] / src / gtk1 / pen.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/gtk1/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 = wxSOLID;
32 m_joinStyle = wxJOIN_ROUND;
33 m_capStyle = wxCAP_ROUND;
34 m_dash = (wxGTKDash*) 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 wxPen::wxPen(const wxColour& colour, int width, wxBrushStyle 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
107 wxPen::~wxPen()
108 {
109 // m_refData unrefed in ~wxObject
110 }
111
112 wxGDIRefData *wxPen::CreateGDIRefData() const
113 {
114 return new wxPenRefData;
115 }
116
117 wxGDIRefData *wxPen::CloneGDIRefData(const wxGDIRefData *data) const
118 {
119 return new wxPenRefData(*(wxPenRefData *)data);
120 }
121
122 bool wxPen::operator == ( const wxPen& pen ) const
123 {
124 if (m_refData == pen.m_refData) return true;
125
126 if (!m_refData || !pen.m_refData) return false;
127
128 return ( *(wxPenRefData*)m_refData == *(wxPenRefData*)pen.m_refData );
129 }
130
131 void wxPen::SetColour( const wxColour &colour )
132 {
133 AllocExclusive();
134
135 M_PENDATA->m_colour = colour;
136 }
137
138 void wxPen::SetDashes( int number_of_dashes, const wxDash *dash )
139 {
140 AllocExclusive();
141
142 M_PENDATA->m_countDashes = number_of_dashes;
143 M_PENDATA->m_dash = (wxGTKDash *)dash;
144 }
145
146 void wxPen::SetColour( unsigned char red, unsigned char green, unsigned char blue )
147 {
148 AllocExclusive();
149
150 M_PENDATA->m_colour.Set( red, green, blue );
151 }
152
153 void wxPen::SetCap( wxPenCap capStyle )
154 {
155 AllocExclusive();
156
157 M_PENDATA->m_capStyle = capStyle;
158 }
159
160 void wxPen::SetJoin( wxPenJoin joinStyle )
161 {
162 AllocExclusive();
163
164 M_PENDATA->m_joinStyle = joinStyle;
165 }
166
167 void wxPen::SetStyle( wxPenStyle style )
168 {
169 AllocExclusive();
170
171 M_PENDATA->m_style = style;
172 }
173
174 void wxPen::SetWidth( int width )
175 {
176 AllocExclusive();
177
178 M_PENDATA->m_width = width;
179 }
180
181 int wxPen::GetDashes( wxDash **ptr ) const
182 {
183 *ptr = (M_PENDATA ? (wxDash*)M_PENDATA->m_dash : (wxDash*) NULL);
184 return (M_PENDATA ? M_PENDATA->m_countDashes : 0);
185 }
186
187 int wxPen::GetDashCount() const
188 {
189 return (M_PENDATA->m_countDashes);
190 }
191
192 wxDash* wxPen::GetDash() const
193 {
194 return (wxDash*)M_PENDATA->m_dash;
195 }
196
197 wxPenCap wxPen::GetCap() const
198 {
199 wxCHECK_MSG( Ok(), -1, wxT("invalid pen") );
200
201 return M_PENDATA->m_capStyle;
202 }
203
204 wxPenJoin wxPen::GetJoin() const
205 {
206 wxCHECK_MSG( Ok(), -1, wxT("invalid pen") );
207
208 return M_PENDATA->m_joinStyle;
209 }
210
211 wxPenStyle wxPen::GetStyle() const
212 {
213 wxCHECK_MSG( Ok(), -1, wxT("invalid pen") );
214
215 return M_PENDATA->m_style;
216 }
217
218 int wxPen::GetWidth() const
219 {
220 wxCHECK_MSG( Ok(), -1, wxT("invalid pen") );
221
222 return M_PENDATA->m_width;
223 }
224
225 wxColour &wxPen::GetColour() const
226 {
227 wxCHECK_MSG( Ok(), wxNullColour, wxT("invalid pen") );
228
229 return M_PENDATA->m_colour;
230 }