]>
Commit | Line | Data |
---|---|---|
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 | m_dash = data.m_dash; | |
47 | } | |
48 | ||
49 | bool operator == (const wxPenRefData& data) const | |
50 | { | |
51 | if ( m_countDashes != data.m_countDashes ) | |
52 | return FALSE; | |
53 | ||
54 | if ( m_dash ) | |
55 | { | |
56 | if ( !data.m_dash || | |
57 | memcmp(m_dash, data.m_dash, m_countDashes*sizeof(wxGTKDash)) ) | |
58 | { | |
59 | return FALSE; | |
60 | } | |
61 | } | |
62 | else if ( data.m_dash ) | |
63 | { | |
64 | return FALSE; | |
65 | } | |
66 | ||
67 | ||
68 | return m_style == data.m_style && | |
69 | m_width == data.m_width && | |
70 | m_joinStyle == data.m_joinStyle && | |
71 | m_capStyle == data.m_capStyle && | |
72 | m_colour == data.m_colour; | |
73 | } | |
74 | ||
75 | int m_width; | |
76 | int m_style; | |
77 | int m_joinStyle; | |
78 | int m_capStyle; | |
79 | wxColour m_colour; | |
80 | int m_countDashes; | |
81 | wxGTKDash *m_dash; | |
82 | }; | |
83 | ||
84 | //----------------------------------------------------------------------------- | |
85 | ||
86 | #define M_PENDATA ((wxPenRefData *)m_refData) | |
87 | ||
88 | IMPLEMENT_DYNAMIC_CLASS(wxPen,wxGDIObject) | |
89 | ||
90 | wxPen::wxPen( const wxColour &colour, int width, int style ) | |
91 | { | |
92 | m_refData = new wxPenRefData(); | |
93 | M_PENDATA->m_width = width; | |
94 | M_PENDATA->m_style = style; | |
95 | M_PENDATA->m_colour = colour; | |
96 | } | |
97 | ||
98 | wxPen::~wxPen() | |
99 | { | |
100 | // m_refData unrefed in ~wxObject | |
101 | } | |
102 | ||
103 | wxObjectRefData *wxPen::CreateRefData() const | |
104 | { | |
105 | return new wxPenRefData; | |
106 | } | |
107 | ||
108 | wxObjectRefData *wxPen::CloneRefData(const wxObjectRefData *data) const | |
109 | { | |
110 | return new wxPenRefData(*(wxPenRefData *)data); | |
111 | } | |
112 | ||
113 | bool wxPen::operator == ( const wxPen& pen ) const | |
114 | { | |
115 | if (m_refData == pen.m_refData) return TRUE; | |
116 | ||
117 | if (!m_refData || !pen.m_refData) return FALSE; | |
118 | ||
119 | return ( *(wxPenRefData*)m_refData == *(wxPenRefData*)pen.m_refData ); | |
120 | } | |
121 | ||
122 | void wxPen::SetColour( const wxColour &colour ) | |
123 | { | |
124 | AllocExclusive(); | |
125 | ||
126 | M_PENDATA->m_colour = colour; | |
127 | } | |
128 | ||
129 | void wxPen::SetDashes( int number_of_dashes, const wxDash *dash ) | |
130 | { | |
131 | AllocExclusive(); | |
132 | ||
133 | M_PENDATA->m_countDashes = number_of_dashes; | |
134 | M_PENDATA->m_dash = (wxGTKDash *)dash; | |
135 | } | |
136 | ||
137 | void wxPen::SetColour( int red, int green, int blue ) | |
138 | { | |
139 | AllocExclusive(); | |
140 | ||
141 | M_PENDATA->m_colour.Set( red, green, blue ); | |
142 | } | |
143 | ||
144 | void wxPen::SetCap( int capStyle ) | |
145 | { | |
146 | AllocExclusive(); | |
147 | ||
148 | M_PENDATA->m_capStyle = capStyle; | |
149 | } | |
150 | ||
151 | void wxPen::SetJoin( int joinStyle ) | |
152 | { | |
153 | AllocExclusive(); | |
154 | ||
155 | M_PENDATA->m_joinStyle = joinStyle; | |
156 | } | |
157 | ||
158 | void wxPen::SetStyle( int style ) | |
159 | { | |
160 | AllocExclusive(); | |
161 | ||
162 | M_PENDATA->m_style = style; | |
163 | } | |
164 | ||
165 | void wxPen::SetWidth( int width ) | |
166 | { | |
167 | AllocExclusive(); | |
168 | ||
169 | M_PENDATA->m_width = width; | |
170 | } | |
171 | ||
172 | int wxPen::GetDashes( wxDash **ptr ) const | |
173 | { | |
174 | *ptr = (M_PENDATA ? (wxDash*)M_PENDATA->m_dash : (wxDash*) NULL); | |
175 | return (M_PENDATA ? M_PENDATA->m_countDashes : 0); | |
176 | } | |
177 | ||
178 | int wxPen::GetDashCount() const | |
179 | { | |
180 | return (M_PENDATA->m_countDashes); | |
181 | } | |
182 | ||
183 | wxDash* wxPen::GetDash() const | |
184 | { | |
185 | return (wxDash*)M_PENDATA->m_dash; | |
186 | } | |
187 | ||
188 | int wxPen::GetCap() const | |
189 | { | |
190 | wxCHECK_MSG( Ok(), -1, wxT("invalid pen") ); | |
191 | ||
192 | return M_PENDATA->m_capStyle; | |
193 | } | |
194 | ||
195 | int wxPen::GetJoin() const | |
196 | { | |
197 | wxCHECK_MSG( Ok(), -1, wxT("invalid pen") ); | |
198 | ||
199 | return M_PENDATA->m_joinStyle; | |
200 | } | |
201 | ||
202 | int wxPen::GetStyle() const | |
203 | { | |
204 | wxCHECK_MSG( Ok(), -1, wxT("invalid pen") ); | |
205 | ||
206 | return M_PENDATA->m_style; | |
207 | } | |
208 | ||
209 | int wxPen::GetWidth() const | |
210 | { | |
211 | wxCHECK_MSG( Ok(), -1, wxT("invalid pen") ); | |
212 | ||
213 | return M_PENDATA->m_width; | |
214 | } | |
215 | ||
216 | wxColour &wxPen::GetColour() const | |
217 | { | |
218 | wxCHECK_MSG( Ok(), wxNullColour, wxT("invalid pen") ); | |
219 | ||
220 | return M_PENDATA->m_colour; | |
221 | } | |
222 |