]>
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 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()
229 case wxBDIAGONAL_HATCH
:
230 m_vAreaBundle
.usSymbol
= PATSYM_DIAG3
;
231 m_vAreaBundle
.usSet
= LCID_DEFAULT
;
234 case wxCROSSDIAG_HATCH
:
235 m_vAreaBundle
.usSymbol
= PATSYM_DIAGHATCH
;
236 m_vAreaBundle
.usSet
= LCID_DEFAULT
;
239 case wxFDIAGONAL_HATCH
:
240 m_vAreaBundle
.usSymbol
= PATSYM_DIAG1
;
241 m_vAreaBundle
.usSet
= LCID_DEFAULT
;
245 m_vAreaBundle
.usSymbol
= PATSYM_HATCH
;
246 m_vAreaBundle
.usSet
= LCID_DEFAULT
;
249 case wxHORIZONTAL_HATCH
:
250 m_vAreaBundle
.usSymbol
= PATSYM_HORIZ
;
251 m_vAreaBundle
.usSet
= LCID_DEFAULT
;
254 case wxVERTICAL_HATCH
:
255 m_vAreaBundle
.usSymbol
= PATSYM_VERT
;
256 m_vAreaBundle
.usSet
= LCID_DEFAULT
;
260 m_vAreaBundle
.usSymbol
= PATSYM_SOLID
;
261 m_vAreaBundle
.usSet
= LCID_DEFAULT
;
265 m_vAreaBundle
.lColor
= vPmColour
;
266 m_vAreaBundle
.lBackColor
= RGB_WHITE
;
267 m_vAreaBundle
.usMixMode
= FM_OVERPAINT
;
268 m_vAreaBundle
.usBackMixMode
= BM_OVERPAINT
;
270 bOk
= ::GpiSetAttrs( M_PENDATA
->m_hPen
272 ,ABB_COLOR
| ABB_BACK_COLOR
| ABB_MIX_MODE
| ABB_BACK_MIX_MODE
|
279 vError
= ::WinGetLastError(vHabmain
);
280 sError
= wxPMErrorToStr(vError
);
281 wxLogError("Can't set Gpi attributes for an AREABUNDLE. Error: %s\n", sError
);
286 } // end of wxPen::RealizeResource
288 WXHANDLE
wxPen::GetResourceHandle()
293 return (WXHANDLE
)M_PENDATA
->m_hPen
;
294 } // end of wxPen::GetResourceHandle
296 bool wxPen::FreeResource(
300 if (M_PENDATA
&& (M_PENDATA
->m_hPen
!= 0))
302 M_PENDATA
->m_hPen
= 0;
306 } // end of wxPen::FreeResource
308 bool wxPen::IsFree() const
310 return (M_PENDATA
&& M_PENDATA
->m_hPen
== 0);
313 void wxPen::Unshare()
315 // Don't change shared data
318 m_refData
= new wxPenRefData();
322 wxPenRefData
* ref
= new wxPenRefData(*(wxPenRefData
*)m_refData
);
326 } // end of wxPen::Unshare
328 void wxPen::SetColour(
329 const wxColour
& rColour
333 M_PENDATA
->m_vColour
= rColour
;
335 } // end of wxPen::SetColour
337 void wxPen::SetColour(
339 , unsigned char cGreen
340 , unsigned char cBlue
344 M_PENDATA
->m_vColour
.Set(cRed
, cGreen
, cBlue
);
346 } // end of wxPen::SetColour
353 if (M_PENDATA
->m_hPen
)
354 ::GpiDestroyPS(M_PENDATA
->m_hPen
);
355 M_PENDATA
->m_hPen
= hPS
;
357 } // end of WxWinGdi_CPen::SetPS
359 void wxPen::SetWidth(
364 M_PENDATA
->m_nWidth
= nWidth
;
366 } // end of wxPen::SetWidth
368 void wxPen::SetStyle(
373 M_PENDATA
->m_nStyle
= nStyle
;
375 } // end of wxPen::SetStyle
377 void wxPen::SetStipple(
378 const wxBitmap
& rStipple
382 M_PENDATA
->m_vStipple
= rStipple
;
383 M_PENDATA
->m_nStyle
= wxSTIPPLE
;
385 } // end of wxPen::SetStipple
387 void wxPen::SetDashes(
389 , const wxDash
* pDash
393 // Does nothing under OS/2
395 } // end of wxPen::SetDashes
402 M_PENDATA
->m_nJoin
= nJoin
;
404 } // end of wxPen::SetJoin
411 M_PENDATA
->m_nCap
= nCap
;
413 } // end of wxPen::SetCap
424 nPMStyle
= LINETYPE_DOT
;
428 nPMStyle
= LINETYPE_DASHDOT
;
432 nPMStyle
= LINETYPE_SHORTDASH
;
436 nPMStyle
= LINETYPE_LONGDASH
;
440 nPMStyle
= LINETYPE_INVISIBLE
;
444 nPMStyle
= LINETYPE_DASHDOUBLEDOT
; // We must make a choice... This is mine!
449 nPMStyle
= LINETYPE_SOLID
;
453 } // end of wx2os2PenStyle