1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxPen class
4 // Author: David Webster
8 // Copyright: (c) David Webster
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
15 #include "wx/gdiobj.h"
16 #include "wx/bitmap.h"
18 typedef long wxPMDash
;
20 class WXDLLIMPEXP_FWD_CORE wxPen
;
22 class WXDLLEXPORT wxPenRefData
: public wxGDIRefData
24 friend class WXDLLIMPEXP_FWD_CORE wxPen
;
27 wxPenRefData(const wxPenRefData
& rData
);
28 virtual ~wxPenRefData();
30 bool operator==(const wxPenRefData
& data
) const
32 // we intentionally don't compare m_hPen fields here
33 return m_nStyle
== data
.m_nStyle
&&
34 m_nWidth
== data
.m_nWidth
&&
35 m_nJoin
== data
.m_nJoin
&&
36 m_nCap
== data
.m_nCap
&&
37 m_vColour
== data
.m_vColour
&&
38 (m_nStyle
!= wxSTIPPLE
|| m_vStipple
.IsSameAs(data
.m_vStipple
)) &&
39 (m_nStyle
!= wxUSER_DASH
||
40 (m_dash
== data
.m_dash
&&
41 memcmp(m_dash
, data
.m_dash
, m_nbDash
*sizeof(wxDash
)) == 0));
53 WXHPEN m_hPen
;// in OS/2 GPI this will be the PS the pen is associated with
56 #define M_PENDATA ((wxPenRefData *)m_refData)
59 class WXDLLEXPORT wxPen
: public wxPenBase
63 wxPen( const wxColour
& rColour
65 ,wxPenStyle nStyle
= wxPENSTYLE_SOLID
67 #if FUTURE_WXWIN_COMPATIBILITY_3_0
68 wxDEPRECATED_FUTURE( wxPen(const wxColour
& col
, int width
, int style
) );
71 wxPen( const wxBitmap
& rStipple
76 inline bool operator == (const wxPen
& rPen
) const
78 const wxPenRefData
*penData
= (wxPenRefData
*)rPen
.m_refData
;
80 // an invalid pen is only equal to another invalid pen
81 return m_refData
? penData
&& *M_PENDATA
== *penData
: !penData
;
84 inline bool operator != (const wxPen
& rPen
) const
85 { return !(*this == rPen
); }
88 // Override in order to recreate the pen
90 void SetColour(const wxColour
& rColour
);
91 void SetColour(unsigned char cRed
, unsigned char cGreen
, unsigned char cBlue
);
93 void SetWidth(int nWidth
);
94 void SetStyle(wxPenStyle nStyle
);
95 void SetStipple(const wxBitmap
& rStipple
);
96 void SetDashes( int nNbDashes
99 void SetJoin(wxPenJoin nJoin
);
100 void SetCap(wxPenCap nCap
);
103 inline wxColour
& GetColour(void) const { return (M_PENDATA
? M_PENDATA
->m_vColour
: wxNullColour
); };
104 inline int GetWidth(void) const { return (M_PENDATA
? M_PENDATA
->m_nWidth
: 0); };
105 inline wxPenStyle
GetStyle(void) const { return (M_PENDATA
? M_PENDATA
->m_nStyle
: 0); };
106 inline wxPenJoin
GetJoin(void) const { return (M_PENDATA
? M_PENDATA
->m_nJoin
: 0); };
107 inline wxPenCap
GetCap(void) const { return (M_PENDATA
? M_PENDATA
->m_nCap
: 0); };
108 inline int GetPS(void) const { return (M_PENDATA
? M_PENDATA
->m_hPen
: 0); };
109 inline int GetDashes(wxDash
**ptr
) const
111 *ptr
= (M_PENDATA
? (wxDash
*)M_PENDATA
->m_dash
: (wxDash
*) NULL
);
112 return (M_PENDATA
? M_PENDATA
->m_nbDash
: 0);
114 inline wxDash
* GetDash() const { return (M_PENDATA
? (wxDash
*)M_PENDATA
->m_dash
: (wxDash
*)NULL
); };
115 inline int GetDashCount() const { return (M_PENDATA
? M_PENDATA
->m_nbDash
: 0); };
117 inline wxBitmap
* GetStipple(void) const { return (M_PENDATA
? (& M_PENDATA
->m_vStipple
) : (wxBitmap
*) NULL
); };
124 // Useful helper: create the brush resource
126 bool RealizeResource(void);
127 bool FreeResource(bool bForce
= false);
128 virtual WXHANDLE
GetResourceHandle(void) const;
129 bool IsFree(void) const;
132 LINEBUNDLE m_vLineBundle
;
133 AREABUNDLE m_vAreaBundle
;
136 virtual wxGDIRefData
* CreateGDIRefData() const;
137 virtual wxGDIRefData
* CloneGDIRefData(const wxGDIRefData
* data
) const;
139 // same as FreeResource() + RealizeResource()
142 DECLARE_DYNAMIC_CLASS(wxPen
)
143 }; // end of CLASS wxPen
145 extern int wx2os2PenStyle(wxPenStyle nWxStyle
);