]> git.saurik.com Git - wxWidgets.git/blob - src/x11/pen.cpp
Create a wrapper file for X11/XKBlib.h header.
[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 #include "wx/bitmap.h"
20 #include "wx/colour.h"
21 #endif
22
23 //-----------------------------------------------------------------------------
24 // wxPen
25 //-----------------------------------------------------------------------------
26
27 class wxPenRefData : public wxGDIRefData
28 {
29 public:
30 wxPenRefData()
31 {
32 m_width = 1;
33 m_style = wxPENSTYLE_SOLID;
34 m_joinStyle = wxJOIN_ROUND;
35 m_capStyle = wxCAP_ROUND;
36 m_dash = NULL;
37 m_countDashes = 0;
38 }
39
40 wxPenRefData( const wxPenRefData& data )
41 {
42 m_style = data.m_style;
43 m_width = data.m_width;
44 m_joinStyle = data.m_joinStyle;
45 m_capStyle = data.m_capStyle;
46 m_colour = data.m_colour;
47 m_countDashes = data.m_countDashes;
48 /*
49 if (data.m_dash) TODO
50 m_dash = new
51 */
52 m_dash = data.m_dash;
53 m_stipple = data.m_stipple;
54 }
55
56 bool operator == (const wxPenRefData& data) const
57 {
58 return (m_style == data.m_style &&
59 m_width == data.m_width &&
60 m_joinStyle == data.m_joinStyle &&
61 m_capStyle == data.m_capStyle &&
62 m_colour == data.m_colour);
63 }
64
65 int m_width;
66 wxPenStyle m_style;
67 wxPenJoin m_joinStyle;
68 wxPenCap m_capStyle;
69 wxColour m_colour;
70 int m_countDashes;
71 wxBitmap m_stipple;
72 wxX11Dash *m_dash;
73 };
74
75 //-----------------------------------------------------------------------------
76
77 #define M_PENDATA ((wxPenRefData *)m_refData)
78
79 IMPLEMENT_DYNAMIC_CLASS(wxPen,wxGDIObject)
80
81 wxPen::wxPen( const wxColour &colour, int width, wxPenStyle style )
82 {
83 m_refData = new wxPenRefData();
84 M_PENDATA->m_width = width;
85 M_PENDATA->m_style = style;
86 M_PENDATA->m_colour = colour;
87 }
88
89 #if FUTURE_WXWIN_COMPATIBILITY_3_0
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 = (wxPenStyle)style;
95 M_PENDATA->m_colour = colour;
96 }
97 #endif
98
99 wxPen::~wxPen()
100 {
101 // m_refData unrefed in ~wxObject
102 }
103
104 wxGDIRefData *wxPen::CreateGDIRefData() const
105 {
106 return new wxPenRefData;
107 }
108
109 wxGDIRefData *wxPen::CloneGDIRefData(const wxGDIRefData *data) const
110 {
111 return new wxPenRefData(*(wxPenRefData *)data);
112 }
113
114 bool wxPen::operator == ( const wxPen& pen ) const
115 {
116 if (m_refData == pen.m_refData) return true;
117
118 if (!m_refData || !pen.m_refData) return false;
119
120 return ( *(wxPenRefData*)m_refData == *(wxPenRefData*)pen.m_refData );
121 }
122
123 void wxPen::SetColour( const wxColour &colour )
124 {
125 AllocExclusive();
126
127 M_PENDATA->m_colour = colour;
128 }
129
130 void wxPen::SetDashes( int number_of_dashes, const wxDash *dash )
131 {
132 AllocExclusive();
133
134 M_PENDATA->m_countDashes = number_of_dashes;
135 M_PENDATA->m_dash = (wxX11Dash *)dash; // TODO
136 }
137
138 void wxPen::SetColour( unsigned char red, unsigned char green, unsigned char blue )
139 {
140 AllocExclusive();
141
142 M_PENDATA->m_colour.Set( red, green, blue );
143 }
144
145 void wxPen::SetCap( wxPenCap capStyle )
146 {
147 AllocExclusive();
148
149 M_PENDATA->m_capStyle = capStyle;
150 }
151
152 void wxPen::SetJoin( wxPenJoin joinStyle )
153 {
154 AllocExclusive();
155
156 M_PENDATA->m_joinStyle = joinStyle;
157 }
158
159 void wxPen::SetStipple( const wxBitmap& stipple )
160 {
161 AllocExclusive();
162
163 M_PENDATA->m_stipple = stipple;
164 }
165
166 void wxPen::SetStyle( wxPenStyle style )
167 {
168 AllocExclusive();
169
170 M_PENDATA->m_style = style;
171 }
172
173 void wxPen::SetWidth( int width )
174 {
175 AllocExclusive();
176
177 M_PENDATA->m_width = width;
178 }
179
180 int wxPen::GetDashes( wxDash **ptr ) const
181 {
182 wxCHECK_MSG( IsOk(), -1, wxT("invalid pen") );
183
184 *ptr = (wxDash*)M_PENDATA->m_dash;
185 return M_PENDATA->m_countDashes;
186 }
187
188 int wxPen::GetDashCount() const
189 {
190 return (M_PENDATA->m_countDashes);
191 }
192
193 wxDash* wxPen::GetDash() const
194 {
195 return (wxDash*)M_PENDATA->m_dash;
196 }
197
198 wxPenCap wxPen::GetCap() const
199 {
200 wxCHECK_MSG( IsOk(), wxCAP_INVALID, wxT("invalid pen") );
201
202 return M_PENDATA->m_capStyle;
203 }
204
205 wxPenJoin wxPen::GetJoin() const
206 {
207 wxCHECK_MSG( IsOk(), wxJOIN_INVALID, wxT("invalid pen") );
208
209 return M_PENDATA->m_joinStyle;
210 }
211
212 wxPenStyle wxPen::GetStyle() const
213 {
214 wxCHECK_MSG( IsOk(), wxPENSTYLE_INVALID, wxT("invalid pen") );
215
216 return M_PENDATA->m_style;
217 }
218
219 int wxPen::GetWidth() const
220 {
221 wxCHECK_MSG( IsOk(), -1, wxT("invalid pen") );
222
223 return M_PENDATA->m_width;
224 }
225
226 wxColour wxPen::GetColour() const
227 {
228 wxCHECK_MSG( IsOk(), wxNullColour, wxT("invalid pen") );
229
230 return M_PENDATA->m_colour;
231 }
232
233 wxBitmap *wxPen::GetStipple() const
234 {
235 wxCHECK_MSG( IsOk(), &wxNullBitmap, wxT("invalid pen") );
236
237 return &M_PENDATA->m_stipple;
238 }