]>
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
115 bool wxPen::RealizeResource()
121 if (M_PENDATA
&& M_PENDATA
->m_hPen
== 0L)
123 SIZEL vSize
= {0, 0};
124 DEVOPENSTRUC vDop
= {0L, "DISPLAY", NULL
, 0L, 0L, 0L, 0L, 0L, 0L};
125 HDC hDC
= ::DevOpenDC( vHabmain
132 M_PENDATA
->m_hPen
= (WXHPEN
)::GpiCreatePS( vHabmain
135 ,PU_PELS
| GPIT_MICRO
| GPIA_ASSOC
141 // Set the color table to RGB mode
143 if (!::GpiCreateLogColorTable( (HPS
)M_PENDATA
->m_hPen
151 vError
= ::WinGetLastError(vHabmain
);
152 sError
= wxPMErrorToStr(vError
);
153 wxLogError("Unable to set current color table to RGB mode. Error: %s\n", sError
);
156 if (M_PENDATA
->m_nStyle
== wxTRANSPARENT
)
161 COLORREF vPmColour
= 0L;
162 USHORT uLineType
= wx2os2PenStyle(M_PENDATA
->m_nStyle
);
164 vPmColour
= M_PENDATA
->m_vColour
.GetPixel();
168 switch(M_PENDATA
->m_nJoin
)
171 uJoin
= LINEJOIN_BEVEL
;
175 uJoin
= LINEJOIN_MITRE
;
179 uJoin
= LINEJOIN_ROUND
;
185 switch(M_PENDATA
->m_nCap
)
187 case wxCAP_PROJECTING
:
188 uCap
= LINEEND_SQUARE
;
196 uCap
= LINEEND_ROUND
;
199 m_vLineBundle
.lColor
= (LONG
)vPmColour
;
200 m_vLineBundle
.usMixMode
= FM_OVERPAINT
;
201 m_vLineBundle
.fxWidth
= M_PENDATA
->m_nWidth
;
202 m_vLineBundle
.lGeomWidth
= M_PENDATA
->m_nWidth
;
203 m_vLineBundle
.usType
= uLineType
;
204 m_vLineBundle
.usEnd
= uCap
;
205 m_vLineBundle
.usJoin
= uJoin
;
207 bOk
= ::GpiSetAttrs( M_PENDATA
->m_hPen
209 ,LBB_COLOR
| LBB_MIX_MODE
| LBB_WIDTH
| LBB_GEOM_WIDTH
| LBB_TYPE
| LBB_END
| LBB_JOIN
215 vError
= ::WinGetLastError(vHabmain
);
216 sError
= wxPMErrorToStr(vError
);
217 wxLogError("Can't set Gpi attributes for a LINEBUNDLE. Error: %s\n", sError
);
221 ULONG flAttrMask
= 0L;
222 ULONG flDefMask
= 0L;
223 switch(M_PENDATA
->m_nStyle
)
226 ::GpiSetBitmapId( M_PENDATA
->m_hPen
227 ,(USHORT
)M_PENDATA
->m_vStipple
.GetHBITMAP()
228 ,(USHORT
)M_PENDATA
->m_vStipple
.GetId()
230 ::GpiSetPatternSet( M_PENDATA
->m_hPen
231 ,(USHORT
)M_PENDATA
->m_vStipple
.GetId()
233 flAttrMask
= ABB_COLOR
| ABB_BACK_COLOR
| ABB_MIX_MODE
| ABB_BACK_MIX_MODE
| ABB_SET
| ABB_SYMBOL
;
234 flDefMask
= ABB_REF_POINT
;
237 case wxBDIAGONAL_HATCH
:
238 m_vAreaBundle
.usSymbol
= PATSYM_DIAG3
;
239 m_vAreaBundle
.usSet
= LCID_DEFAULT
;
240 flAttrMask
= ABB_COLOR
| ABB_BACK_COLOR
| ABB_MIX_MODE
| ABB_BACK_MIX_MODE
| ABB_SYMBOL
;
241 flDefMask
= ABB_SET
| ABB_REF_POINT
;
244 case wxCROSSDIAG_HATCH
:
245 m_vAreaBundle
.usSymbol
= PATSYM_DIAGHATCH
;
246 m_vAreaBundle
.usSet
= LCID_DEFAULT
;
247 flAttrMask
= ABB_COLOR
| ABB_BACK_COLOR
| ABB_MIX_MODE
| ABB_BACK_MIX_MODE
| ABB_SYMBOL
;
248 flDefMask
= ABB_SET
| ABB_REF_POINT
;
251 case wxFDIAGONAL_HATCH
:
252 m_vAreaBundle
.usSymbol
= PATSYM_DIAG1
;
253 m_vAreaBundle
.usSet
= LCID_DEFAULT
;
254 flAttrMask
= ABB_COLOR
| ABB_BACK_COLOR
| ABB_MIX_MODE
| ABB_BACK_MIX_MODE
| ABB_SYMBOL
;
255 flDefMask
= ABB_SET
| ABB_REF_POINT
;
259 m_vAreaBundle
.usSymbol
= PATSYM_HATCH
;
260 m_vAreaBundle
.usSet
= LCID_DEFAULT
;
261 flAttrMask
= ABB_COLOR
| ABB_BACK_COLOR
| ABB_MIX_MODE
| ABB_BACK_MIX_MODE
| ABB_SYMBOL
;
262 flDefMask
= ABB_SET
| ABB_REF_POINT
;
265 case wxHORIZONTAL_HATCH
:
266 m_vAreaBundle
.usSymbol
= PATSYM_HORIZ
;
267 m_vAreaBundle
.usSet
= LCID_DEFAULT
;
268 flAttrMask
= ABB_COLOR
| ABB_BACK_COLOR
| ABB_MIX_MODE
| ABB_BACK_MIX_MODE
| ABB_SYMBOL
;
269 flDefMask
= ABB_SET
| ABB_REF_POINT
;
272 case wxVERTICAL_HATCH
:
273 m_vAreaBundle
.usSymbol
= PATSYM_VERT
;
274 m_vAreaBundle
.usSet
= LCID_DEFAULT
;
275 flAttrMask
= ABB_COLOR
| ABB_BACK_COLOR
| ABB_MIX_MODE
| ABB_BACK_MIX_MODE
| ABB_SYMBOL
;
276 flDefMask
= ABB_SET
| ABB_REF_POINT
;
280 m_vAreaBundle
.usSymbol
= PATSYM_SOLID
;
281 m_vAreaBundle
.usSet
= LCID_DEFAULT
;
282 flAttrMask
= ABB_COLOR
| ABB_BACK_COLOR
| ABB_MIX_MODE
| ABB_BACK_MIX_MODE
| ABB_SYMBOL
;
283 flDefMask
= ABB_SET
| ABB_REF_POINT
;
287 m_vAreaBundle
.lColor
= vPmColour
;
288 m_vAreaBundle
.lBackColor
= RGB_WHITE
;
289 m_vAreaBundle
.usMixMode
= FM_OVERPAINT
;
290 m_vAreaBundle
.usBackMixMode
= BM_OVERPAINT
;
292 bOk
= ::GpiSetAttrs( M_PENDATA
->m_hPen
300 vError
= ::WinGetLastError(vHabmain
);
301 sError
= wxPMErrorToStr(vError
);
302 wxLogError("Can't set Gpi attributes for an AREABUNDLE. Error: %s\n", sError
);
307 } // end of wxPen::RealizeResource
309 WXHANDLE
wxPen::GetResourceHandle()
314 return (WXHANDLE
)M_PENDATA
->m_hPen
;
315 } // end of wxPen::GetResourceHandle
317 bool wxPen::FreeResource(
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(
350 const wxColour
& rColour
354 M_PENDATA
->m_vColour
= rColour
;
356 } // end of wxPen::SetColour
358 void wxPen::SetColour(
360 , unsigned char cGreen
361 , unsigned char cBlue
365 M_PENDATA
->m_vColour
.Set(cRed
, cGreen
, cBlue
);
367 } // end of wxPen::SetColour
374 if (M_PENDATA
->m_hPen
)
375 ::GpiDestroyPS(M_PENDATA
->m_hPen
);
376 M_PENDATA
->m_hPen
= hPS
;
378 } // end of WxWinGdi_CPen::SetPS
380 void wxPen::SetWidth(
385 M_PENDATA
->m_nWidth
= nWidth
;
387 } // end of wxPen::SetWidth
389 void wxPen::SetStyle(
394 M_PENDATA
->m_nStyle
= nStyle
;
396 } // end of wxPen::SetStyle
398 void wxPen::SetStipple(
399 const wxBitmap
& rStipple
403 M_PENDATA
->m_vStipple
= rStipple
;
404 M_PENDATA
->m_nStyle
= wxSTIPPLE
;
406 } // end of wxPen::SetStipple
408 void wxPen::SetDashes(
410 , const wxDash
* pDash
414 // Does nothing under OS/2
416 } // end of wxPen::SetDashes
423 M_PENDATA
->m_nJoin
= nJoin
;
425 } // end of wxPen::SetJoin
432 M_PENDATA
->m_nCap
= nCap
;
434 } // end of wxPen::SetCap
445 nPMStyle
= LINETYPE_DOT
;
449 nPMStyle
= LINETYPE_DASHDOT
;
453 nPMStyle
= LINETYPE_SHORTDASH
;
457 nPMStyle
= LINETYPE_LONGDASH
;
461 nPMStyle
= LINETYPE_INVISIBLE
;
465 nPMStyle
= LINETYPE_DASHDOUBLEDOT
; // We must make a choice... This is mine!
470 nPMStyle
= LINETYPE_SOLID
;
474 } // end of wx2os2PenStyle