]>
Commit | Line | Data |
---|---|---|
c801d85f KB |
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); | |
335a8b43 | 27 | wxPenRefData(const wxPenRefData& data); |
c801d85f KB |
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; | |
ff7b1510 | 42 | } |
c801d85f | 43 | |
e55ad60e RR |
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 | ||
c801d85f KB |
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 ); | |
ff7b1510 | 62 | } |
c801d85f KB |
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; | |
52cbfcf0 | 70 | |
c801d85f | 71 | if (wxThePenList) wxThePenList->AddPen( this ); |
ff7b1510 | 72 | } |
c801d85f KB |
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; | |
52cbfcf0 | 80 | |
c801d85f | 81 | if (wxThePenList) wxThePenList->AddPen( this ); |
ff7b1510 | 82 | } |
c801d85f KB |
83 | |
84 | wxPen::wxPen( const wxPen& pen ) | |
85 | { | |
86 | Ref( pen ); | |
87 | if (wxThePenList) wxThePenList->AddPen( this ); | |
ff7b1510 | 88 | } |
c801d85f KB |
89 | |
90 | wxPen::wxPen( const wxPen* pen ) | |
91 | { | |
92 | UnRef(); | |
93 | if (pen) Ref( *pen ); | |
52cbfcf0 | 94 | |
c801d85f | 95 | if (wxThePenList) wxThePenList->AddPen( this ); |
ff7b1510 | 96 | } |
c801d85f KB |
97 | |
98 | wxPen::~wxPen(void) | |
99 | { | |
100 | if (wxThePenList) wxThePenList->RemovePen( this ); | |
ff7b1510 | 101 | } |
c801d85f KB |
102 | |
103 | wxPen& wxPen::operator = ( const wxPen& pen ) | |
104 | { | |
105 | if (*this == pen) return (*this); | |
106 | Ref( pen ); | |
107 | return *this; | |
ff7b1510 | 108 | } |
c801d85f KB |
109 | |
110 | bool wxPen::operator == ( const wxPen& pen ) | |
111 | { | |
112 | return m_refData == pen.m_refData; | |
ff7b1510 | 113 | } |
c801d85f KB |
114 | |
115 | bool wxPen::operator != ( const wxPen& pen ) | |
116 | { | |
117 | return m_refData != pen.m_refData; | |
ff7b1510 | 118 | } |
c801d85f KB |
119 | |
120 | void wxPen::SetColour( const wxColour &colour ) | |
121 | { | |
e55ad60e | 122 | Unshare(); |
c801d85f | 123 | M_PENDATA->m_colour = colour; |
ff7b1510 | 124 | } |
c801d85f KB |
125 | |
126 | void wxPen::SetColour( const wxString &colourName ) | |
127 | { | |
e55ad60e | 128 | Unshare(); |
c801d85f | 129 | M_PENDATA->m_colour = colourName; |
ff7b1510 | 130 | } |
c801d85f | 131 | |
debe6624 | 132 | void wxPen::SetColour( int red, int green, int blue ) |
c801d85f | 133 | { |
e55ad60e | 134 | Unshare(); |
c801d85f | 135 | M_PENDATA->m_colour.Set( red, green, blue ); |
ff7b1510 | 136 | } |
c801d85f KB |
137 | |
138 | void wxPen::SetCap( int capStyle ) | |
139 | { | |
e55ad60e | 140 | Unshare(); |
c801d85f | 141 | M_PENDATA->m_capStyle = capStyle; |
ff7b1510 | 142 | } |
c801d85f KB |
143 | |
144 | void wxPen::SetJoin( int joinStyle ) | |
145 | { | |
e55ad60e | 146 | Unshare(); |
c801d85f | 147 | M_PENDATA->m_joinStyle = joinStyle; |
ff7b1510 | 148 | } |
c801d85f KB |
149 | |
150 | void wxPen::SetStyle( int style ) | |
151 | { | |
e55ad60e | 152 | Unshare(); |
c801d85f | 153 | M_PENDATA->m_style = style; |
ff7b1510 | 154 | } |
c801d85f KB |
155 | |
156 | void wxPen::SetWidth( int width ) | |
157 | { | |
e55ad60e | 158 | Unshare(); |
c801d85f | 159 | M_PENDATA->m_width = width; |
ff7b1510 | 160 | } |
c801d85f KB |
161 | |
162 | int wxPen::GetCap(void) const | |
163 | { | |
e55ad60e RR |
164 | if (!m_refData) |
165 | { | |
166 | wxFAIL_MSG( "invalid pen" ); | |
167 | return -1; | |
168 | } | |
169 | ||
c801d85f | 170 | return M_PENDATA->m_capStyle; |
ff7b1510 | 171 | } |
c801d85f KB |
172 | |
173 | int wxPen::GetJoin(void) const | |
174 | { | |
175 | if (!m_refData) | |
e55ad60e RR |
176 | { |
177 | wxFAIL_MSG( "invalid pen" ); | |
178 | return -1; | |
179 | } | |
180 | ||
181 | return M_PENDATA->m_joinStyle; | |
ff7b1510 | 182 | } |
c801d85f KB |
183 | |
184 | int wxPen::GetStyle(void) const | |
185 | { | |
186 | if (!m_refData) | |
e55ad60e RR |
187 | { |
188 | wxFAIL_MSG( "invalid pen" ); | |
189 | return -1; | |
190 | } | |
191 | ||
192 | return M_PENDATA->m_style; | |
ff7b1510 | 193 | } |
c801d85f KB |
194 | |
195 | int wxPen::GetWidth(void) const | |
196 | { | |
197 | if (!m_refData) | |
e55ad60e RR |
198 | { |
199 | wxFAIL_MSG( "invalid pen" ); | |
200 | return -1; | |
201 | } | |
202 | ||
203 | return M_PENDATA->m_width; | |
ff7b1510 | 204 | } |
c801d85f KB |
205 | |
206 | wxColour &wxPen::GetColour(void) const | |
207 | { | |
208 | if (!m_refData) | |
e55ad60e RR |
209 | { |
210 | wxFAIL_MSG( "invalid pen" ); | |
c801d85f | 211 | return wxNullColour; |
e55ad60e RR |
212 | } |
213 | ||
214 | return M_PENDATA->m_colour; | |
ff7b1510 | 215 | } |
c801d85f KB |
216 | |
217 | bool wxPen::Ok(void) const | |
218 | { | |
e55ad60e RR |
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 | } | |
ff7b1510 | 234 | } |
c801d85f | 235 |