]>
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"
24 #include "wx/os2/private.h"
27 IMPLEMENT_DYNAMIC_CLASS(wxPen
, wxGDIObject
)
29 wxPenRefData::wxPenRefData()
33 m_nJoin
= wxJOIN_ROUND
;
34 m_nCap
= wxCAP_ROUND
;
36 m_dash
= (wxDash
*)NULL
;
38 } // end of wxPenRefData::wxPenRefData
40 wxPenRefData::wxPenRefData(
41 const wxPenRefData
& rData
44 m_nStyle
= rData
.m_nStyle
;
45 m_nWidth
= rData
.m_nWidth
;
46 m_nJoin
= rData
.m_nJoin
;
47 m_nCap
= rData
.m_nCap
;
48 m_nbDash
= rData
.m_nbDash
;
49 m_dash
= rData
.m_dash
;
50 m_vColour
= rData
.m_vColour
;
52 } // end of wxPenRefData::wxPenRefData
54 wxPenRefData::~wxPenRefData()
56 } // end of wxPenRefData::~wxPenRefData
64 wxThePenList
->AddPen(this);
65 } // end of wxPen::wxPen
70 wxThePenList
->RemovePen(this);
71 } // end of wxPen::wxPen
73 // Should implement Create
75 const wxColour
& rColour
80 m_refData
= new wxPenRefData
;
82 M_PENDATA
->m_vColour
= rColour
;
83 M_PENDATA
->m_nWidth
= nWidth
;
84 M_PENDATA
->m_nStyle
= nStyle
;
85 M_PENDATA
->m_nJoin
= wxJOIN_ROUND
;
86 M_PENDATA
->m_nCap
= wxCAP_ROUND
;
87 M_PENDATA
->m_hPen
= 0L;
92 wxThePenList
->AddPen(this);
93 } // end of wxPen::wxPen
96 const wxBitmap
& rStipple
100 m_refData
= new wxPenRefData
;
102 M_PENDATA
->m_vStipple
= rStipple
;
103 M_PENDATA
->m_nWidth
= nWidth
;
104 M_PENDATA
->m_nStyle
= wxSTIPPLE
;
105 M_PENDATA
->m_nJoin
= wxJOIN_ROUND
;
106 M_PENDATA
->m_nCap
= wxCAP_ROUND
;
107 M_PENDATA
->m_hPen
= 0;
112 wxThePenList
->AddPen(this);
113 } // end of wxPen::wxPen
119 bool wxPen::RealizeResource()
125 if (M_PENDATA
&& M_PENDATA
->m_hPen
== 0L)
127 SIZEL vSize
= {0, 0};
128 DEVOPENSTRUC vDop
= {0L, "DISPLAY", NULL
, 0L, 0L, 0L, 0L, 0L, 0L};
129 HDC hDC
= ::DevOpenDC( vHabmain
136 M_PENDATA
->m_hPen
= (WXHPEN
)::GpiCreatePS( vHabmain
139 ,PU_PELS
| GPIT_MICRO
| GPIA_ASSOC
145 // Set the color table to RGB mode
147 if (!::GpiCreateLogColorTable( (HPS
)M_PENDATA
->m_hPen
155 vError
= ::WinGetLastError(vHabmain
);
156 sError
= wxPMErrorToStr(vError
);
157 wxLogError(_T("Unable to set current color table to RGB mode. Error: %s\n"), sError
.c_str());
160 if (M_PENDATA
->m_nStyle
== wxTRANSPARENT
)
165 COLORREF vPmColour
= 0L;
166 USHORT uLineType
= (USHORT
)wx2os2PenStyle(M_PENDATA
->m_nStyle
);
168 vPmColour
= M_PENDATA
->m_vColour
.GetPixel();
172 switch(M_PENDATA
->m_nJoin
)
175 uJoin
= LINEJOIN_BEVEL
;
179 uJoin
= LINEJOIN_MITRE
;
183 uJoin
= LINEJOIN_ROUND
;
189 switch(M_PENDATA
->m_nCap
)
191 case wxCAP_PROJECTING
:
192 uCap
= LINEEND_SQUARE
;
200 uCap
= LINEEND_ROUND
;
203 m_vLineBundle
.lColor
= (LONG
)vPmColour
;
204 m_vLineBundle
.usMixMode
= FM_OVERPAINT
;
205 m_vLineBundle
.fxWidth
= M_PENDATA
->m_nWidth
;
206 m_vLineBundle
.lGeomWidth
= M_PENDATA
->m_nWidth
;
207 m_vLineBundle
.usType
= uLineType
;
208 m_vLineBundle
.usEnd
= uCap
;
209 m_vLineBundle
.usJoin
= uJoin
;
211 bOk
= ::GpiSetAttrs( M_PENDATA
->m_hPen
213 ,LBB_COLOR
| LBB_MIX_MODE
| LBB_WIDTH
| LBB_GEOM_WIDTH
| LBB_TYPE
| LBB_END
| LBB_JOIN
219 vError
= ::WinGetLastError(vHabmain
);
220 sError
= wxPMErrorToStr(vError
);
221 wxLogError(_T("Can't set Gpi attributes for a LINEBUNDLE. Error: %s\n"), sError
.c_str());
225 ULONG flAttrMask
= 0L;
226 ULONG flDefMask
= 0L;
227 switch(M_PENDATA
->m_nStyle
)
230 ::GpiSetBitmapId( M_PENDATA
->m_hPen
231 ,(USHORT
)M_PENDATA
->m_vStipple
.GetHBITMAP()
232 ,(USHORT
)M_PENDATA
->m_vStipple
.GetId()
234 ::GpiSetPatternSet( M_PENDATA
->m_hPen
235 ,(USHORT
)M_PENDATA
->m_vStipple
.GetId()
237 flAttrMask
= ABB_COLOR
| ABB_BACK_COLOR
| ABB_MIX_MODE
| ABB_BACK_MIX_MODE
| ABB_SET
| ABB_SYMBOL
;
238 flDefMask
= ABB_REF_POINT
;
241 case wxBDIAGONAL_HATCH
:
242 m_vAreaBundle
.usSymbol
= PATSYM_DIAG3
;
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 wxCROSSDIAG_HATCH
:
249 m_vAreaBundle
.usSymbol
= PATSYM_DIAGHATCH
;
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 wxFDIAGONAL_HATCH
:
256 m_vAreaBundle
.usSymbol
= PATSYM_DIAG1
;
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
;
263 m_vAreaBundle
.usSymbol
= PATSYM_HATCH
;
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 wxHORIZONTAL_HATCH
:
270 m_vAreaBundle
.usSymbol
= PATSYM_HORIZ
;
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 wxVERTICAL_HATCH
:
277 m_vAreaBundle
.usSymbol
= PATSYM_VERT
;
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
.usSymbol
= PATSYM_SOLID
;
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
.lColor
= vPmColour
;
292 m_vAreaBundle
.lBackColor
= RGB_WHITE
;
293 m_vAreaBundle
.usMixMode
= FM_OVERPAINT
;
294 m_vAreaBundle
.usBackMixMode
= BM_OVERPAINT
;
296 bOk
= ::GpiSetAttrs( M_PENDATA
->m_hPen
304 vError
= ::WinGetLastError(vHabmain
);
305 sError
= wxPMErrorToStr(vError
);
306 wxLogError(_T("Can't set Gpi attributes for an AREABUNDLE. Error: %s\n"), sError
.c_str());
312 } // end of wxPen::RealizeResource
314 WXHANDLE
wxPen::GetResourceHandle()
319 return (WXHANDLE
)M_PENDATA
->m_hPen
;
320 } // end of wxPen::GetResourceHandle
322 bool wxPen::FreeResource( bool WXUNUSED(bForce
) )
324 if (M_PENDATA
&& (M_PENDATA
->m_hPen
!= 0))
326 M_PENDATA
->m_hPen
= 0;
330 } // end of wxPen::FreeResource
332 bool wxPen::IsFree() const
334 return (M_PENDATA
&& M_PENDATA
->m_hPen
== 0);
337 void wxPen::Unshare()
339 // Don't change shared data
342 m_refData
= new wxPenRefData();
346 wxPenRefData
* ref
= new wxPenRefData(*(wxPenRefData
*)m_refData
);
350 } // end of wxPen::Unshare
352 void wxPen::SetColour( const wxColour
& rColour
)
355 M_PENDATA
->m_vColour
= rColour
;
357 } // end of wxPen::SetColour
359 void wxPen::SetColour( unsigned char cRed
, unsigned char cGreen
, unsigned char cBlue
)
362 M_PENDATA
->m_vColour
.Set(cRed
, cGreen
, cBlue
);
364 } // end of wxPen::SetColour
366 void wxPen::SetPS( HPS hPS
)
369 if (M_PENDATA
->m_hPen
)
370 ::GpiDestroyPS(M_PENDATA
->m_hPen
);
371 M_PENDATA
->m_hPen
= hPS
;
373 } // end of WxWinGdi_CPen::SetPS
375 void wxPen::SetWidth(
380 M_PENDATA
->m_nWidth
= nWidth
;
382 } // end of wxPen::SetWidth
384 void wxPen::SetStyle(
389 M_PENDATA
->m_nStyle
= nStyle
;
391 } // end of wxPen::SetStyle
393 void wxPen::SetStipple(
394 const wxBitmap
& rStipple
398 M_PENDATA
->m_vStipple
= rStipple
;
399 M_PENDATA
->m_nStyle
= wxSTIPPLE
;
401 } // end of wxPen::SetStipple
403 void wxPen::SetDashes( int WXUNUSED(nNbDashes
),
404 const wxDash
* WXUNUSED(pDash
) )
407 // Does nothing under OS/2
409 } // end of wxPen::SetDashes
416 M_PENDATA
->m_nJoin
= nJoin
;
418 } // end of wxPen::SetJoin
425 M_PENDATA
->m_nCap
= nCap
;
427 } // end of wxPen::SetCap
438 nPMStyle
= LINETYPE_DOT
;
442 nPMStyle
= LINETYPE_DASHDOT
;
446 nPMStyle
= LINETYPE_SHORTDASH
;
450 nPMStyle
= LINETYPE_LONGDASH
;
454 nPMStyle
= LINETYPE_INVISIBLE
;
458 nPMStyle
= LINETYPE_DASHDOUBLEDOT
; // We must make a choice... This is mine!
463 nPMStyle
= LINETYPE_SOLID
;
467 } // end of wx2os2PenStyle