]>
git.saurik.com Git - wxWidgets.git/blob - src/os2/pen.cpp
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()
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
90 const wxBitmap
& rStipple
94 m_refData
= new wxPenRefData
;
96 M_PENDATA
->m_vStipple
= rStipple
;
97 M_PENDATA
->m_nWidth
= nWidth
;
98 M_PENDATA
->m_nStyle
= wxSTIPPLE
;
99 M_PENDATA
->m_nJoin
= wxJOIN_ROUND
;
100 M_PENDATA
->m_nCap
= wxCAP_ROUND
;
101 M_PENDATA
->m_hPen
= 0;
104 } // end of wxPen::wxPen
110 bool wxPen::RealizeResource()
116 if (M_PENDATA
&& M_PENDATA
->m_hPen
== 0L)
118 SIZEL vSize
= {0, 0};
119 DEVOPENSTRUC vDop
= {0L, "DISPLAY", NULL
, 0L, 0L, 0L, 0L, 0L, 0L};
120 HDC hDC
= ::DevOpenDC( vHabmain
127 M_PENDATA
->m_hPen
= (WXHPEN
)::GpiCreatePS( vHabmain
130 ,PU_PELS
| GPIT_MICRO
| GPIA_ASSOC
136 // Set the color table to RGB mode
138 if (!::GpiCreateLogColorTable( (HPS
)M_PENDATA
->m_hPen
146 vError
= ::WinGetLastError(vHabmain
);
147 sError
= wxPMErrorToStr(vError
);
148 wxLogError(_T("Unable to set current color table to RGB mode. Error: %s\n"), sError
.c_str());
151 if (M_PENDATA
->m_nStyle
== wxTRANSPARENT
)
156 COLORREF vPmColour
= 0L;
157 USHORT uLineType
= (USHORT
)wx2os2PenStyle(M_PENDATA
->m_nStyle
);
159 vPmColour
= M_PENDATA
->m_vColour
.GetPixel();
163 switch(M_PENDATA
->m_nJoin
)
166 uJoin
= LINEJOIN_BEVEL
;
170 uJoin
= LINEJOIN_MITRE
;
174 uJoin
= LINEJOIN_ROUND
;
180 switch(M_PENDATA
->m_nCap
)
182 case wxCAP_PROJECTING
:
183 uCap
= LINEEND_SQUARE
;
191 uCap
= LINEEND_ROUND
;
194 m_vLineBundle
.lColor
= (LONG
)vPmColour
;
195 m_vLineBundle
.usMixMode
= FM_OVERPAINT
;
196 if (M_PENDATA
->m_nWidth
< 1)
197 M_PENDATA
->m_nWidth
= 1;
198 m_vLineBundle
.fxWidth
= M_PENDATA
->m_nWidth
;
199 m_vLineBundle
.lGeomWidth
= M_PENDATA
->m_nWidth
;
200 m_vLineBundle
.usType
= uLineType
;
201 m_vLineBundle
.usEnd
= uCap
;
202 m_vLineBundle
.usJoin
= uJoin
;
204 bOk
= ::GpiSetAttrs( M_PENDATA
->m_hPen
206 ,LBB_COLOR
| LBB_MIX_MODE
| LBB_WIDTH
| LBB_GEOM_WIDTH
| LBB_TYPE
| LBB_END
| LBB_JOIN
212 vError
= ::WinGetLastError(vHabmain
);
213 sError
= wxPMErrorToStr(vError
);
214 wxLogError(_T("Can't set Gpi attributes for a LINEBUNDLE. Error: %s\n"), sError
.c_str());
218 ULONG flAttrMask
= 0L;
219 ULONG flDefMask
= 0L;
220 switch(M_PENDATA
->m_nStyle
)
223 ::GpiSetBitmapId( M_PENDATA
->m_hPen
224 ,(USHORT
)M_PENDATA
->m_vStipple
.GetHBITMAP()
225 ,(USHORT
)M_PENDATA
->m_vStipple
.GetId()
227 ::GpiSetPatternSet( M_PENDATA
->m_hPen
228 ,(USHORT
)M_PENDATA
->m_vStipple
.GetId()
230 flAttrMask
= ABB_COLOR
| ABB_BACK_COLOR
| ABB_MIX_MODE
| ABB_BACK_MIX_MODE
| ABB_SET
| ABB_SYMBOL
;
231 flDefMask
= ABB_REF_POINT
;
234 case wxBDIAGONAL_HATCH
:
235 m_vAreaBundle
.usSymbol
= PATSYM_DIAG3
;
236 m_vAreaBundle
.usSet
= LCID_DEFAULT
;
237 flAttrMask
= ABB_COLOR
| ABB_BACK_COLOR
| ABB_MIX_MODE
| ABB_BACK_MIX_MODE
| ABB_SYMBOL
;
238 flDefMask
= ABB_SET
| ABB_REF_POINT
;
241 case wxCROSSDIAG_HATCH
:
242 m_vAreaBundle
.usSymbol
= PATSYM_DIAGHATCH
;
243 m_vAreaBundle
.usSet
= LCID_DEFAULT
;
244 flAttrMask
= ABB_COLOR
| ABB_BACK_COLOR
| ABB_MIX_MODE
| ABB_BACK_MIX_MODE
| ABB_SYMBOL
;
245 flDefMask
= ABB_SET
| ABB_REF_POINT
;
248 case wxFDIAGONAL_HATCH
:
249 m_vAreaBundle
.usSymbol
= PATSYM_DIAG1
;
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
;
256 m_vAreaBundle
.usSymbol
= PATSYM_HATCH
;
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 wxHORIZONTAL_HATCH
:
263 m_vAreaBundle
.usSymbol
= PATSYM_HORIZ
;
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 wxVERTICAL_HATCH
:
270 m_vAreaBundle
.usSymbol
= PATSYM_VERT
;
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
;
277 m_vAreaBundle
.usSymbol
= PATSYM_SOLID
;
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
;
284 m_vAreaBundle
.lColor
= vPmColour
;
285 m_vAreaBundle
.lBackColor
= RGB_WHITE
;
286 m_vAreaBundle
.usMixMode
= FM_OVERPAINT
;
287 m_vAreaBundle
.usBackMixMode
= BM_OVERPAINT
;
289 bOk
= ::GpiSetAttrs( M_PENDATA
->m_hPen
297 vError
= ::WinGetLastError(vHabmain
);
298 sError
= wxPMErrorToStr(vError
);
299 wxLogError(_T("Can't set Gpi attributes for an AREABUNDLE. Error: %s\n"), sError
.c_str());
305 } // end of wxPen::RealizeResource
307 WXHANDLE
wxPen::GetResourceHandle()
312 return (WXHANDLE
)M_PENDATA
->m_hPen
;
313 } // end of wxPen::GetResourceHandle
315 bool wxPen::FreeResource( bool WXUNUSED(bForce
) )
317 if (M_PENDATA
&& (M_PENDATA
->m_hPen
!= 0))
319 M_PENDATA
->m_hPen
= 0;
323 } // end of wxPen::FreeResource
325 bool wxPen::IsFree() const
327 return (M_PENDATA
&& M_PENDATA
->m_hPen
== 0);
330 void wxPen::Unshare()
332 // Don't change shared data
335 m_refData
= new wxPenRefData();
339 wxPenRefData
* ref
= new wxPenRefData(*(wxPenRefData
*)m_refData
);
343 } // end of wxPen::Unshare
345 void wxPen::SetColour( const wxColour
& rColour
)
348 M_PENDATA
->m_vColour
= rColour
;
350 } // end of wxPen::SetColour
352 void wxPen::SetColour( unsigned char cRed
, unsigned char cGreen
, unsigned char cBlue
)
355 M_PENDATA
->m_vColour
.Set(cRed
, cGreen
, cBlue
);
357 } // end of wxPen::SetColour
359 void wxPen::SetPS( HPS hPS
)
362 if (M_PENDATA
->m_hPen
)
363 ::GpiDestroyPS(M_PENDATA
->m_hPen
);
364 M_PENDATA
->m_hPen
= hPS
;
366 } // end of WxWinGdi_CPen::SetPS
368 void wxPen::SetWidth(
373 M_PENDATA
->m_nWidth
= nWidth
;
375 } // end of wxPen::SetWidth
377 void wxPen::SetStyle(
382 M_PENDATA
->m_nStyle
= nStyle
;
384 } // end of wxPen::SetStyle
386 void wxPen::SetStipple(
387 const wxBitmap
& rStipple
391 M_PENDATA
->m_vStipple
= rStipple
;
392 M_PENDATA
->m_nStyle
= wxSTIPPLE
;
394 } // end of wxPen::SetStipple
396 void wxPen::SetDashes( int WXUNUSED(nNbDashes
),
397 const wxDash
* WXUNUSED(pDash
) )
400 // Does nothing under OS/2
402 } // end of wxPen::SetDashes
409 M_PENDATA
->m_nJoin
= nJoin
;
411 } // end of wxPen::SetJoin
418 M_PENDATA
->m_nCap
= nCap
;
420 } // end of wxPen::SetCap
431 nPMStyle
= LINETYPE_DOT
;
435 nPMStyle
= LINETYPE_DASHDOT
;
439 nPMStyle
= LINETYPE_SHORTDASH
;
443 nPMStyle
= LINETYPE_LONGDASH
;
447 nPMStyle
= LINETYPE_INVISIBLE
;
451 nPMStyle
= LINETYPE_DASHDOUBLEDOT
; // We must make a choice... This is mine!
456 nPMStyle
= LINETYPE_SOLID
;
460 } // end of wx2os2PenStyle