]> git.saurik.com Git - wxWidgets.git/blob - src/gtk1/pen.cpp
wxDC scaling fix patch (Derry Bryson)
[wxWidgets.git] / src / gtk1 / 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 if (wxThePenList) wxThePenList->AddPen( this );
73 }
74
75 wxPen::wxPen( const wxColour &colour, int width, int style )
76 {
77 m_refData = new wxPenRefData();
78 M_PENDATA->m_width = width;
79 M_PENDATA->m_style = style;
80 M_PENDATA->m_colour = colour;
81
82 if (wxThePenList) wxThePenList->AddPen( this );
83 }
84
85 wxPen::wxPen( const wxPen& pen )
86 {
87 Ref( pen );
88 if (wxThePenList) wxThePenList->AddPen( this );
89 }
90
91 wxPen::~wxPen()
92 {
93 if (wxThePenList) wxThePenList->RemovePen( this );
94 }
95
96 wxPen& wxPen::operator = ( const wxPen& pen )
97 {
98 if (*this == pen) return (*this);
99 Ref( pen );
100 return *this;
101 }
102
103 bool wxPen::operator == ( const wxPen& pen ) const
104 {
105 return m_refData == pen.m_refData;
106 }
107
108 bool wxPen::operator != ( const wxPen& pen ) const
109 {
110 return m_refData != pen.m_refData;
111 }
112
113 void wxPen::SetColour( const wxColour &colour )
114 {
115 Unshare();
116 M_PENDATA->m_colour = colour;
117 }
118
119 void wxPen::SetDashes( int number_of_dashes, const wxDash *dash )
120 {
121 Unshare();
122 M_PENDATA->m_countDashes = number_of_dashes;
123 M_PENDATA->m_dash = (wxGTKDash *)dash; /* TODO */
124 }
125
126 void wxPen::SetColour( int red, int green, int blue )
127 {
128 Unshare();
129 M_PENDATA->m_colour.Set( red, green, blue );
130 }
131
132 void wxPen::SetCap( int capStyle )
133 {
134 Unshare();
135 M_PENDATA->m_capStyle = capStyle;
136 }
137
138 void wxPen::SetJoin( int joinStyle )
139 {
140 Unshare();
141 M_PENDATA->m_joinStyle = joinStyle;
142 }
143
144 void wxPen::SetStyle( int style )
145 {
146 Unshare();
147 M_PENDATA->m_style = style;
148 }
149
150 void wxPen::SetWidth( int width )
151 {
152 Unshare();
153 M_PENDATA->m_width = width;
154 }
155
156 int wxPen::GetDashes( wxDash **ptr ) const
157 {
158 *ptr = (M_PENDATA ? (wxDash*)M_PENDATA->m_dash : (wxDash*) NULL);
159 return (M_PENDATA ? M_PENDATA->m_countDashes : 0);
160 }
161
162 int wxPen::GetDashCount() const
163 {
164 return (M_PENDATA->m_countDashes);
165 }
166
167 wxDash* wxPen::GetDash() const
168 {
169 return (wxDash*)M_PENDATA->m_dash;
170 }
171
172 int wxPen::GetCap() const
173 {
174 wxCHECK_MSG( Ok(), -1, wxT("invalid pen") );
175
176 return M_PENDATA->m_capStyle;
177 }
178
179 int wxPen::GetJoin() const
180 {
181 wxCHECK_MSG( Ok(), -1, wxT("invalid pen") );
182
183 return M_PENDATA->m_joinStyle;
184 }
185
186 int wxPen::GetStyle() const
187 {
188 wxCHECK_MSG( Ok(), -1, wxT("invalid pen") );
189
190 return M_PENDATA->m_style;
191 }
192
193 int wxPen::GetWidth() const
194 {
195 wxCHECK_MSG( Ok(), -1, wxT("invalid pen") );
196
197 return M_PENDATA->m_width;
198 }
199
200 wxColour &wxPen::GetColour() const
201 {
202 wxCHECK_MSG( Ok(), wxNullColour, wxT("invalid pen") );
203
204 return M_PENDATA->m_colour;
205 }
206
207 bool wxPen::Ok() const
208 {
209 return (m_refData != NULL);
210 }
211
212 void wxPen::Unshare()
213 {
214 if (!m_refData)
215 {
216 m_refData = new wxPenRefData();
217 }
218 else
219 {
220 wxPenRefData* ref = new wxPenRefData( *(wxPenRefData*)m_refData );
221 UnRef();
222 m_refData = ref;
223 }
224 }
225