]> git.saurik.com Git - wxWidgets.git/blob - src/os2/pen.cpp
added and documented wxProcess::Is{Input|Error}Available() and IsInputOpened
[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 IMPLEMENT_DYNAMIC_CLASS(wxPen, wxGDIObject)
28
29 wxPenRefData::wxPenRefData()
30 {
31 m_nStyle = wxSOLID;
32 m_nWidth = 1;
33 m_nJoin = wxJOIN_ROUND ;
34 m_nCap = wxCAP_ROUND ;
35 m_hPen = 0L;
36 } // end of wxPenRefData::wxPenRefData
37
38 wxPenRefData::wxPenRefData(
39 const wxPenRefData& rData
40 )
41 {
42 m_nStyle = rData.m_nStyle;
43 m_nWidth = rData.m_nWidth;
44 m_nJoin = rData.m_nJoin;
45 m_nCap = rData.m_nCap;
46 m_vColour = rData.m_vColour;
47 m_hPen = 0L;
48 } // end of wxPenRefData::wxPenRefData
49
50 wxPenRefData::~wxPenRefData()
51 {
52 } // end of wxPenRefData::~wxPenRefData
53
54 //
55 // Pens
56 //
57 wxPen::wxPen()
58 {
59 if ( wxThePenList )
60 wxThePenList->AddPen(this);
61 } // end of wxPen::wxPen
62
63 wxPen::~wxPen()
64 {
65 if (wxThePenList)
66 wxThePenList->RemovePen(this);
67 } // end of wxPen::wxPen
68
69 // Should implement Create
70 wxPen::wxPen(
71 const wxColour& rColour
72 , int nWidth
73 , int nStyle
74 )
75 {
76 m_refData = new wxPenRefData;
77
78 M_PENDATA->m_vColour = rColour;
79 M_PENDATA->m_nWidth = nWidth;
80 M_PENDATA->m_nStyle = nStyle;
81 M_PENDATA->m_nJoin = wxJOIN_ROUND ;
82 M_PENDATA->m_nCap = wxCAP_ROUND ;
83 M_PENDATA->m_hPen = 0L;
84
85 RealizeResource();
86
87 if ( wxThePenList )
88 wxThePenList->AddPen(this);
89 } // end of wxPen::wxPen
90
91 wxPen::wxPen(
92 const wxBitmap& rStipple
93 , int nWidth
94 )
95 {
96 m_refData = new wxPenRefData;
97
98 M_PENDATA->m_vStipple = rStipple;
99 M_PENDATA->m_nWidth = nWidth;
100 M_PENDATA->m_nStyle = wxSTIPPLE;
101 M_PENDATA->m_nJoin = wxJOIN_ROUND ;
102 M_PENDATA->m_nCap = wxCAP_ROUND ;
103 M_PENDATA->m_hPen = 0;
104
105 RealizeResource();
106
107 if ( wxThePenList )
108 wxThePenList->AddPen(this);
109 } // end of wxPen::wxPen
110
111 bool wxPen::RealizeResource()
112 {
113 BOOL bOk;
114 ERRORID vError;
115 wxString sError;
116
117 if (M_PENDATA && M_PENDATA->m_hPen == 0L)
118 {
119 SIZEL vSize = {0, 0};
120 DEVOPENSTRUC vDop = {0L, "DISPLAY", NULL, 0L, 0L, 0L, 0L, 0L, 0L};
121 HDC hDC = ::DevOpenDC( vHabmain
122 ,OD_MEMORY
123 ,"*"
124 ,5L
125 ,(PDEVOPENDATA)&vDop
126 ,NULLHANDLE
127 );
128 M_PENDATA->m_hPen = (WXHPEN)::GpiCreatePS( vHabmain
129 ,hDC
130 ,&vSize
131 ,PU_PELS | GPIT_MICRO | GPIA_ASSOC
132 );
133 }
134 if (M_PENDATA)
135 {
136 //
137 // Set the color table to RGB mode
138 //
139 if (!::GpiCreateLogColorTable( (HPS)M_PENDATA->m_hPen
140 ,0L
141 ,LCOLF_RGB
142 ,0L
143 ,0L
144 ,NULL
145 ))
146 {
147 vError = ::WinGetLastError(vHabmain);
148 sError = wxPMErrorToStr(vError);
149 wxLogError("Unable to set current color table to RGB mode. Error: %s\n", sError);
150 return FALSE;
151 }
152 if (M_PENDATA->m_nStyle == wxTRANSPARENT)
153 {
154 return TRUE;
155 }
156
157 COLORREF vPmColour = 0L;
158 USHORT uLineType = wx2os2PenStyle(M_PENDATA->m_nStyle);
159
160 vPmColour = M_PENDATA->m_vColour.GetPixel();
161
162 USHORT uJoin = 0L;
163
164 switch(M_PENDATA->m_nJoin)
165 {
166 case wxJOIN_BEVEL:
167 uJoin = LINEJOIN_BEVEL;
168 break;
169
170 case wxJOIN_MITER:
171 uJoin = LINEJOIN_MITRE;
172 break;
173
174 case wxJOIN_ROUND:
175 uJoin = LINEJOIN_ROUND;
176 break;
177 }
178
179 USHORT uCap = 0L;
180
181 switch(M_PENDATA->m_nCap)
182 {
183 case wxCAP_PROJECTING:
184 uCap = LINEEND_SQUARE;
185 break;
186
187 case wxCAP_BUTT:
188 uCap = LINEEND_FLAT;
189 break;
190
191 case wxCAP_ROUND:
192 uCap = LINEEND_ROUND;
193 break;
194 }
195 m_vLineBundle.lColor = (LONG)vPmColour;
196 m_vLineBundle.usMixMode = FM_OVERPAINT;
197 m_vLineBundle.fxWidth = M_PENDATA->m_nWidth;
198 m_vLineBundle.lGeomWidth = M_PENDATA->m_nWidth;
199 m_vLineBundle.usType = uLineType;
200 m_vLineBundle.usEnd = uCap;
201 m_vLineBundle.usJoin = uJoin;
202
203 bOk = ::GpiSetAttrs( M_PENDATA->m_hPen
204 ,PRIM_LINE
205 ,LBB_COLOR | LBB_MIX_MODE | LBB_WIDTH | LBB_GEOM_WIDTH | LBB_TYPE | LBB_END | LBB_JOIN
206 ,0L
207 ,&m_vLineBundle
208 );
209 if (!bOk)
210 {
211 vError = ::WinGetLastError(vHabmain);
212 sError = wxPMErrorToStr(vError);
213 wxLogError("Can't set Gpi attributes for a LINEBUNDLE. Error: %s\n", sError);
214 return FALSE;
215 }
216
217 ULONG flAttrMask = 0L;
218 ULONG flDefMask = 0L;
219 switch(M_PENDATA->m_nStyle)
220 {
221 case wxSTIPPLE:
222 ::GpiSetBitmapId( M_PENDATA->m_hPen
223 ,(USHORT)M_PENDATA->m_vStipple.GetHBITMAP()
224 ,(USHORT)M_PENDATA->m_vStipple.GetId()
225 );
226 ::GpiSetPatternSet( M_PENDATA->m_hPen
227 ,(USHORT)M_PENDATA->m_vStipple.GetId()
228 );
229 flAttrMask = ABB_COLOR | ABB_BACK_COLOR | ABB_MIX_MODE | ABB_BACK_MIX_MODE | ABB_SET | ABB_SYMBOL;
230 flDefMask = ABB_REF_POINT;
231 break;
232
233 case wxBDIAGONAL_HATCH:
234 m_vAreaBundle.usSymbol = PATSYM_DIAG3;
235 m_vAreaBundle.usSet = LCID_DEFAULT;
236 flAttrMask = ABB_COLOR | ABB_BACK_COLOR | ABB_MIX_MODE | ABB_BACK_MIX_MODE | ABB_SYMBOL;
237 flDefMask = ABB_SET | ABB_REF_POINT;
238 break;
239
240 case wxCROSSDIAG_HATCH:
241 m_vAreaBundle.usSymbol = PATSYM_DIAGHATCH;
242 m_vAreaBundle.usSet = LCID_DEFAULT;
243 flAttrMask = ABB_COLOR | ABB_BACK_COLOR | ABB_MIX_MODE | ABB_BACK_MIX_MODE | ABB_SYMBOL;
244 flDefMask = ABB_SET | ABB_REF_POINT;
245 break;
246
247 case wxFDIAGONAL_HATCH:
248 m_vAreaBundle.usSymbol = PATSYM_DIAG1;
249 m_vAreaBundle.usSet = LCID_DEFAULT;
250 flAttrMask = ABB_COLOR | ABB_BACK_COLOR | ABB_MIX_MODE | ABB_BACK_MIX_MODE | ABB_SYMBOL;
251 flDefMask = ABB_SET | ABB_REF_POINT;
252 break;
253
254 case wxCROSS_HATCH:
255 m_vAreaBundle.usSymbol = PATSYM_HATCH;
256 m_vAreaBundle.usSet = LCID_DEFAULT;
257 flAttrMask = ABB_COLOR | ABB_BACK_COLOR | ABB_MIX_MODE | ABB_BACK_MIX_MODE | ABB_SYMBOL;
258 flDefMask = ABB_SET | ABB_REF_POINT;
259 break;
260
261 case wxHORIZONTAL_HATCH:
262 m_vAreaBundle.usSymbol = PATSYM_HORIZ;
263 m_vAreaBundle.usSet = LCID_DEFAULT;
264 flAttrMask = ABB_COLOR | ABB_BACK_COLOR | ABB_MIX_MODE | ABB_BACK_MIX_MODE | ABB_SYMBOL;
265 flDefMask = ABB_SET | ABB_REF_POINT;
266 break;
267
268 case wxVERTICAL_HATCH:
269 m_vAreaBundle.usSymbol = PATSYM_VERT;
270 m_vAreaBundle.usSet = LCID_DEFAULT;
271 flAttrMask = ABB_COLOR | ABB_BACK_COLOR | ABB_MIX_MODE | ABB_BACK_MIX_MODE | ABB_SYMBOL;
272 flDefMask = ABB_SET | ABB_REF_POINT;
273 break;
274
275 default:
276 m_vAreaBundle.usSymbol = PATSYM_SOLID;
277 m_vAreaBundle.usSet = LCID_DEFAULT;
278 flAttrMask = ABB_COLOR | ABB_BACK_COLOR | ABB_MIX_MODE | ABB_BACK_MIX_MODE | ABB_SYMBOL;
279 flDefMask = ABB_SET | ABB_REF_POINT;
280 break;
281 }
282
283 m_vAreaBundle.lColor = vPmColour;
284 m_vAreaBundle.lBackColor = RGB_WHITE;
285 m_vAreaBundle.usMixMode = FM_OVERPAINT;
286 m_vAreaBundle.usBackMixMode = BM_OVERPAINT;
287
288 bOk = ::GpiSetAttrs( M_PENDATA->m_hPen
289 ,PRIM_AREA
290 ,flAttrMask
291 ,flDefMask
292 ,&m_vAreaBundle
293 );
294 if (!bOk)
295 {
296 vError = ::WinGetLastError(vHabmain);
297 sError = wxPMErrorToStr(vError);
298 wxLogError("Can't set Gpi attributes for an AREABUNDLE. Error: %s\n", sError);
299 }
300 return bOk;
301 }
302 return FALSE;
303 } // end of wxPen::RealizeResource
304
305 WXHANDLE wxPen::GetResourceHandle()
306 {
307 if (!M_PENDATA)
308 return 0;
309 else
310 return (WXHANDLE)M_PENDATA->m_hPen;
311 } // end of wxPen::GetResourceHandle
312
313 bool wxPen::FreeResource(
314 bool bForce
315 )
316 {
317 if (M_PENDATA && (M_PENDATA->m_hPen != 0))
318 {
319 M_PENDATA->m_hPen = 0;
320 return TRUE;
321 }
322 else return FALSE;
323 } // end of wxPen::FreeResource
324
325 bool wxPen::IsFree() const
326 {
327 return (M_PENDATA && M_PENDATA->m_hPen == 0);
328 }
329
330 void wxPen::Unshare()
331 {
332 // Don't change shared data
333 if (!m_refData)
334 {
335 m_refData = new wxPenRefData();
336 }
337 else
338 {
339 wxPenRefData* ref = new wxPenRefData(*(wxPenRefData*)m_refData);
340 UnRef();
341 m_refData = ref;
342 }
343 } // end of wxPen::Unshare
344
345 void wxPen::SetColour(
346 const wxColour& rColour
347 )
348 {
349 Unshare();
350 M_PENDATA->m_vColour = rColour;
351 RealizeResource();
352 } // end of wxPen::SetColour
353
354 void wxPen::SetColour(
355 unsigned char cRed
356 , unsigned char cGreen
357 , unsigned char cBlue
358 )
359 {
360 Unshare();
361 M_PENDATA->m_vColour.Set(cRed, cGreen, cBlue);
362 RealizeResource();
363 } // end of wxPen::SetColour
364
365 void wxPen::SetPS(
366 HPS hPS
367 )
368 {
369 Unshare();
370 if (M_PENDATA->m_hPen)
371 ::GpiDestroyPS(M_PENDATA->m_hPen);
372 M_PENDATA->m_hPen = hPS;
373 RealizeResource();
374 } // end of WxWinGdi_CPen::SetPS
375
376 void wxPen::SetWidth(
377 int nWidth
378 )
379 {
380 Unshare();
381 M_PENDATA->m_nWidth = nWidth;
382 RealizeResource();
383 } // end of wxPen::SetWidth
384
385 void wxPen::SetStyle(
386 int nStyle
387 )
388 {
389 Unshare();
390 M_PENDATA->m_nStyle = nStyle;
391 RealizeResource();
392 } // end of wxPen::SetStyle
393
394 void wxPen::SetStipple(
395 const wxBitmap& rStipple
396 )
397 {
398 Unshare();
399 M_PENDATA->m_vStipple = rStipple;
400 M_PENDATA->m_nStyle = wxSTIPPLE;
401 RealizeResource();
402 } // end of wxPen::SetStipple
403
404 void wxPen::SetDashes(
405 int nNbDashes
406 , const wxDash* pDash
407 )
408 {
409 //
410 // Does nothing under OS/2
411 //
412 } // end of wxPen::SetDashes
413
414 void wxPen::SetJoin(
415 int nJoin
416 )
417 {
418 Unshare();
419 M_PENDATA->m_nJoin = nJoin;
420 RealizeResource();
421 } // end of wxPen::SetJoin
422
423 void wxPen::SetCap(
424 int nCap
425 )
426 {
427 Unshare();
428 M_PENDATA->m_nCap = nCap;
429 RealizeResource();
430 } // end of wxPen::SetCap
431
432 int wx2os2PenStyle(
433 int nWxStyle
434 )
435 {
436 int nPMStyle = 0;
437
438 switch (nWxStyle)
439 {
440 case wxDOT:
441 nPMStyle = LINETYPE_DOT;
442 break;
443
444 case wxDOT_DASH:
445 nPMStyle = LINETYPE_DASHDOT;
446 break;
447
448 case wxSHORT_DASH:
449 nPMStyle = LINETYPE_SHORTDASH;
450 break;
451
452 case wxLONG_DASH:
453 nPMStyle = LINETYPE_LONGDASH;
454 break;
455
456 case wxTRANSPARENT:
457 nPMStyle = LINETYPE_INVISIBLE;
458 break;
459
460 case wxUSER_DASH:
461 nPMStyle = LINETYPE_DASHDOUBLEDOT; // We must make a choice... This is mine!
462 break;
463
464 case wxSOLID:
465 default:
466 nPMStyle = LINETYPE_SOLID;
467 break;
468 }
469 return nPMStyle;
470 } // end of wx2os2PenStyle
471
472