1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/os2/pen.cpp
4 // Author: David Webster
8 // Copyright: (c) David Webster
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
25 #include "wx/os2/private.h"
28 IMPLEMENT_DYNAMIC_CLASS(wxPen
, wxGDIObject
)
30 wxPenRefData::wxPenRefData()
32 m_nStyle
= wxPENSTYLE_SOLID
;
34 m_nJoin
= wxJOIN_ROUND
;
35 m_nCap
= wxCAP_ROUND
;
37 m_dash
= (wxDash
*)NULL
;
39 } // end of wxPenRefData::wxPenRefData
41 wxPenRefData::wxPenRefData(
42 const wxPenRefData
& rData
45 m_nStyle
= rData
.m_nStyle
;
46 m_nWidth
= rData
.m_nWidth
;
47 m_nJoin
= rData
.m_nJoin
;
48 m_nCap
= rData
.m_nCap
;
49 m_nbDash
= rData
.m_nbDash
;
50 m_dash
= rData
.m_dash
;
51 m_vColour
= rData
.m_vColour
;
53 } // end of wxPenRefData::wxPenRefData
55 wxPenRefData::~wxPenRefData()
57 } // end of wxPenRefData::~wxPenRefData
64 } // end of wxPen::wxPen
68 } // end of wxPen::wxPen
70 // Should implement Create
72 const wxColour
& rColour
77 m_refData
= new wxPenRefData
;
79 M_PENDATA
->m_vColour
= rColour
;
80 M_PENDATA
->m_nWidth
= nWidth
;
81 M_PENDATA
->m_nStyle
= nStyle
;
82 M_PENDATA
->m_nJoin
= wxJOIN_ROUND
;
83 M_PENDATA
->m_nCap
= wxCAP_ROUND
;
84 M_PENDATA
->m_hPen
= 0L;
87 } // end of wxPen::wxPen
89 wxPen::wxPen(const wxColour
& colour
, int width
, wxBrushStyle style
)
91 m_refData
= new wxPenRefData
;
93 M_PENDATA
->m_vColour
= colour
;
94 M_PENDATA
->m_nWidth
= width
;
95 M_PENDATA
->m_nStyle
= (wxPenStyle
)nStyle
;
96 M_PENDATA
->m_nJoin
= wxJOIN_ROUND
;
97 M_PENDATA
->m_nCap
= wxCAP_ROUND
;
98 M_PENDATA
->m_hPen
= 0L;
104 const wxBitmap
& rStipple
108 m_refData
= new wxPenRefData
;
110 M_PENDATA
->m_vStipple
= rStipple
;
111 M_PENDATA
->m_nWidth
= nWidth
;
112 M_PENDATA
->m_nStyle
= wxSTIPPLE
;
113 M_PENDATA
->m_nJoin
= wxJOIN_ROUND
;
114 M_PENDATA
->m_nCap
= wxCAP_ROUND
;
115 M_PENDATA
->m_hPen
= 0;
118 } // end of wxPen::wxPen
124 bool wxPen::RealizeResource()
130 if (M_PENDATA
&& M_PENDATA
->m_hPen
== 0L)
132 SIZEL vSize
= {0, 0};
133 DEVOPENSTRUC vDop
= {0L, "DISPLAY", NULL
, 0L, 0L, 0L, 0L, 0L, 0L};
134 HDC hDC
= ::DevOpenDC( vHabmain
141 M_PENDATA
->m_hPen
= (WXHPEN
)::GpiCreatePS( vHabmain
144 ,PU_PELS
| GPIT_MICRO
| GPIA_ASSOC
150 // Set the color table to RGB mode
152 if (!::GpiCreateLogColorTable( (HPS
)M_PENDATA
->m_hPen
160 vError
= ::WinGetLastError(vHabmain
);
161 sError
= wxPMErrorToStr(vError
);
162 wxLogError(_T("Unable to set current color table to RGB mode. Error: %s\n"), sError
.c_str());
165 if (M_PENDATA
->m_nStyle
== wxPENSTYLE_TRANSPARENT
)
170 COLORREF vPmColour
= 0L;
171 USHORT uLineType
= (USHORT
)wx2os2PenStyle(M_PENDATA
->m_nStyle
);
173 vPmColour
= M_PENDATA
->m_vColour
.GetPixel();
177 switch(M_PENDATA
->m_nJoin
)
180 uJoin
= LINEJOIN_BEVEL
;
184 uJoin
= LINEJOIN_MITRE
;
188 uJoin
= LINEJOIN_ROUND
;
194 switch(M_PENDATA
->m_nCap
)
196 case wxCAP_PROJECTING
:
197 uCap
= LINEEND_SQUARE
;
205 uCap
= LINEEND_ROUND
;
208 m_vLineBundle
.lColor
= (LONG
)vPmColour
;
209 m_vLineBundle
.usMixMode
= FM_OVERPAINT
;
210 if (M_PENDATA
->m_nWidth
< 1)
211 M_PENDATA
->m_nWidth
= 1;
212 m_vLineBundle
.fxWidth
= M_PENDATA
->m_nWidth
;
213 m_vLineBundle
.lGeomWidth
= M_PENDATA
->m_nWidth
;
214 m_vLineBundle
.usType
= uLineType
;
215 m_vLineBundle
.usEnd
= uCap
;
216 m_vLineBundle
.usJoin
= uJoin
;
218 bOk
= ::GpiSetAttrs( M_PENDATA
->m_hPen
220 ,LBB_COLOR
| LBB_MIX_MODE
| LBB_WIDTH
| LBB_GEOM_WIDTH
| LBB_TYPE
| LBB_END
| LBB_JOIN
226 vError
= ::WinGetLastError(vHabmain
);
227 sError
= wxPMErrorToStr(vError
);
228 wxLogError(_T("Can't set Gpi attributes for a LINEBUNDLE. Error: %s\n"), sError
.c_str());
232 ULONG flAttrMask
= 0L;
233 ULONG flDefMask
= 0L;
234 switch(M_PENDATA
->m_nStyle
)
236 case wxPENSTYLE_STIPPLE
:
237 ::GpiSetBitmapId( M_PENDATA
->m_hPen
238 ,(USHORT
)M_PENDATA
->m_vStipple
.GetHBITMAP()
239 ,(USHORT
)M_PENDATA
->m_vStipple
.GetId()
241 ::GpiSetPatternSet( M_PENDATA
->m_hPen
242 ,(USHORT
)M_PENDATA
->m_vStipple
.GetId()
244 flAttrMask
= ABB_COLOR
| ABB_BACK_COLOR
| ABB_MIX_MODE
| ABB_BACK_MIX_MODE
| ABB_SET
| ABB_SYMBOL
;
245 flDefMask
= ABB_REF_POINT
;
248 case wxPENSTYLE_BDIAGONAL_HATCH
:
249 m_vAreaBundle
.usSymbol
= PATSYM_DIAG3
;
250 m_vAreaBundle
.usSet
= LCID_DEFAULT
;
251 flAttrMask
= ABB_COLOR
| ABB_BACK_COLOR
| ABB_MIX_MODE
| ABB_BACK_MIX_MODE
| ABB_SYMBOL
;
252 flDefMask
= ABB_SET
| ABB_REF_POINT
;
255 case wxPENSTYLE_CROSSDIAG_HATCH
:
256 m_vAreaBundle
.usSymbol
= PATSYM_DIAGHATCH
;
257 m_vAreaBundle
.usSet
= LCID_DEFAULT
;
258 flAttrMask
= ABB_COLOR
| ABB_BACK_COLOR
| ABB_MIX_MODE
| ABB_BACK_MIX_MODE
| ABB_SYMBOL
;
259 flDefMask
= ABB_SET
| ABB_REF_POINT
;
262 case wxPENSTYLE_FDIAGONAL_HATCH
:
263 m_vAreaBundle
.usSymbol
= PATSYM_DIAG1
;
264 m_vAreaBundle
.usSet
= LCID_DEFAULT
;
265 flAttrMask
= ABB_COLOR
| ABB_BACK_COLOR
| ABB_MIX_MODE
| ABB_BACK_MIX_MODE
| ABB_SYMBOL
;
266 flDefMask
= ABB_SET
| ABB_REF_POINT
;
269 case wxPENSTYLE_CROSS_HATCH
:
270 m_vAreaBundle
.usSymbol
= PATSYM_HATCH
;
271 m_vAreaBundle
.usSet
= LCID_DEFAULT
;
272 flAttrMask
= ABB_COLOR
| ABB_BACK_COLOR
| ABB_MIX_MODE
| ABB_BACK_MIX_MODE
| ABB_SYMBOL
;
273 flDefMask
= ABB_SET
| ABB_REF_POINT
;
276 case wxPENSTYLE_HORIZONTAL_HATCH
:
277 m_vAreaBundle
.usSymbol
= PATSYM_HORIZ
;
278 m_vAreaBundle
.usSet
= LCID_DEFAULT
;
279 flAttrMask
= ABB_COLOR
| ABB_BACK_COLOR
| ABB_MIX_MODE
| ABB_BACK_MIX_MODE
| ABB_SYMBOL
;
280 flDefMask
= ABB_SET
| ABB_REF_POINT
;
283 case wxPENSTYLE_VERTICAL_HATCH
:
284 m_vAreaBundle
.usSymbol
= PATSYM_VERT
;
285 m_vAreaBundle
.usSet
= LCID_DEFAULT
;
286 flAttrMask
= ABB_COLOR
| ABB_BACK_COLOR
| ABB_MIX_MODE
| ABB_BACK_MIX_MODE
| ABB_SYMBOL
;
287 flDefMask
= ABB_SET
| ABB_REF_POINT
;
291 m_vAreaBundle
.usSymbol
= PATSYM_SOLID
;
292 m_vAreaBundle
.usSet
= LCID_DEFAULT
;
293 flAttrMask
= ABB_COLOR
| ABB_BACK_COLOR
| ABB_MIX_MODE
| ABB_BACK_MIX_MODE
| ABB_SYMBOL
;
294 flDefMask
= ABB_SET
| ABB_REF_POINT
;
298 m_vAreaBundle
.lColor
= vPmColour
;
299 m_vAreaBundle
.lBackColor
= RGB_WHITE
;
300 m_vAreaBundle
.usMixMode
= FM_OVERPAINT
;
301 m_vAreaBundle
.usBackMixMode
= BM_OVERPAINT
;
303 bOk
= ::GpiSetAttrs( M_PENDATA
->m_hPen
311 vError
= ::WinGetLastError(vHabmain
);
312 sError
= wxPMErrorToStr(vError
);
313 wxLogError(_T("Can't set Gpi attributes for an AREABUNDLE. Error: %s\n"), sError
.c_str());
319 } // end of wxPen::RealizeResource
321 WXHANDLE
wxPen::GetResourceHandle() const
326 return (WXHANDLE
)M_PENDATA
->m_hPen
;
327 } // end of wxPen::GetResourceHandle
329 bool wxPen::FreeResource( bool WXUNUSED(bForce
) )
331 if (M_PENDATA
&& (M_PENDATA
->m_hPen
!= 0))
333 M_PENDATA
->m_hPen
= 0;
337 } // end of wxPen::FreeResource
339 bool wxPen::IsFree() const
341 return (M_PENDATA
&& M_PENDATA
->m_hPen
== 0);
344 wxGDIRefData
* wxPen::CreateGDIRefData() const
346 return new wxPenRefData
;
349 wxGDIRefData
* wxPen::CloneGDIRefData(const wxGDIRefData
* data
) const
351 return new wxPenRefData(*wx_static_cast(const wxPenRefData
*, data
));
354 void wxPen::SetColour( const wxColour
& rColour
)
357 M_PENDATA
->m_vColour
= rColour
;
359 } // end of wxPen::SetColour
361 void wxPen::SetColour( unsigned char cRed
, unsigned char cGreen
, unsigned char cBlue
)
364 M_PENDATA
->m_vColour
.Set(cRed
, cGreen
, cBlue
);
366 } // end of wxPen::SetColour
368 void wxPen::SetPS( HPS hPS
)
371 if (M_PENDATA
->m_hPen
)
372 ::GpiDestroyPS(M_PENDATA
->m_hPen
);
373 M_PENDATA
->m_hPen
= hPS
;
375 } // end of WxWinGdi_CPen::SetPS
377 void wxPen::SetWidth(
382 M_PENDATA
->m_nWidth
= nWidth
;
384 } // end of wxPen::SetWidth
386 void wxPen::SetStyle(
391 M_PENDATA
->m_nStyle
= nStyle
;
393 } // end of wxPen::SetStyle
395 void wxPen::SetStipple(
396 const wxBitmap
& rStipple
400 M_PENDATA
->m_vStipple
= rStipple
;
401 M_PENDATA
->m_nStyle
= wxSTIPPLE
;
403 } // end of wxPen::SetStipple
405 void wxPen::SetDashes( int WXUNUSED(nNbDashes
),
406 const wxDash
* WXUNUSED(pDash
) )
409 // Does nothing under OS/2
411 } // end of wxPen::SetDashes
418 M_PENDATA
->m_nJoin
= nJoin
;
420 } // end of wxPen::SetJoin
427 M_PENDATA
->m_nCap
= nCap
;
429 } // end of wxPen::SetCap
440 nPMStyle
= LINETYPE_DOT
;
443 case wxPENSTYLE_DOT_DASH
:
444 nPMStyle
= LINETYPE_DASHDOT
;
447 case wxPENSTYLE_SHORT_DASH
:
448 nPMStyle
= LINETYPE_SHORTDASH
;
451 case wxPENSTYLE_LONG_DASH
:
452 nPMStyle
= LINETYPE_LONGDASH
;
455 case wxPENSTYLE_TRANSPARENT
:
456 nPMStyle
= LINETYPE_INVISIBLE
;
459 case wxPENSTYLE_USER_DASH
:
460 nPMStyle
= LINETYPE_DASHDOUBLEDOT
; // We must make a choice... This is mine!
463 case wxPENSTYLE_SOLID
:
465 nPMStyle
= LINETYPE_SOLID
;
469 } // end of wx2os2PenStyle