]> git.saurik.com Git - wxWidgets.git/blame - src/mgl/pen.cpp
don't crash when XIM is used under IRIX
[wxWidgets.git] / src / mgl / pen.cpp
CommitLineData
32b8ec41 1/////////////////////////////////////////////////////////////////////////////
46562151 2// Name: src/mgl/pen.cpp
32b8ec41
VZ
3// Purpose:
4// Author: Vaclav Slavik
5// Id: $Id$
c41c20a5 6// Copyright: (c) 2001-2002 SciTech Software, Inc. (www.scitechsoft.com)
65571936 7// Licence: wxWindows licence
32b8ec41
VZ
8/////////////////////////////////////////////////////////////////////////////
9
a246f95e
VS
10// For compilers that support precompilation, includes "wx.h".
11#include "wx/wxprec.h"
12
13#ifdef __BORLANDC__
14 #pragma hdrstop
15#endif
16
32b8ec41
VZ
17#include "wx/pen.h"
18#include "wx/bitmap.h"
c3d15542 19#include "wx/colour.h"
32b8ec41
VZ
20#include "wx/mgl/private.h"
21
22//-----------------------------------------------------------------------------
23// wxPen
24//-----------------------------------------------------------------------------
25
26class wxPenRefData: public wxObjectRefData
27{
28 public:
29 wxPenRefData();
30 wxPenRefData(const wxPenRefData& data);
31
32 int m_width;
33 int m_style;
34 wxColour m_colour;
35 wxBitmap m_stipple;
36 pixpattern24_t m_pixPattern;
37
38 // not used by wxMGL, but we want to preserve values
39 int m_joinStyle;
40 int m_capStyle;
41 int m_countDashes;
42 wxDash *m_dash;
43};
44
45wxPenRefData::wxPenRefData()
46{
47 m_width = 1;
48 m_style = wxSOLID;
49 m_joinStyle = wxJOIN_ROUND;
50 m_capStyle = wxCAP_ROUND;
51 m_dash = (wxDash*) NULL;
52 m_countDashes = 0;
53
54 int x, y, c;
55 for (y = 0; y < 8; y++)
56 for (x = 0; x < 8; x++)
57 for (c = 0; c < 3; c++)
58 m_pixPattern.p[x][y][c] = 0;
59}
60
61wxPenRefData::wxPenRefData(const wxPenRefData& data)
62{
63 m_style = data.m_style;
64 m_width = data.m_width;
65 m_joinStyle = data.m_joinStyle;
66 m_capStyle = data.m_capStyle;
67 m_colour = data.m_colour;
68 m_countDashes = data.m_countDashes;
69 m_dash = data.m_dash;
70 m_stipple = data.m_stipple;
71
72 int x, y, c;
73 for (y = 0; y < 8; y++)
74 for (x = 0; x < 8; x++)
75 for (c = 0; c < 3; c++)
76 m_pixPattern.p[x][y][c] = data.m_pixPattern.p[x][y][c];
77}
78
79//-----------------------------------------------------------------------------
80
81#define M_PENDATA ((wxPenRefData *)m_refData)
82
83IMPLEMENT_DYNAMIC_CLASS(wxPen,wxGDIObject)
84
32b8ec41
VZ
85wxPen::wxPen(const wxColour &colour, int width, int style)
86{
87 m_refData = new wxPenRefData();
88 M_PENDATA->m_width = width;
89 M_PENDATA->m_style = style;
90 M_PENDATA->m_colour = colour;
32b8ec41
VZ
91}
92
93wxPen::wxPen(const wxBitmap& stipple, int width)
94{
95 wxCHECK_RET( stipple.Ok(), _T("invalid bitmap") );
46562151 96 wxCHECK_RET( stipple.GetWidth() == 8 && stipple.GetHeight() == 8,
32b8ec41
VZ
97 _T("stipple bitmap must be 8x8") );
98
99 m_refData = new wxPenRefData();
100 M_PENDATA->m_width = width;
101 M_PENDATA->m_style = wxSTIPPLE;
102 M_PENDATA->m_stipple = stipple;
103 wxBitmapToPixPattern(stipple, &(M_PENDATA->m_pixPattern), NULL);
32b8ec41
VZ
104}
105
106wxPen::wxPen(const wxPen& pen)
107{
108 Ref(pen);
32b8ec41
VZ
109}
110
111wxPen& wxPen::operator = (const wxPen& pen)
112{
113 if (*this == pen) return (*this);
114 Ref(pen);
115 return *this;
116}
117
118bool wxPen::operator == (const wxPen& pen) const
119{
120 return m_refData == pen.m_refData;
121}
122
123bool wxPen::operator != (const wxPen& pen) const
124{
125 return m_refData != pen.m_refData;
126}
127
128void wxPen::SetColour(const wxColour &colour)
129{
6d7ee9e8 130 AllocExclusive();
32b8ec41
VZ
131 M_PENDATA->m_colour = colour;
132}
133
134void wxPen::SetDashes(int number_of_dashes, const wxDash *dash)
135{
6d7ee9e8 136 AllocExclusive();
32b8ec41
VZ
137 M_PENDATA->m_countDashes = number_of_dashes;
138 M_PENDATA->m_dash = (wxDash *)dash; /* TODO */
139}
140
1a1498c0 141void wxPen::SetColour(unsigned char red, unsigned char green, unsigned char blue)
32b8ec41 142{
6d7ee9e8 143 AllocExclusive();
32b8ec41
VZ
144 M_PENDATA->m_colour.Set(red, green, blue);
145}
146
147void wxPen::SetCap(int capStyle)
148{
6d7ee9e8 149 AllocExclusive();
32b8ec41
VZ
150 M_PENDATA->m_capStyle = capStyle;
151}
152
153void wxPen::SetJoin(int joinStyle)
154{
6d7ee9e8 155 AllocExclusive();
32b8ec41
VZ
156 M_PENDATA->m_joinStyle = joinStyle;
157}
158
159void wxPen::SetStyle(int style)
160{
6d7ee9e8 161 AllocExclusive();
32b8ec41
VZ
162 M_PENDATA->m_style = style;
163}
164
165void wxPen::SetStipple(const wxBitmap& stipple)
166{
167 wxCHECK_RET( stipple.Ok(), _T("invalid bitmap") );
46562151 168 wxCHECK_RET( stipple.GetWidth() == 8 && stipple.GetHeight() == 8,
32b8ec41
VZ
169 _T("stipple bitmap must be 8x8") );
170
6d7ee9e8 171 AllocExclusive();
32b8ec41
VZ
172 M_PENDATA->m_stipple = stipple;
173 wxBitmapToPixPattern(stipple, &(M_PENDATA->m_pixPattern), NULL);
174}
175
176void wxPen::SetWidth(int width)
177{
6d7ee9e8 178 AllocExclusive();
32b8ec41
VZ
179 M_PENDATA->m_width = width;
180}
181
46562151 182int wxPen::GetDashes(wxDash **ptr) const
32b8ec41 183{
46562151 184 *ptr = (M_PENDATA ? (wxDash*)M_PENDATA->m_dash : (wxDash*) NULL);
32b8ec41
VZ
185 return (M_PENDATA ? M_PENDATA->m_countDashes : 0);
186}
187
46562151
WS
188int wxPen::GetDashCount() const
189{
190 return (M_PENDATA->m_countDashes);
32b8ec41
VZ
191}
192
46562151
WS
193wxDash* wxPen::GetDash() const
194{
195 return (wxDash*)M_PENDATA->m_dash;
32b8ec41
VZ
196}
197
198int wxPen::GetCap() const
199{
200 wxCHECK_MSG( Ok(), -1, wxT("invalid pen") );
201
202 return M_PENDATA->m_capStyle;
203}
204
205int wxPen::GetJoin() const
206{
207 wxCHECK_MSG( Ok(), -1, wxT("invalid pen") );
208
209 return M_PENDATA->m_joinStyle;
210}
211
212int wxPen::GetStyle() const
213{
214 wxCHECK_MSG( Ok(), -1, wxT("invalid pen") );
215
216 return M_PENDATA->m_style;
217}
218
219int wxPen::GetWidth() const
220{
221 wxCHECK_MSG( Ok(), -1, wxT("invalid pen") );
222
223 return M_PENDATA->m_width;
224}
225
226wxColour &wxPen::GetColour() const
227{
228 wxCHECK_MSG( Ok(), wxNullColour, wxT("invalid pen") );
229
230 return M_PENDATA->m_colour;
231}
232
233wxBitmap *wxPen::GetStipple() const
234{
235 wxCHECK_MSG( Ok(), NULL, wxT("invalid pen") );
236
237 return &(M_PENDATA->m_stipple);
238}
239
240void* wxPen::GetPixPattern() const
241{
242 wxCHECK_MSG( Ok(), NULL, wxT("invalid pen") );
243
244 return (void*)&(M_PENDATA->m_pixPattern);
245}
246
247
248bool wxPen::Ok() const
249{
250 return (m_refData != NULL);
251}
252
6d7ee9e8 253wxObjectRefData *wxPen::CreateRefData() const
32b8ec41 254{
6d7ee9e8
VS
255 return new wxPenRefData;
256}
257
258wxObjectRefData *wxPen::CloneRefData(const wxObjectRefData *data) const
259{
260 return new wxPenRefData(*(wxPenRefData *)data);
32b8ec41 261}