]>
git.saurik.com Git - wxWidgets.git/blob - src/os2/pen.cpp
1 /////////////////////////////////////////////////////////////////////////////
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 } // end of wxPenRefData::wxPenRefData
38 wxPenRefData::wxPenRefData(
39 const wxPenRefData
& rData
42 m_nStyle
= rData
.m_nStyle
;
43 m_nWidth
= rData
.m_nWidth
;
44 m_nJoin
= rData
.m_nJoin
;
45 m_nCap
= rData
.m_nCap
;
46 m_vColour
= rData
.m_vColour
;
48 } // end of wxPenRefData::wxPenRefData
50 wxPenRefData::~wxPenRefData()
52 } // end of wxPenRefData::~wxPenRefData
60 wxThePenList
->AddPen(this);
61 } // end of wxPen::wxPen
66 wxThePenList
->RemovePen(this);
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;
88 wxThePenList
->AddPen(this);
89 } // end of wxPen::wxPen
92 const wxBitmap
& rStipple
96 m_refData
= new wxPenRefData
;
98 M_PENDATA
->m_vStipple
= rStipple
;
99 M_PENDATA
->m_nWidth
= nWidth
;
100 M_PENDATA
->m_nStyle
= wxSTIPPLE
;
101 M_PENDATA
->m_nJoin
= wxJOIN_ROUND
;
102 M_PENDATA
->m_nCap
= wxCAP_ROUND
;
103 M_PENDATA
->m_hPen
= 0;
108 wxThePenList
->AddPen(this);
109 } // end of wxPen::wxPen
111 bool wxPen::RealizeResource()
117 if (M_PENDATA
&& M_PENDATA
->m_hPen
== 0L)
119 SIZEL vSize
= {0, 0};
120 DEVOPENSTRUC vDop
= {0L, "DISPLAY", NULL
, 0L, 0L, 0L, 0L, 0L, 0L};
121 HDC hDC
= ::DevOpenDC( vHabmain
128 M_PENDATA
->m_hPen
= (WXHPEN
)::GpiCreatePS( vHabmain
131 ,PU_PELS
| GPIT_MICRO
| GPIA_ASSOC
137 // Set the color table to RGB mode
139 if (!::GpiCreateLogColorTable( (HPS
)M_PENDATA
->m_hPen
147 vError
= ::WinGetLastError(vHabmain
);
148 sError
= wxPMErrorToStr(vError
);
149 wxLogError("Unable to set current color table to RGB mode. Error: %s\n", sError
);
152 if (M_PENDATA
->m_nStyle
== wxTRANSPARENT
)
157 COLORREF vPmColour
= 0L;
158 USHORT uLineType
= wx2os2PenStyle(M_PENDATA
->m_nStyle
);
160 vPmColour
= M_PENDATA
->m_vColour
.GetPixel();
164 switch(M_PENDATA
->m_nJoin
)
167 uJoin
= LINEJOIN_BEVEL
;
171 uJoin
= LINEJOIN_MITRE
;
175 uJoin
= LINEJOIN_ROUND
;
181 switch(M_PENDATA
->m_nCap
)
183 case wxCAP_PROJECTING
:
184 uCap
= LINEEND_SQUARE
;
192 uCap
= LINEEND_ROUND
;
195 m_vLineBundle
.lColor
= (LONG
)vPmColour
;
196 m_vLineBundle
.usMixMode
= FM_OVERPAINT
;
197 m_vLineBundle
.fxWidth
= M_PENDATA
->m_nWidth
;
198 m_vLineBundle
.lGeomWidth
= M_PENDATA
->m_nWidth
;
199 m_vLineBundle
.usType
= uLineType
;
200 m_vLineBundle
.usEnd
= uCap
;
201 m_vLineBundle
.usJoin
= uJoin
;
203 bOk
= ::GpiSetAttrs( M_PENDATA
->m_hPen
205 ,LBB_COLOR
| LBB_MIX_MODE
| LBB_WIDTH
| LBB_GEOM_WIDTH
| LBB_TYPE
| LBB_END
| LBB_JOIN
211 vError
= ::WinGetLastError(vHabmain
);
212 sError
= wxPMErrorToStr(vError
);
213 wxLogError("Can't set Gpi attributes for a LINEBUNDLE. Error: %s\n", sError
);
217 ULONG flAttrMask
= 0L;
218 ULONG flDefMask
= 0L;
219 switch(M_PENDATA
->m_nStyle
)
222 ::GpiSetBitmapId( M_PENDATA
->m_hPen
223 ,(USHORT
)M_PENDATA
->m_vStipple
.GetHBITMAP()
224 ,(USHORT
)M_PENDATA
->m_vStipple
.GetId()
226 ::GpiSetPatternSet( M_PENDATA
->m_hPen
227 ,(USHORT
)M_PENDATA
->m_vStipple
.GetId()
229 flAttrMask
= ABB_COLOR
| ABB_BACK_COLOR
| ABB_MIX_MODE
| ABB_BACK_MIX_MODE
| ABB_SET
| ABB_SYMBOL
;
230 flDefMask
= ABB_REF_POINT
;
233 case wxBDIAGONAL_HATCH
:
234 m_vAreaBundle
.usSymbol
= PATSYM_DIAG3
;
235 m_vAreaBundle
.usSet
= LCID_DEFAULT
;
236 flAttrMask
= ABB_COLOR
| ABB_BACK_COLOR
| ABB_MIX_MODE
| ABB_BACK_MIX_MODE
| ABB_SYMBOL
;
237 flDefMask
= ABB_SET
| ABB_REF_POINT
;
240 case wxCROSSDIAG_HATCH
:
241 m_vAreaBundle
.usSymbol
= PATSYM_DIAGHATCH
;
242 m_vAreaBundle
.usSet
= LCID_DEFAULT
;
243 flAttrMask
= ABB_COLOR
| ABB_BACK_COLOR
| ABB_MIX_MODE
| ABB_BACK_MIX_MODE
| ABB_SYMBOL
;
244 flDefMask
= ABB_SET
| ABB_REF_POINT
;
247 case wxFDIAGONAL_HATCH
:
248 m_vAreaBundle
.usSymbol
= PATSYM_DIAG1
;
249 m_vAreaBundle
.usSet
= LCID_DEFAULT
;
250 flAttrMask
= ABB_COLOR
| ABB_BACK_COLOR
| ABB_MIX_MODE
| ABB_BACK_MIX_MODE
| ABB_SYMBOL
;
251 flDefMask
= ABB_SET
| ABB_REF_POINT
;
255 m_vAreaBundle
.usSymbol
= PATSYM_HATCH
;
256 m_vAreaBundle
.usSet
= LCID_DEFAULT
;
257 flAttrMask
= ABB_COLOR
| ABB_BACK_COLOR
| ABB_MIX_MODE
| ABB_BACK_MIX_MODE
| ABB_SYMBOL
;
258 flDefMask
= ABB_SET
| ABB_REF_POINT
;
261 case wxHORIZONTAL_HATCH
:
262 m_vAreaBundle
.usSymbol
= PATSYM_HORIZ
;
263 m_vAreaBundle
.usSet
= LCID_DEFAULT
;
264 flAttrMask
= ABB_COLOR
| ABB_BACK_COLOR
| ABB_MIX_MODE
| ABB_BACK_MIX_MODE
| ABB_SYMBOL
;
265 flDefMask
= ABB_SET
| ABB_REF_POINT
;
268 case wxVERTICAL_HATCH
:
269 m_vAreaBundle
.usSymbol
= PATSYM_VERT
;
270 m_vAreaBundle
.usSet
= LCID_DEFAULT
;
271 flAttrMask
= ABB_COLOR
| ABB_BACK_COLOR
| ABB_MIX_MODE
| ABB_BACK_MIX_MODE
| ABB_SYMBOL
;
272 flDefMask
= ABB_SET
| ABB_REF_POINT
;
276 m_vAreaBundle
.usSymbol
= PATSYM_SOLID
;
277 m_vAreaBundle
.usSet
= LCID_DEFAULT
;
278 flAttrMask
= ABB_COLOR
| ABB_BACK_COLOR
| ABB_MIX_MODE
| ABB_BACK_MIX_MODE
| ABB_SYMBOL
;
279 flDefMask
= ABB_SET
| ABB_REF_POINT
;
283 m_vAreaBundle
.lColor
= vPmColour
;
284 m_vAreaBundle
.lBackColor
= RGB_WHITE
;
285 m_vAreaBundle
.usMixMode
= FM_OVERPAINT
;
286 m_vAreaBundle
.usBackMixMode
= BM_OVERPAINT
;
288 bOk
= ::GpiSetAttrs( M_PENDATA
->m_hPen
296 vError
= ::WinGetLastError(vHabmain
);
297 sError
= wxPMErrorToStr(vError
);
298 wxLogError("Can't set Gpi attributes for an AREABUNDLE. Error: %s\n", sError
);
303 } // end of wxPen::RealizeResource
305 WXHANDLE
wxPen::GetResourceHandle()
310 return (WXHANDLE
)M_PENDATA
->m_hPen
;
311 } // end of wxPen::GetResourceHandle
313 bool wxPen::FreeResource(
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(
346 const wxColour
& rColour
350 M_PENDATA
->m_vColour
= rColour
;
352 } // end of wxPen::SetColour
354 void wxPen::SetColour(
356 , unsigned char cGreen
357 , unsigned char cBlue
361 M_PENDATA
->m_vColour
.Set(cRed
, cGreen
, cBlue
);
363 } // end of wxPen::SetColour
370 if (M_PENDATA
->m_hPen
)
371 ::GpiDestroyPS(M_PENDATA
->m_hPen
);
372 M_PENDATA
->m_hPen
= hPS
;
374 } // end of WxWinGdi_CPen::SetPS
376 void wxPen::SetWidth(
381 M_PENDATA
->m_nWidth
= nWidth
;
383 } // end of wxPen::SetWidth
385 void wxPen::SetStyle(
390 M_PENDATA
->m_nStyle
= nStyle
;
392 } // end of wxPen::SetStyle
394 void wxPen::SetStipple(
395 const wxBitmap
& rStipple
399 M_PENDATA
->m_vStipple
= rStipple
;
400 M_PENDATA
->m_nStyle
= wxSTIPPLE
;
402 } // end of wxPen::SetStipple
404 void wxPen::SetDashes(
406 , const wxDash
* pDash
410 // Does nothing under OS/2
412 } // end of wxPen::SetDashes
419 M_PENDATA
->m_nJoin
= nJoin
;
421 } // end of wxPen::SetJoin
428 M_PENDATA
->m_nCap
= nCap
;
430 } // end of wxPen::SetCap
441 nPMStyle
= LINETYPE_DOT
;
445 nPMStyle
= LINETYPE_DASHDOT
;
449 nPMStyle
= LINETYPE_SHORTDASH
;
453 nPMStyle
= LINETYPE_LONGDASH
;
457 nPMStyle
= LINETYPE_INVISIBLE
;
461 nPMStyle
= LINETYPE_DASHDOUBLEDOT
; // We must make a choice... This is mine!
466 nPMStyle
= LINETYPE_SOLID
;
470 } // end of wx2os2PenStyle