]> git.saurik.com Git - wxWidgets.git/blob - src/gtk1/pen.cpp
added wxTextEntry::AutoComplete() and implemented it for wxGTK
[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 wxObjectRefData
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 : wxObjectRefData()
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 int m_style;
78 int m_joinStyle;
79 int 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, int 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()
100 {
101 // m_refData unrefed in ~wxObject
102 }
103
104 wxObjectRefData *wxPen::CreateRefData() const
105 {
106 return new wxPenRefData;
107 }
108
109 wxObjectRefData *wxPen::CloneRefData(const wxObjectRefData *data) const
110 {
111 return new wxPenRefData(*(wxPenRefData *)data);
112 }
113
114 bool wxPen::operator == ( const wxPen& pen ) const
115 {
116 if (m_refData == pen.m_refData) return true;
117
118 if (!m_refData || !pen.m_refData) return false;
119
120 return ( *(wxPenRefData*)m_refData == *(wxPenRefData*)pen.m_refData );
121 }
122
123 void wxPen::SetColour( const wxColour &colour )
124 {
125 AllocExclusive();
126
127 M_PENDATA->m_colour = colour;
128 }
129
130 void wxPen::SetDashes( int number_of_dashes, const wxDash *dash )
131 {
132 AllocExclusive();
133
134 M_PENDATA->m_countDashes = number_of_dashes;
135 M_PENDATA->m_dash = (wxGTKDash *)dash;
136 }
137
138 void wxPen::SetColour( unsigned char red, unsigned char green, unsigned char blue )
139 {
140 AllocExclusive();
141
142 M_PENDATA->m_colour.Set( red, green, blue );
143 }
144
145 void wxPen::SetCap( int capStyle )
146 {
147 AllocExclusive();
148
149 M_PENDATA->m_capStyle = capStyle;
150 }
151
152 void wxPen::SetJoin( int joinStyle )
153 {
154 AllocExclusive();
155
156 M_PENDATA->m_joinStyle = joinStyle;
157 }
158
159 void wxPen::SetStyle( int style )
160 {
161 AllocExclusive();
162
163 M_PENDATA->m_style = style;
164 }
165
166 void wxPen::SetWidth( int width )
167 {
168 AllocExclusive();
169
170 M_PENDATA->m_width = width;
171 }
172
173 int wxPen::GetDashes( wxDash **ptr ) const
174 {
175 *ptr = (M_PENDATA ? (wxDash*)M_PENDATA->m_dash : (wxDash*) NULL);
176 return (M_PENDATA ? M_PENDATA->m_countDashes : 0);
177 }
178
179 int wxPen::GetDashCount() const
180 {
181 return (M_PENDATA->m_countDashes);
182 }
183
184 wxDash* wxPen::GetDash() const
185 {
186 return (wxDash*)M_PENDATA->m_dash;
187 }
188
189 int wxPen::GetCap() const
190 {
191 wxCHECK_MSG( Ok(), -1, wxT("invalid pen") );
192
193 return M_PENDATA->m_capStyle;
194 }
195
196 int wxPen::GetJoin() const
197 {
198 wxCHECK_MSG( Ok(), -1, wxT("invalid pen") );
199
200 return M_PENDATA->m_joinStyle;
201 }
202
203 int wxPen::GetStyle() const
204 {
205 wxCHECK_MSG( Ok(), -1, wxT("invalid pen") );
206
207 return M_PENDATA->m_style;
208 }
209
210 int wxPen::GetWidth() const
211 {
212 wxCHECK_MSG( Ok(), -1, wxT("invalid pen") );
213
214 return M_PENDATA->m_width;
215 }
216
217 wxColour &wxPen::GetColour() const
218 {
219 wxCHECK_MSG( Ok(), wxNullColour, wxT("invalid pen") );
220
221 return M_PENDATA->m_colour;
222 }