]>
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"
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("Unable to set current color table to RGB mode. Error: %s\n", sError
);
157 if (M_PENDATA
->m_nStyle
== wxTRANSPARENT
)
162 COLORREF vPmColour
= 0L;
163 USHORT uLineType
= 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("Can't set Gpi attributes for a LINEBUNDLE. Error: %s\n", sError
);
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("Can't set Gpi attributes for an AREABUNDLE. Error: %s\n", sError
);
308 } // end of wxPen::RealizeResource
310 WXHANDLE
wxPen::GetResourceHandle()
315 return (WXHANDLE
)M_PENDATA
->m_hPen
;
316 } // end of wxPen::GetResourceHandle
318 bool wxPen::FreeResource(
322 if (M_PENDATA
&& (M_PENDATA
->m_hPen
!= 0))
324 M_PENDATA
->m_hPen
= 0;
328 } // end of wxPen::FreeResource
330 bool wxPen::IsFree() const
332 return (M_PENDATA
&& M_PENDATA
->m_hPen
== 0);
335 void wxPen::Unshare()
337 // Don't change shared data
340 m_refData
= new wxPenRefData();
344 wxPenRefData
* ref
= new wxPenRefData(*(wxPenRefData
*)m_refData
);
348 } // end of wxPen::Unshare
350 void wxPen::SetColour(
351 const wxColour
& rColour
355 M_PENDATA
->m_vColour
= rColour
;
357 } // end of wxPen::SetColour
359 void wxPen::SetColour(
361 , unsigned char cGreen
362 , unsigned char cBlue
366 M_PENDATA
->m_vColour
.Set(cRed
, cGreen
, cBlue
);
368 } // end of wxPen::SetColour
375 if (M_PENDATA
->m_hPen
)
376 ::GpiDestroyPS(M_PENDATA
->m_hPen
);
377 M_PENDATA
->m_hPen
= hPS
;
379 } // end of WxWinGdi_CPen::SetPS
381 void wxPen::SetWidth(
386 M_PENDATA
->m_nWidth
= nWidth
;
388 } // end of wxPen::SetWidth
390 void wxPen::SetStyle(
395 M_PENDATA
->m_nStyle
= nStyle
;
397 } // end of wxPen::SetStyle
399 void wxPen::SetStipple(
400 const wxBitmap
& rStipple
404 M_PENDATA
->m_vStipple
= rStipple
;
405 M_PENDATA
->m_nStyle
= wxSTIPPLE
;
407 } // end of wxPen::SetStipple
409 void wxPen::SetDashes(
411 , const wxDash
* pDash
415 // Does nothing under OS/2
417 } // end of wxPen::SetDashes
424 M_PENDATA
->m_nJoin
= nJoin
;
426 } // end of wxPen::SetJoin
433 M_PENDATA
->m_nCap
= nCap
;
435 } // end of wxPen::SetCap
446 nPMStyle
= LINETYPE_DOT
;
450 nPMStyle
= LINETYPE_DASHDOT
;
454 nPMStyle
= LINETYPE_SHORTDASH
;
458 nPMStyle
= LINETYPE_LONGDASH
;
462 nPMStyle
= LINETYPE_INVISIBLE
;
466 nPMStyle
= LINETYPE_DASHDOUBLEDOT
; // We must make a choice... This is mine!
471 nPMStyle
= LINETYPE_SOLID
;
475 } // end of wx2os2PenStyle