]> git.saurik.com Git - wxWidgets.git/blob - src/x11/pen.cpp
revert removal of gtk1 code from common file
[wxWidgets.git] / src / x11 / pen.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/x11/pen.cpp
3 // Purpose: wxPen
4 // Author: Julian Smart
5 // Modified by:
6 // Created: 17/09/98
7 // RCS-ID: $Id$
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 // for compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
14
15 #include "wx/pen.h"
16
17 #ifndef WX_PRECOMP
18 #include "wx/utils.h"
19 #endif
20
21 #include "wx/colour.h"
22 #include "wx/bitmap.h"
23
24 //-----------------------------------------------------------------------------
25 // wxPen
26 //-----------------------------------------------------------------------------
27
28 class wxPenRefData: public wxObjectRefData
29 {
30 public:
31 wxPenRefData()
32 {
33 m_width = 1;
34 m_style = wxSOLID;
35 m_joinStyle = wxJOIN_ROUND;
36 m_capStyle = wxCAP_ROUND;
37 m_dash = (wxX11Dash*) NULL;
38 m_countDashes = 0;
39 }
40
41 wxPenRefData( const wxPenRefData& data )
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 /*
50 if (data.m_dash) TODO
51 m_dash = new
52 */
53 m_dash = data.m_dash;
54 m_stipple = data.m_stipple;
55 }
56
57 bool operator == (const wxPenRefData& data) const
58 {
59 return (m_style == data.m_style &&
60 m_width == data.m_width &&
61 m_joinStyle == data.m_joinStyle &&
62 m_capStyle == data.m_capStyle &&
63 m_colour == data.m_colour);
64 }
65
66 int m_width;
67 int m_style;
68 int m_joinStyle;
69 int m_capStyle;
70 wxColour m_colour;
71 int m_countDashes;
72 wxBitmap m_stipple;
73 wxX11Dash *m_dash;
74 };
75
76 //-----------------------------------------------------------------------------
77
78 #define M_PENDATA ((wxPenRefData *)m_refData)
79
80 IMPLEMENT_DYNAMIC_CLASS(wxPen,wxGDIObject)
81
82 wxPen::wxPen( const wxColour &colour, int width, int style )
83 {
84 m_refData = new wxPenRefData();
85 M_PENDATA->m_width = width;
86 M_PENDATA->m_style = style;
87 M_PENDATA->m_colour = colour;
88 }
89
90 wxPen::~wxPen()
91 {
92 // m_refData unrefed in ~wxObject
93 }
94
95 wxObjectRefData *wxPen::CreateRefData() const
96 {
97 return new wxPenRefData;
98 }
99
100 wxObjectRefData *wxPen::CloneRefData(const wxObjectRefData *data) const
101 {
102 return new wxPenRefData(*(wxPenRefData *)data);
103 }
104
105 bool wxPen::operator == ( const wxPen& pen ) const
106 {
107 if (m_refData == pen.m_refData) return true;
108
109 if (!m_refData || !pen.m_refData) return false;
110
111 return ( *(wxPenRefData*)m_refData == *(wxPenRefData*)pen.m_refData );
112 }
113
114 void wxPen::SetColour( const wxColour &colour )
115 {
116 AllocExclusive();
117
118 M_PENDATA->m_colour = colour;
119 }
120
121 void wxPen::SetDashes( int number_of_dashes, const wxDash *dash )
122 {
123 AllocExclusive();
124
125 M_PENDATA->m_countDashes = number_of_dashes;
126 M_PENDATA->m_dash = (wxX11Dash *)dash; // TODO
127 }
128
129 void wxPen::SetColour( unsigned char red, unsigned char green, unsigned char blue )
130 {
131 AllocExclusive();
132
133 M_PENDATA->m_colour.Set( red, green, blue );
134 }
135
136 void wxPen::SetCap( int capStyle )
137 {
138 AllocExclusive();
139
140 M_PENDATA->m_capStyle = capStyle;
141 }
142
143 void wxPen::SetJoin( int joinStyle )
144 {
145 AllocExclusive();
146
147 M_PENDATA->m_joinStyle = joinStyle;
148 }
149
150 void wxPen::SetStipple( wxBitmap *stipple )
151 {
152 AllocExclusive();
153
154 M_PENDATA->m_stipple = *stipple;
155 }
156
157 void wxPen::SetStyle( int style )
158 {
159 AllocExclusive();
160
161 M_PENDATA->m_style = style;
162 }
163
164 void wxPen::SetWidth( int width )
165 {
166 AllocExclusive();
167
168 M_PENDATA->m_width = width;
169 }
170
171 int wxPen::GetDashes( wxDash **ptr ) const
172 {
173 *ptr = (M_PENDATA ? (wxDash*)M_PENDATA->m_dash : (wxDash*) NULL);
174 return (M_PENDATA ? M_PENDATA->m_countDashes : 0);
175 }
176
177 int wxPen::GetDashCount() const
178 {
179 return (M_PENDATA->m_countDashes);
180 }
181
182 wxDash* wxPen::GetDash() const
183 {
184 return (wxDash*)M_PENDATA->m_dash;
185 }
186
187 int wxPen::GetCap() const
188 {
189 wxCHECK_MSG( Ok(), -1, wxT("invalid pen") );
190
191 return M_PENDATA->m_capStyle;
192 }
193
194 int wxPen::GetJoin() const
195 {
196 wxCHECK_MSG( Ok(), -1, wxT("invalid pen") );
197
198 return M_PENDATA->m_joinStyle;
199 }
200
201 int wxPen::GetStyle() const
202 {
203 wxCHECK_MSG( Ok(), -1, wxT("invalid pen") );
204
205 return M_PENDATA->m_style;
206 }
207
208 int wxPen::GetWidth() const
209 {
210 wxCHECK_MSG( Ok(), -1, wxT("invalid pen") );
211
212 return M_PENDATA->m_width;
213 }
214
215 wxColour &wxPen::GetColour() const
216 {
217 wxCHECK_MSG( Ok(), wxNullColour, wxT("invalid pen") );
218
219 return M_PENDATA->m_colour;
220 }
221
222 wxBitmap *wxPen::GetStipple() const
223 {
224 wxCHECK_MSG( Ok(), &wxNullBitmap, wxT("invalid pen") );
225
226 return &M_PENDATA->m_stipple;
227 }