]>
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
63 } // end of wxPen::wxPen
67 } // end of wxPen::wxPen
69 // Should implement Create
71 const wxColour
& rColour
76 m_refData
= new wxPenRefData
;
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;
86 } // end of wxPen::wxPen
89 const wxBitmap
& rStipple
93 m_refData
= new wxPenRefData
;
95 M_PENDATA
->m_vStipple
= rStipple
;
96 M_PENDATA
->m_nWidth
= nWidth
;
97 M_PENDATA
->m_nStyle
= wxSTIPPLE
;
98 M_PENDATA
->m_nJoin
= wxJOIN_ROUND
;
99 M_PENDATA
->m_nCap
= wxCAP_ROUND
;
100 M_PENDATA
->m_hPen
= 0;
103 } // end of wxPen::wxPen
109 bool wxPen::RealizeResource()
115 if (M_PENDATA
&& M_PENDATA
->m_hPen
== 0L)
117 SIZEL vSize
= {0, 0};
118 DEVOPENSTRUC vDop
= {0L, "DISPLAY", NULL
, 0L, 0L, 0L, 0L, 0L, 0L};
119 HDC hDC
= ::DevOpenDC( vHabmain
126 M_PENDATA
->m_hPen
= (WXHPEN
)::GpiCreatePS( vHabmain
129 ,PU_PELS
| GPIT_MICRO
| GPIA_ASSOC
135 // Set the color table to RGB mode
137 if (!::GpiCreateLogColorTable( (HPS
)M_PENDATA
->m_hPen
145 vError
= ::WinGetLastError(vHabmain
);
146 sError
= wxPMErrorToStr(vError
);
147 wxLogError(_T("Unable to set current color table to RGB mode. Error: %s\n"), sError
.c_str());
150 if (M_PENDATA
->m_nStyle
== wxTRANSPARENT
)
155 COLORREF vPmColour
= 0L;
156 USHORT uLineType
= (USHORT
)wx2os2PenStyle(M_PENDATA
->m_nStyle
);
158 vPmColour
= M_PENDATA
->m_vColour
.GetPixel();
162 switch(M_PENDATA
->m_nJoin
)
165 uJoin
= LINEJOIN_BEVEL
;
169 uJoin
= LINEJOIN_MITRE
;
173 uJoin
= LINEJOIN_ROUND
;
179 switch(M_PENDATA
->m_nCap
)
181 case wxCAP_PROJECTING
:
182 uCap
= LINEEND_SQUARE
;
190 uCap
= LINEEND_ROUND
;
193 m_vLineBundle
.lColor
= (LONG
)vPmColour
;
194 m_vLineBundle
.usMixMode
= FM_OVERPAINT
;
195 m_vLineBundle
.fxWidth
= M_PENDATA
->m_nWidth
;
196 m_vLineBundle
.lGeomWidth
= M_PENDATA
->m_nWidth
;
197 m_vLineBundle
.usType
= uLineType
;
198 m_vLineBundle
.usEnd
= uCap
;
199 m_vLineBundle
.usJoin
= uJoin
;
201 bOk
= ::GpiSetAttrs( M_PENDATA
->m_hPen
203 ,LBB_COLOR
| LBB_MIX_MODE
| LBB_WIDTH
| LBB_GEOM_WIDTH
| LBB_TYPE
| LBB_END
| LBB_JOIN
209 vError
= ::WinGetLastError(vHabmain
);
210 sError
= wxPMErrorToStr(vError
);
211 wxLogError(_T("Can't set Gpi attributes for a LINEBUNDLE. Error: %s\n"), sError
.c_str());
215 ULONG flAttrMask
= 0L;
216 ULONG flDefMask
= 0L;
217 switch(M_PENDATA
->m_nStyle
)
220 ::GpiSetBitmapId( M_PENDATA
->m_hPen
221 ,(USHORT
)M_PENDATA
->m_vStipple
.GetHBITMAP()
222 ,(USHORT
)M_PENDATA
->m_vStipple
.GetId()
224 ::GpiSetPatternSet( M_PENDATA
->m_hPen
225 ,(USHORT
)M_PENDATA
->m_vStipple
.GetId()
227 flAttrMask
= ABB_COLOR
| ABB_BACK_COLOR
| ABB_MIX_MODE
| ABB_BACK_MIX_MODE
| ABB_SET
| ABB_SYMBOL
;
228 flDefMask
= ABB_REF_POINT
;
231 case wxBDIAGONAL_HATCH
:
232 m_vAreaBundle
.usSymbol
= PATSYM_DIAG3
;
233 m_vAreaBundle
.usSet
= LCID_DEFAULT
;
234 flAttrMask
= ABB_COLOR
| ABB_BACK_COLOR
| ABB_MIX_MODE
| ABB_BACK_MIX_MODE
| ABB_SYMBOL
;
235 flDefMask
= ABB_SET
| ABB_REF_POINT
;
238 case wxCROSSDIAG_HATCH
:
239 m_vAreaBundle
.usSymbol
= PATSYM_DIAGHATCH
;
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 wxFDIAGONAL_HATCH
:
246 m_vAreaBundle
.usSymbol
= PATSYM_DIAG1
;
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
;
253 m_vAreaBundle
.usSymbol
= PATSYM_HATCH
;
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
;
259 case wxHORIZONTAL_HATCH
:
260 m_vAreaBundle
.usSymbol
= PATSYM_HORIZ
;
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 wxVERTICAL_HATCH
:
267 m_vAreaBundle
.usSymbol
= PATSYM_VERT
;
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
;
274 m_vAreaBundle
.usSymbol
= PATSYM_SOLID
;
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
.lColor
= vPmColour
;
282 m_vAreaBundle
.lBackColor
= RGB_WHITE
;
283 m_vAreaBundle
.usMixMode
= FM_OVERPAINT
;
284 m_vAreaBundle
.usBackMixMode
= BM_OVERPAINT
;
286 bOk
= ::GpiSetAttrs( M_PENDATA
->m_hPen
294 vError
= ::WinGetLastError(vHabmain
);
295 sError
= wxPMErrorToStr(vError
);
296 wxLogError(_T("Can't set Gpi attributes for an AREABUNDLE. Error: %s\n"), sError
.c_str());
302 } // end of wxPen::RealizeResource
304 WXHANDLE
wxPen::GetResourceHandle()
309 return (WXHANDLE
)M_PENDATA
->m_hPen
;
310 } // end of wxPen::GetResourceHandle
312 bool wxPen::FreeResource( bool WXUNUSED(bForce
) )
314 if (M_PENDATA
&& (M_PENDATA
->m_hPen
!= 0))
316 M_PENDATA
->m_hPen
= 0;
320 } // end of wxPen::FreeResource
322 bool wxPen::IsFree() const
324 return (M_PENDATA
&& M_PENDATA
->m_hPen
== 0);
327 void wxPen::Unshare()
329 // Don't change shared data
332 m_refData
= new wxPenRefData();
336 wxPenRefData
* ref
= new wxPenRefData(*(wxPenRefData
*)m_refData
);
340 } // end of wxPen::Unshare
342 void wxPen::SetColour( const wxColour
& rColour
)
345 M_PENDATA
->m_vColour
= rColour
;
347 } // end of wxPen::SetColour
349 void wxPen::SetColour( unsigned char cRed
, unsigned char cGreen
, unsigned char cBlue
)
352 M_PENDATA
->m_vColour
.Set(cRed
, cGreen
, cBlue
);
354 } // end of wxPen::SetColour
356 void wxPen::SetPS( HPS hPS
)
359 if (M_PENDATA
->m_hPen
)
360 ::GpiDestroyPS(M_PENDATA
->m_hPen
);
361 M_PENDATA
->m_hPen
= hPS
;
363 } // end of WxWinGdi_CPen::SetPS
365 void wxPen::SetWidth(
370 M_PENDATA
->m_nWidth
= nWidth
;
372 } // end of wxPen::SetWidth
374 void wxPen::SetStyle(
379 M_PENDATA
->m_nStyle
= nStyle
;
381 } // end of wxPen::SetStyle
383 void wxPen::SetStipple(
384 const wxBitmap
& rStipple
388 M_PENDATA
->m_vStipple
= rStipple
;
389 M_PENDATA
->m_nStyle
= wxSTIPPLE
;
391 } // end of wxPen::SetStipple
393 void wxPen::SetDashes( int WXUNUSED(nNbDashes
),
394 const wxDash
* WXUNUSED(pDash
) )
397 // Does nothing under OS/2
399 } // end of wxPen::SetDashes
406 M_PENDATA
->m_nJoin
= nJoin
;
408 } // end of wxPen::SetJoin
415 M_PENDATA
->m_nCap
= nCap
;
417 } // end of wxPen::SetCap
428 nPMStyle
= LINETYPE_DOT
;
432 nPMStyle
= LINETYPE_DASHDOT
;
436 nPMStyle
= LINETYPE_SHORTDASH
;
440 nPMStyle
= LINETYPE_LONGDASH
;
444 nPMStyle
= LINETYPE_INVISIBLE
;
448 nPMStyle
= LINETYPE_DASHDOUBLEDOT
; // We must make a choice... This is mine!
453 nPMStyle
= LINETYPE_SOLID
;
457 } // end of wx2os2PenStyle