]> git.saurik.com Git - wxWidgets.git/blob - src/x11/pen.cpp
No changes, just move mouse capturing bookkeeping data out of wxWindow.
[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 // Copyright: (c) Julian Smart
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
10
11 // for compilers that support precompilation, includes "wx.h".
12 #include "wx/wxprec.h"
13
14 #include "wx/pen.h"
15
16 #ifndef WX_PRECOMP
17 #include "wx/utils.h"
18 #include "wx/bitmap.h"
19 #include "wx/colour.h"
20 #endif
21
22 //-----------------------------------------------------------------------------
23 // wxPen
24 //-----------------------------------------------------------------------------
25
26 class wxPenRefData : public wxGDIRefData
27 {
28 public:
29 wxPenRefData()
30 {
31 m_width = 1;
32 m_style = wxPENSTYLE_SOLID;
33 m_joinStyle = wxJOIN_ROUND;
34 m_capStyle = wxCAP_ROUND;
35 m_dash = NULL;
36 m_countDashes = 0;
37 }
38
39 wxPenRefData( const wxPenRefData& data )
40 {
41 m_style = data.m_style;
42 m_width = data.m_width;
43 m_joinStyle = data.m_joinStyle;
44 m_capStyle = data.m_capStyle;
45 m_colour = data.m_colour;
46 m_countDashes = data.m_countDashes;
47 /*
48 if (data.m_dash) TODO
49 m_dash = new
50 */
51 m_dash = data.m_dash;
52 m_stipple = data.m_stipple;
53 }
54
55 bool operator == (const wxPenRefData& data) const
56 {
57 return (m_style == data.m_style &&
58 m_width == data.m_width &&
59 m_joinStyle == data.m_joinStyle &&
60 m_capStyle == data.m_capStyle &&
61 m_colour == data.m_colour);
62 }
63
64 int m_width;
65 wxPenStyle m_style;
66 wxPenJoin m_joinStyle;
67 wxPenCap m_capStyle;
68 wxColour m_colour;
69 int m_countDashes;
70 wxBitmap m_stipple;
71 wxX11Dash *m_dash;
72 };
73
74 //-----------------------------------------------------------------------------
75
76 #define M_PENDATA ((wxPenRefData *)m_refData)
77
78 IMPLEMENT_DYNAMIC_CLASS(wxPen,wxGDIObject)
79
80 wxPen::wxPen( const wxColour &colour, int width, wxPenStyle style )
81 {
82 m_refData = new wxPenRefData();
83 M_PENDATA->m_width = width;
84 M_PENDATA->m_style = style;
85 M_PENDATA->m_colour = colour;
86 }
87
88 #if FUTURE_WXWIN_COMPATIBILITY_3_0
89 wxPen::wxPen(const wxColour& colour, int width, int style)
90 {
91 m_refData = new wxPenRefData();
92 M_PENDATA->m_width = width;
93 M_PENDATA->m_style = (wxPenStyle)style;
94 M_PENDATA->m_colour = colour;
95 }
96 #endif
97
98 wxPen::~wxPen()
99 {
100 // m_refData unrefed in ~wxObject
101 }
102
103 wxGDIRefData *wxPen::CreateGDIRefData() const
104 {
105 return new wxPenRefData;
106 }
107
108 wxGDIRefData *wxPen::CloneGDIRefData(const wxGDIRefData *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 = (wxX11Dash *)dash; // TODO
135 }
136
137 void wxPen::SetColour( unsigned char red, unsigned char green, unsigned char blue )
138 {
139 AllocExclusive();
140
141 M_PENDATA->m_colour.Set( red, green, blue );
142 }
143
144 void wxPen::SetCap( wxPenCap capStyle )
145 {
146 AllocExclusive();
147
148 M_PENDATA->m_capStyle = capStyle;
149 }
150
151 void wxPen::SetJoin( wxPenJoin joinStyle )
152 {
153 AllocExclusive();
154
155 M_PENDATA->m_joinStyle = joinStyle;
156 }
157
158 void wxPen::SetStipple( const wxBitmap& stipple )
159 {
160 AllocExclusive();
161
162 M_PENDATA->m_stipple = stipple;
163 }
164
165 void wxPen::SetStyle( wxPenStyle style )
166 {
167 AllocExclusive();
168
169 M_PENDATA->m_style = style;
170 }
171
172 void wxPen::SetWidth( int width )
173 {
174 AllocExclusive();
175
176 M_PENDATA->m_width = width;
177 }
178
179 int wxPen::GetDashes( wxDash **ptr ) const
180 {
181 wxCHECK_MSG( IsOk(), -1, wxT("invalid pen") );
182
183 *ptr = (wxDash*)M_PENDATA->m_dash;
184 return M_PENDATA->m_countDashes;
185 }
186
187 int wxPen::GetDashCount() const
188 {
189 return (M_PENDATA->m_countDashes);
190 }
191
192 wxDash* wxPen::GetDash() const
193 {
194 return (wxDash*)M_PENDATA->m_dash;
195 }
196
197 wxPenCap wxPen::GetCap() const
198 {
199 wxCHECK_MSG( IsOk(), wxCAP_INVALID, wxT("invalid pen") );
200
201 return M_PENDATA->m_capStyle;
202 }
203
204 wxPenJoin wxPen::GetJoin() const
205 {
206 wxCHECK_MSG( IsOk(), wxJOIN_INVALID, wxT("invalid pen") );
207
208 return M_PENDATA->m_joinStyle;
209 }
210
211 wxPenStyle wxPen::GetStyle() const
212 {
213 wxCHECK_MSG( IsOk(), wxPENSTYLE_INVALID, wxT("invalid pen") );
214
215 return M_PENDATA->m_style;
216 }
217
218 int wxPen::GetWidth() const
219 {
220 wxCHECK_MSG( IsOk(), -1, wxT("invalid pen") );
221
222 return M_PENDATA->m_width;
223 }
224
225 wxColour wxPen::GetColour() const
226 {
227 wxCHECK_MSG( IsOk(), wxNullColour, wxT("invalid pen") );
228
229 return M_PENDATA->m_colour;
230 }
231
232 wxBitmap *wxPen::GetStipple() const
233 {
234 wxCHECK_MSG( IsOk(), &wxNullBitmap, wxT("invalid pen") );
235
236 return &M_PENDATA->m_stipple;
237 }