]>
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 } // end of wxPenRefData::wxPenRefData
39 wxPenRefData::wxPenRefData(
40 const wxPenRefData
& rData
43 m_nStyle
= rData
.m_nStyle
;
44 m_nWidth
= rData
.m_nWidth
;
45 m_nJoin
= rData
.m_nJoin
;
46 m_nCap
= rData
.m_nCap
;
47 m_vColour
= rData
.m_vColour
;
49 } // end of wxPenRefData::wxPenRefData
51 wxPenRefData::~wxPenRefData()
53 } // end of wxPenRefData::~wxPenRefData
61 wxThePenList
->AddPen(this);
62 } // end of wxPen::wxPen
67 wxThePenList
->RemovePen(this);
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;
89 wxThePenList
->AddPen(this);
90 } // end of wxPen::wxPen
93 const wxBitmap
& rStipple
97 m_refData
= new wxPenRefData
;
99 M_PENDATA
->m_vStipple
= rStipple
;
100 M_PENDATA
->m_nWidth
= nWidth
;
101 M_PENDATA
->m_nStyle
= wxSTIPPLE
;
102 M_PENDATA
->m_nJoin
= wxJOIN_ROUND
;
103 M_PENDATA
->m_nCap
= wxCAP_ROUND
;
104 M_PENDATA
->m_hPen
= 0;
109 wxThePenList
->AddPen(this);
110 } // end of wxPen::wxPen
116 bool wxPen::RealizeResource()
122 if (M_PENDATA
&& M_PENDATA
->m_hPen
== 0L)
124 SIZEL vSize
= {0, 0};
125 DEVOPENSTRUC vDop
= {0L, "DISPLAY", NULL
, 0L, 0L, 0L, 0L, 0L, 0L};
126 HDC hDC
= ::DevOpenDC( vHabmain
133 M_PENDATA
->m_hPen
= (WXHPEN
)::GpiCreatePS( vHabmain
136 ,PU_PELS
| GPIT_MICRO
| GPIA_ASSOC
142 // Set the color table to RGB mode
144 if (!::GpiCreateLogColorTable( (HPS
)M_PENDATA
->m_hPen
152 vError
= ::WinGetLastError(vHabmain
);
153 sError
= wxPMErrorToStr(vError
);
154 wxLogError(_T("Unable to set current color table to RGB mode. Error: %s\n"), sError
.c_str());
157 if (M_PENDATA
->m_nStyle
== wxTRANSPARENT
)
162 COLORREF vPmColour
= 0L;
163 USHORT uLineType
= (USHORT
)wx2os2PenStyle(M_PENDATA
->m_nStyle
);
165 vPmColour
= M_PENDATA
->m_vColour
.GetPixel();
169 switch(M_PENDATA
->m_nJoin
)
172 uJoin
= LINEJOIN_BEVEL
;
176 uJoin
= LINEJOIN_MITRE
;
180 uJoin
= LINEJOIN_ROUND
;
186 switch(M_PENDATA
->m_nCap
)
188 case wxCAP_PROJECTING
:
189 uCap
= LINEEND_SQUARE
;
197 uCap
= LINEEND_ROUND
;
200 m_vLineBundle
.lColor
= (LONG
)vPmColour
;
201 m_vLineBundle
.usMixMode
= FM_OVERPAINT
;
202 m_vLineBundle
.fxWidth
= M_PENDATA
->m_nWidth
;
203 m_vLineBundle
.lGeomWidth
= M_PENDATA
->m_nWidth
;
204 m_vLineBundle
.usType
= uLineType
;
205 m_vLineBundle
.usEnd
= uCap
;
206 m_vLineBundle
.usJoin
= uJoin
;
208 bOk
= ::GpiSetAttrs( M_PENDATA
->m_hPen
210 ,LBB_COLOR
| LBB_MIX_MODE
| LBB_WIDTH
| LBB_GEOM_WIDTH
| LBB_TYPE
| LBB_END
| LBB_JOIN
216 vError
= ::WinGetLastError(vHabmain
);
217 sError
= wxPMErrorToStr(vError
);
218 wxLogError(_T("Can't set Gpi attributes for a LINEBUNDLE. Error: %s\n"), sError
.c_str());
222 ULONG flAttrMask
= 0L;
223 ULONG flDefMask
= 0L;
224 switch(M_PENDATA
->m_nStyle
)
227 ::GpiSetBitmapId( M_PENDATA
->m_hPen
228 ,(USHORT
)M_PENDATA
->m_vStipple
.GetHBITMAP()
229 ,(USHORT
)M_PENDATA
->m_vStipple
.GetId()
231 ::GpiSetPatternSet( M_PENDATA
->m_hPen
232 ,(USHORT
)M_PENDATA
->m_vStipple
.GetId()
234 flAttrMask
= ABB_COLOR
| ABB_BACK_COLOR
| ABB_MIX_MODE
| ABB_BACK_MIX_MODE
| ABB_SET
| ABB_SYMBOL
;
235 flDefMask
= ABB_REF_POINT
;
238 case wxBDIAGONAL_HATCH
:
239 m_vAreaBundle
.usSymbol
= PATSYM_DIAG3
;
240 m_vAreaBundle
.usSet
= LCID_DEFAULT
;
241 flAttrMask
= ABB_COLOR
| ABB_BACK_COLOR
| ABB_MIX_MODE
| ABB_BACK_MIX_MODE
| ABB_SYMBOL
;
242 flDefMask
= ABB_SET
| ABB_REF_POINT
;
245 case wxCROSSDIAG_HATCH
:
246 m_vAreaBundle
.usSymbol
= PATSYM_DIAGHATCH
;
247 m_vAreaBundle
.usSet
= LCID_DEFAULT
;
248 flAttrMask
= ABB_COLOR
| ABB_BACK_COLOR
| ABB_MIX_MODE
| ABB_BACK_MIX_MODE
| ABB_SYMBOL
;
249 flDefMask
= ABB_SET
| ABB_REF_POINT
;
252 case wxFDIAGONAL_HATCH
:
253 m_vAreaBundle
.usSymbol
= PATSYM_DIAG1
;
254 m_vAreaBundle
.usSet
= LCID_DEFAULT
;
255 flAttrMask
= ABB_COLOR
| ABB_BACK_COLOR
| ABB_MIX_MODE
| ABB_BACK_MIX_MODE
| ABB_SYMBOL
;
256 flDefMask
= ABB_SET
| ABB_REF_POINT
;
260 m_vAreaBundle
.usSymbol
= PATSYM_HATCH
;
261 m_vAreaBundle
.usSet
= LCID_DEFAULT
;
262 flAttrMask
= ABB_COLOR
| ABB_BACK_COLOR
| ABB_MIX_MODE
| ABB_BACK_MIX_MODE
| ABB_SYMBOL
;
263 flDefMask
= ABB_SET
| ABB_REF_POINT
;
266 case wxHORIZONTAL_HATCH
:
267 m_vAreaBundle
.usSymbol
= PATSYM_HORIZ
;
268 m_vAreaBundle
.usSet
= LCID_DEFAULT
;
269 flAttrMask
= ABB_COLOR
| ABB_BACK_COLOR
| ABB_MIX_MODE
| ABB_BACK_MIX_MODE
| ABB_SYMBOL
;
270 flDefMask
= ABB_SET
| ABB_REF_POINT
;
273 case wxVERTICAL_HATCH
:
274 m_vAreaBundle
.usSymbol
= PATSYM_VERT
;
275 m_vAreaBundle
.usSet
= LCID_DEFAULT
;
276 flAttrMask
= ABB_COLOR
| ABB_BACK_COLOR
| ABB_MIX_MODE
| ABB_BACK_MIX_MODE
| ABB_SYMBOL
;
277 flDefMask
= ABB_SET
| ABB_REF_POINT
;
281 m_vAreaBundle
.usSymbol
= PATSYM_SOLID
;
282 m_vAreaBundle
.usSet
= LCID_DEFAULT
;
283 flAttrMask
= ABB_COLOR
| ABB_BACK_COLOR
| ABB_MIX_MODE
| ABB_BACK_MIX_MODE
| ABB_SYMBOL
;
284 flDefMask
= ABB_SET
| ABB_REF_POINT
;
288 m_vAreaBundle
.lColor
= vPmColour
;
289 m_vAreaBundle
.lBackColor
= RGB_WHITE
;
290 m_vAreaBundle
.usMixMode
= FM_OVERPAINT
;
291 m_vAreaBundle
.usBackMixMode
= BM_OVERPAINT
;
293 bOk
= ::GpiSetAttrs( M_PENDATA
->m_hPen
301 vError
= ::WinGetLastError(vHabmain
);
302 sError
= wxPMErrorToStr(vError
);
303 wxLogError(_T("Can't set Gpi attributes for an AREABUNDLE. Error: %s\n"), sError
.c_str());
309 } // end of wxPen::RealizeResource
311 WXHANDLE
wxPen::GetResourceHandle()
316 return (WXHANDLE
)M_PENDATA
->m_hPen
;
317 } // end of wxPen::GetResourceHandle
319 bool wxPen::FreeResource( bool WXUNUSED(bForce
) )
321 if (M_PENDATA
&& (M_PENDATA
->m_hPen
!= 0))
323 M_PENDATA
->m_hPen
= 0;
327 } // end of wxPen::FreeResource
329 bool wxPen::IsFree() const
331 return (M_PENDATA
&& M_PENDATA
->m_hPen
== 0);
334 void wxPen::Unshare()
336 // Don't change shared data
339 m_refData
= new wxPenRefData();
343 wxPenRefData
* ref
= new wxPenRefData(*(wxPenRefData
*)m_refData
);
347 } // end of wxPen::Unshare
349 void wxPen::SetColour( const wxColour
& rColour
)
352 M_PENDATA
->m_vColour
= rColour
;
354 } // end of wxPen::SetColour
356 void wxPen::SetColour( unsigned char cRed
, unsigned char cGreen
, unsigned char cBlue
)
359 M_PENDATA
->m_vColour
.Set(cRed
, cGreen
, cBlue
);
361 } // end of wxPen::SetColour
363 void wxPen::SetPS( HPS hPS
)
366 if (M_PENDATA
->m_hPen
)
367 ::GpiDestroyPS(M_PENDATA
->m_hPen
);
368 M_PENDATA
->m_hPen
= hPS
;
370 } // end of WxWinGdi_CPen::SetPS
372 void wxPen::SetWidth(
377 M_PENDATA
->m_nWidth
= nWidth
;
379 } // end of wxPen::SetWidth
381 void wxPen::SetStyle(
386 M_PENDATA
->m_nStyle
= nStyle
;
388 } // end of wxPen::SetStyle
390 void wxPen::SetStipple(
391 const wxBitmap
& rStipple
395 M_PENDATA
->m_vStipple
= rStipple
;
396 M_PENDATA
->m_nStyle
= wxSTIPPLE
;
398 } // end of wxPen::SetStipple
400 void wxPen::SetDashes( int WXUNUSED(nNbDashes
),
401 const wxDash
* WXUNUSED(pDash
) )
404 // Does nothing under OS/2
406 } // end of wxPen::SetDashes
413 M_PENDATA
->m_nJoin
= nJoin
;
415 } // end of wxPen::SetJoin
422 M_PENDATA
->m_nCap
= nCap
;
424 } // end of wxPen::SetCap
435 nPMStyle
= LINETYPE_DOT
;
439 nPMStyle
= LINETYPE_DASHDOT
;
443 nPMStyle
= LINETYPE_SHORTDASH
;
447 nPMStyle
= LINETYPE_LONGDASH
;
451 nPMStyle
= LINETYPE_INVISIBLE
;
455 nPMStyle
= LINETYPE_DASHDOUBLEDOT
; // We must make a choice... This is mine!
460 nPMStyle
= LINETYPE_SOLID
;
464 } // end of wx2os2PenStyle