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