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