]> git.saurik.com Git - wxWidgets.git/blob - src/gtk1/pen.cpp
Fixed Dialog Editor compilation and window sizing bug. Various warning-related
[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 //-----------------------------------------------------------------------------
18 // wxPen
19 //-----------------------------------------------------------------------------
20
21 class wxPenRefData: public wxObjectRefData
22 {
23 public:
24
25 wxPenRefData(void);
26 wxPenRefData(const wxPenRefData& data);
27
28 int m_width;
29 int m_style;
30 int m_joinStyle;
31 int m_capStyle;
32 wxColour m_colour;
33 };
34
35 wxPenRefData::wxPenRefData(void)
36 {
37 m_width = 1;
38 m_style = wxSOLID;
39 m_joinStyle = wxJOIN_ROUND;
40 m_capStyle = wxCAP_ROUND;
41 }
42
43 wxPenRefData::wxPenRefData( const wxPenRefData& data )
44 {
45 m_style = data.m_style;
46 m_width = data.m_width;
47 m_joinStyle = data.m_joinStyle;
48 m_capStyle = data.m_capStyle;
49 m_colour = data.m_colour;
50 }
51
52 //-----------------------------------------------------------------------------
53
54 #define M_PENDATA ((wxPenRefData *)m_refData)
55
56 IMPLEMENT_DYNAMIC_CLASS(wxPen,wxGDIObject)
57
58 wxPen::wxPen(void)
59 {
60 if (wxThePenList) wxThePenList->AddPen( this );
61 }
62
63 wxPen::wxPen( const wxColour &colour, int width, int style )
64 {
65 m_refData = new wxPenRefData();
66 M_PENDATA->m_width = width;
67 M_PENDATA->m_style = style;
68 M_PENDATA->m_colour = colour;
69
70 if (wxThePenList) wxThePenList->AddPen( this );
71 }
72
73 wxPen::wxPen( const wxPen& pen )
74 {
75 Ref( pen );
76 if (wxThePenList) wxThePenList->AddPen( this );
77 }
78
79 wxPen::wxPen( const wxPen* pen )
80 {
81 UnRef();
82 if (pen) Ref( *pen );
83
84 if (wxThePenList) wxThePenList->AddPen( this );
85 }
86
87 wxPen::~wxPen(void)
88 {
89 if (wxThePenList) wxThePenList->RemovePen( this );
90 }
91
92 wxPen& wxPen::operator = ( const wxPen& pen )
93 {
94 if (*this == pen) return (*this);
95 Ref( pen );
96 return *this;
97 }
98
99 bool wxPen::operator == ( const wxPen& pen )
100 {
101 return m_refData == pen.m_refData;
102 }
103
104 bool wxPen::operator != ( const wxPen& pen )
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::SetColour( int red, int green, int blue )
116 {
117 Unshare();
118 M_PENDATA->m_colour.Set( red, green, blue );
119 }
120
121 void wxPen::SetCap( int capStyle )
122 {
123 Unshare();
124 M_PENDATA->m_capStyle = capStyle;
125 }
126
127 void wxPen::SetJoin( int joinStyle )
128 {
129 Unshare();
130 M_PENDATA->m_joinStyle = joinStyle;
131 }
132
133 void wxPen::SetStyle( int style )
134 {
135 Unshare();
136 M_PENDATA->m_style = style;
137 }
138
139 void wxPen::SetWidth( int width )
140 {
141 Unshare();
142 M_PENDATA->m_width = width;
143 }
144
145 int wxPen::GetCap(void) const
146 {
147 if (!m_refData)
148 {
149 wxFAIL_MSG( "invalid pen" );
150 return -1;
151 }
152
153 return M_PENDATA->m_capStyle;
154 }
155
156 int wxPen::GetJoin(void) const
157 {
158 if (!m_refData)
159 {
160 wxFAIL_MSG( "invalid pen" );
161 return -1;
162 }
163
164 return M_PENDATA->m_joinStyle;
165 }
166
167 int wxPen::GetStyle(void) const
168 {
169 if (!m_refData)
170 {
171 wxFAIL_MSG( "invalid pen" );
172 return -1;
173 }
174
175 return M_PENDATA->m_style;
176 }
177
178 int wxPen::GetWidth(void) const
179 {
180 if (!m_refData)
181 {
182 wxFAIL_MSG( "invalid pen" );
183 return -1;
184 }
185
186 return M_PENDATA->m_width;
187 }
188
189 wxColour &wxPen::GetColour(void) const
190 {
191 if (!m_refData)
192 {
193 wxFAIL_MSG( "invalid pen" );
194 return wxNullColour;
195 }
196
197 return M_PENDATA->m_colour;
198 }
199
200 bool wxPen::Ok(void) const
201 {
202 return (m_refData != NULL);
203 }
204
205 void wxPen::Unshare(void)
206 {
207 if (!m_refData)
208 {
209 m_refData = new wxPenRefData();
210 }
211 else
212 {
213 wxPenRefData* ref = new wxPenRefData( *(wxPenRefData*)m_refData );
214 UnRef();
215 m_refData = ref;
216 }
217 }
218