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