]> git.saurik.com Git - wxWidgets.git/blob - src/gtk/pen.cpp
generate wxEVT_COMMAND_TEXT_ENTER for multiline controls too
[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 #include "wx/colour.h"
15
16 #include <gdk/gdk.h>
17
18 //-----------------------------------------------------------------------------
19 // wxPen
20 //-----------------------------------------------------------------------------
21
22 class wxPenRefData: public wxObjectRefData
23 {
24 public:
25 wxPenRefData()
26 {
27 m_width = 1;
28 m_style = wxSOLID;
29 m_joinStyle = wxJOIN_ROUND;
30 m_capStyle = wxCAP_ROUND;
31 m_dash = (wxGTKDash*) NULL;
32 m_countDashes = 0;
33 }
34
35 wxPenRefData( const wxPenRefData& data )
36 : wxObjectRefData()
37 {
38 m_style = data.m_style;
39 m_width = data.m_width;
40 m_joinStyle = data.m_joinStyle;
41 m_capStyle = data.m_capStyle;
42 m_colour = data.m_colour;
43 m_countDashes = data.m_countDashes;
44 m_dash = data.m_dash;
45 }
46
47 bool operator == (const wxPenRefData& data) const
48 {
49 if ( m_countDashes != data.m_countDashes )
50 return false;
51
52 if ( m_dash )
53 {
54 if ( !data.m_dash ||
55 memcmp(m_dash, data.m_dash, m_countDashes*sizeof(wxGTKDash)) )
56 {
57 return false;
58 }
59 }
60 else if ( data.m_dash )
61 {
62 return false;
63 }
64
65
66 return m_style == data.m_style &&
67 m_width == data.m_width &&
68 m_joinStyle == data.m_joinStyle &&
69 m_capStyle == data.m_capStyle &&
70 m_colour == data.m_colour;
71 }
72
73 int m_width;
74 int m_style;
75 int m_joinStyle;
76 int m_capStyle;
77 wxColour m_colour;
78 int m_countDashes;
79 wxGTKDash *m_dash;
80 };
81
82 //-----------------------------------------------------------------------------
83
84 #define M_PENDATA ((wxPenRefData *)m_refData)
85
86 IMPLEMENT_DYNAMIC_CLASS(wxPen,wxGDIObject)
87
88 wxPen::wxPen( const wxColour &colour, int width, int style )
89 {
90 m_refData = new wxPenRefData();
91 M_PENDATA->m_width = width;
92 M_PENDATA->m_style = style;
93 M_PENDATA->m_colour = colour;
94 }
95
96 wxPen::~wxPen()
97 {
98 // m_refData unrefed in ~wxObject
99 }
100
101 wxObjectRefData *wxPen::CreateRefData() const
102 {
103 return new wxPenRefData;
104 }
105
106 wxObjectRefData *wxPen::CloneRefData(const wxObjectRefData *data) const
107 {
108 return new wxPenRefData(*(wxPenRefData *)data);
109 }
110
111 bool wxPen::operator == ( const wxPen& pen ) const
112 {
113 if (m_refData == pen.m_refData) return true;
114
115 if (!m_refData || !pen.m_refData) return false;
116
117 return ( *(wxPenRefData*)m_refData == *(wxPenRefData*)pen.m_refData );
118 }
119
120 void wxPen::SetColour( const wxColour &colour )
121 {
122 AllocExclusive();
123
124 M_PENDATA->m_colour = colour;
125 }
126
127 void wxPen::SetDashes( int number_of_dashes, const wxDash *dash )
128 {
129 AllocExclusive();
130
131 M_PENDATA->m_countDashes = number_of_dashes;
132 M_PENDATA->m_dash = (wxGTKDash *)dash;
133 }
134
135 void wxPen::SetColour( unsigned char red, unsigned char green, unsigned char blue )
136 {
137 AllocExclusive();
138
139 M_PENDATA->m_colour.Set( red, green, blue );
140 }
141
142 void wxPen::SetCap( int capStyle )
143 {
144 AllocExclusive();
145
146 M_PENDATA->m_capStyle = capStyle;
147 }
148
149 void wxPen::SetJoin( int joinStyle )
150 {
151 AllocExclusive();
152
153 M_PENDATA->m_joinStyle = joinStyle;
154 }
155
156 void wxPen::SetStyle( int style )
157 {
158 AllocExclusive();
159
160 M_PENDATA->m_style = style;
161 }
162
163 void wxPen::SetWidth( int width )
164 {
165 AllocExclusive();
166
167 M_PENDATA->m_width = width;
168 }
169
170 int wxPen::GetDashes( wxDash **ptr ) const
171 {
172 *ptr = (M_PENDATA ? (wxDash*)M_PENDATA->m_dash : (wxDash*) NULL);
173 return (M_PENDATA ? M_PENDATA->m_countDashes : 0);
174 }
175
176 int wxPen::GetDashCount() const
177 {
178 return (M_PENDATA->m_countDashes);
179 }
180
181 wxDash* wxPen::GetDash() const
182 {
183 return (wxDash*)M_PENDATA->m_dash;
184 }
185
186 int wxPen::GetCap() const
187 {
188 wxCHECK_MSG( Ok(), -1, wxT("invalid pen") );
189
190 return M_PENDATA->m_capStyle;
191 }
192
193 int wxPen::GetJoin() const
194 {
195 wxCHECK_MSG( Ok(), -1, wxT("invalid pen") );
196
197 return M_PENDATA->m_joinStyle;
198 }
199
200 int wxPen::GetStyle() const
201 {
202 wxCHECK_MSG( Ok(), -1, wxT("invalid pen") );
203
204 return M_PENDATA->m_style;
205 }
206
207 int wxPen::GetWidth() const
208 {
209 wxCHECK_MSG( Ok(), -1, wxT("invalid pen") );
210
211 return M_PENDATA->m_width;
212 }
213
214 wxColour &wxPen::GetColour() const
215 {
216 wxCHECK_MSG( Ok(), wxNullColour, wxT("invalid pen") );
217
218 return M_PENDATA->m_colour;
219 }