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