]> git.saurik.com Git - wxWidgets.git/blob - src/os2/pen.cpp
debug check for infinite loop in InitializeClasses() added
[wxWidgets.git] / src / os2 / pen.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: pen.cpp
3 // Purpose: wxPen
4 // Author: David Webster
5 // Modified by:
6 // Created: 10/10/99
7 // RCS-ID: $Id$
8 // Copyright: (c) David Webster
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
14
15 #ifndef WX_PRECOMP
16 #include <stdio.h>
17 #include "wx/setup.h"
18 #include "wx/list.h"
19 #include "wx/utils.h"
20 #include "wx/app.h"
21 #include "wx/pen.h"
22 #endif
23
24 #include "wx/os2/private.h"
25 #include "assert.h"
26
27 #if !USE_SHARED_LIBRARIES
28 IMPLEMENT_DYNAMIC_CLASS(wxPen, wxGDIObject)
29 #endif
30
31 wxPenRefData::wxPenRefData()
32 {
33 m_style = wxSOLID;
34 m_width = 1;
35 m_join = wxJOIN_ROUND ;
36 m_cap = wxCAP_ROUND ;
37 m_nbDash = 0 ;
38 m_dash = 0 ;
39 m_hPen = 0;
40 }
41
42 wxPenRefData::wxPenRefData(const wxPenRefData& data)
43 {
44 m_style = data.m_style;
45 m_width = data.m_width;
46 m_join = data.m_join;
47 m_cap = data.m_cap;
48 m_nbDash = data.m_nbDash;
49 m_dash = data.m_dash;
50 m_colour = data.m_colour;
51 /* TODO: null data
52 m_hPen = 0;
53 */
54 }
55
56 wxPenRefData::~wxPenRefData()
57 {
58 // TODO: delete data
59 }
60
61 // Pens
62
63 wxPen::wxPen()
64 {
65 if ( wxThePenList )
66 wxThePenList->AddPen(this);
67 }
68
69 wxPen::~wxPen()
70 {
71 if (wxThePenList)
72 wxThePenList->RemovePen(this);
73 }
74
75 // Should implement Create
76 wxPen::wxPen(const wxColour& col, int Width, int Style)
77 {
78 m_refData = new wxPenRefData;
79
80 M_PENDATA->m_colour = col;
81 // M_PENDATA->m_stipple = NULL;
82 M_PENDATA->m_width = Width;
83 M_PENDATA->m_style = Style;
84 M_PENDATA->m_join = wxJOIN_ROUND ;
85 M_PENDATA->m_cap = wxCAP_ROUND ;
86 M_PENDATA->m_nbDash = 0 ;
87 M_PENDATA->m_dash = 0 ;
88 M_PENDATA->m_hPen = 0 ;
89
90 // TODO:
91 /*
92 if ((Style == wxDOT) || (Style == wxLONG_DASH) ||
93 (Style == wxSHORT_DASH) || (Style == wxDOT_DASH) ||
94 (Style == wxUSER_DASH))
95 M_PENDATA->m_width = 1;
96 */
97 RealizeResource();
98
99 if ( wxThePenList )
100 wxThePenList->AddPen(this);
101 }
102
103 wxPen::wxPen(const wxBitmap& stipple, int Width)
104 {
105 m_refData = new wxPenRefData;
106
107 M_PENDATA->m_stipple = stipple;
108 M_PENDATA->m_width = Width;
109 M_PENDATA->m_style = wxSTIPPLE;
110 M_PENDATA->m_join = wxJOIN_ROUND ;
111 M_PENDATA->m_cap = wxCAP_ROUND ;
112 M_PENDATA->m_nbDash = 0 ;
113 M_PENDATA->m_dash = 0 ;
114 M_PENDATA->m_hPen = 0 ;
115
116 RealizeResource();
117
118 if ( wxThePenList )
119 wxThePenList->AddPen(this);
120 }
121
122 bool wxPen::RealizeResource()
123 {
124 // TODO: create actual pen
125 return FALSE;
126 }
127
128 WXHANDLE wxPen::GetResourceHandle()
129 {
130 if ( !M_PENDATA )
131 return 0;
132 else
133 return (WXHANDLE)M_PENDATA->m_hPen;
134 }
135
136 bool wxPen::FreeResource(bool force)
137 {
138 if (M_PENDATA && (M_PENDATA->m_hPen != 0))
139 {
140 // TODO: DeleteObject((HPEN) M_PENDATA->m_hPen);
141 M_PENDATA->m_hPen = 0;
142 return TRUE;
143 }
144 else return FALSE;
145 }
146
147 bool wxPen::IsFree() const
148 {
149 return (M_PENDATA && M_PENDATA->m_hPen == 0);
150 }
151
152 void wxPen::Unshare()
153 {
154 // Don't change shared data
155 if (!m_refData)
156 {
157 m_refData = new wxPenRefData();
158 }
159 else
160 {
161 wxPenRefData* ref = new wxPenRefData(*(wxPenRefData*)m_refData);
162 UnRef();
163 m_refData = ref;
164 }
165 }
166
167 void wxPen::SetColour(const wxColour& col)
168 {
169 Unshare();
170
171 M_PENDATA->m_colour = col;
172
173 RealizeResource();
174 }
175
176 void wxPen::SetColour(unsigned char r, unsigned char g, unsigned char b)
177 {
178 Unshare();
179
180 M_PENDATA->m_colour.Set(r, g, b);
181
182 RealizeResource();
183 }
184
185 void wxPen::SetWidth(int Width)
186 {
187 Unshare();
188
189 M_PENDATA->m_width = Width;
190
191 RealizeResource();
192 }
193
194 void wxPen::SetStyle(int Style)
195 {
196 Unshare();
197
198 M_PENDATA->m_style = Style;
199
200 RealizeResource();
201 }
202
203 void wxPen::SetStipple(const wxBitmap& Stipple)
204 {
205 Unshare();
206
207 M_PENDATA->m_stipple = Stipple;
208 M_PENDATA->m_style = wxSTIPPLE;
209
210 RealizeResource();
211 }
212
213 void wxPen::SetDashes(int nb_dashes, const wxDash *Dash)
214 {
215 Unshare();
216
217 M_PENDATA->m_nbDash = nb_dashes;
218 M_PENDATA->m_dash = (wxDash *)Dash;
219
220 RealizeResource();
221 }
222
223 void wxPen::SetJoin(int Join)
224 {
225 Unshare();
226
227 M_PENDATA->m_join = Join;
228
229 RealizeResource();
230 }
231
232 void wxPen::SetCap(int Cap)
233 {
234 Unshare();
235
236 M_PENDATA->m_cap = Cap;
237
238 RealizeResource();
239 }
240
241 int wx2os2PenStyle(int wx_style)
242 {
243 int cstyle;
244 // TODO:
245 /*
246 switch (wx_style)
247 {
248 case wxDOT:
249 cstyle = PS_DOT;
250 break;
251
252 case wxDOT_DASH:
253 cstyle = PS_DASHDOT;
254 break;
255
256 case wxSHORT_DASH:
257 case wxLONG_DASH:
258 cstyle = PS_DASH;
259 break;
260
261 case wxTRANSPARENT:
262 cstyle = PS_NULL;
263 break;
264
265 case wxUSER_DASH:
266 #ifdef __WIN32__
267 // Win32s doesn't have PS_USERSTYLE
268 if (wxGetOsVersion()==wxWINDOWS_NT || wxGetOsVersion()==wxWIN95)
269 cstyle = PS_USERSTYLE;
270 else
271 cstyle = PS_DOT; // We must make a choice... This is mine!
272 #else
273 cstyle = PS_DASH;
274 #endif
275 break;
276 case wxSOLID:
277 default:
278 cstyle = PS_SOLID;
279 break;
280 }
281 */
282 return cstyle;
283 }
284
285