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