+#define M_PENDATA ((wxPenRefData*)m_refData)
+
+// Win32 has ExtCreatePen() but WinCE doesn't
+#if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
+ #define wxHAVE_EXT_CREATE_PEN
+#endif
+
+// ----------------------------------------------------------------------------
+// wxPenRefData: contains information about an HPEN and its handle
+// ----------------------------------------------------------------------------
+
+class WXDLLEXPORT wxPenRefData : public wxGDIRefData
+{
+public:
+ // ctors and dtor
+ // --------------
+
+ wxPenRefData();
+ wxPenRefData(const wxPenRefData& data);
+ wxPenRefData(const wxColour& col, int width, wxPenStyle style);
+ wxPenRefData(const wxBitmap& stipple, int width);
+ virtual ~wxPenRefData();
+
+ bool operator==(const wxPenRefData& data) const
+ {
+ // we intentionally don't compare m_hPen fields here
+ return m_style == data.m_style &&
+ m_width == data.m_width &&
+ m_join == data.m_join &&
+ m_cap == data.m_cap &&
+ m_colour == data.m_colour &&
+ (m_style != wxPENSTYLE_STIPPLE || m_stipple.IsSameAs(data.m_stipple)) &&
+ (m_style != wxPENSTYLE_USER_DASH ||
+ (m_nbDash == data.m_nbDash &&
+ memcmp(m_dash, data.m_dash, m_nbDash*sizeof(wxDash)) == 0));
+ }
+
+
+ // accessors and setters
+ // ---------------------
+
+ wxColour& GetColour() const { return wx_const_cast(wxColour&, m_colour); }
+ int GetWidth() const { return m_width; }
+ wxPenStyle GetStyle() const { return m_style; }
+ wxPenJoin GetJoin() const { return m_join; }
+ wxPenCap GetCap() const { return m_cap; }
+ wxDash* GetDash() const { return m_dash; }
+ int GetDashCount() const { return m_nbDash; }
+ wxBitmap* GetStipple() const { return wx_const_cast(wxBitmap *, &m_stipple); }
+
+ void SetColour(const wxColour& col) { Free(); m_colour = col; }
+ void SetWidth(int width) { Free(); m_width = width; }
+ void SetStyle(wxPenStyle style) { Free(); m_style = style; }
+ void SetStipple(const wxBitmap& stipple)
+ {
+ Free();
+
+ m_style = wxPENSTYLE_STIPPLE;
+ m_stipple = stipple;
+ }
+
+ void SetDashes(int nb_dashes, const wxDash *dash)
+ {
+ Free();
+
+ m_nbDash = nb_dashes;
+ m_dash = wx_const_cast(wxDash *, dash);
+ }
+
+ void SetJoin(wxPenJoin join) { Free(); m_join = join; }
+ void SetCap(wxPenCap cap) { Free(); m_cap = cap; }
+
+
+ // HPEN management
+ // ---------------
+
+ // create the HPEN if we don't have it yet
+ bool Alloc();
+
+ // get the HPEN creating it on demand
+ WXHPEN GetHPEN() const;
+
+ // return true if we have a valid HPEN
+ bool HasHPEN() const { return m_hPen != 0; }
+
+ // return true if we had a valid handle before, false otherwise
+ bool Free();
+
+private:
+ // initialize the fields which have reasonable default values
+ //
+ // doesn't initialize m_width and m_style which must be initialize in ctor
+ void Init()
+ {
+ m_join = wxJOIN_ROUND;
+ m_cap = wxCAP_ROUND;
+ m_nbDash = 0;
+ m_dash = NULL;
+ m_hPen = 0;
+ }
+
+ int m_width;
+ wxPenStyle m_style;
+ wxPenJoin m_join;
+ wxPenCap m_cap;
+ wxBitmap m_stipple;
+ int m_nbDash;
+ wxDash * m_dash;
+ wxColour m_colour;
+ HPEN m_hPen;
+
+ DECLARE_NO_ASSIGN_CLASS(wxPenRefData)
+};
+
+// ============================================================================
+// implementation
+// ============================================================================
+
+// ----------------------------------------------------------------------------
+// wxPenRefData ctors/dtor
+// ----------------------------------------------------------------------------