+}
+
+#endif // wxHAVE_EXT_CREATE_PEN
+
+bool wxPenRefData::Alloc()
+{
+ if ( m_hPen )
+ return false;
+
+ if ( m_style == wxPENSTYLE_TRANSPARENT )
+ {
+ m_hPen = (HPEN)::GetStockObject(NULL_PEN);
+ return true;
+ }
+
+ const COLORREF col = m_colour.GetPixel();
+
+#ifdef wxHAVE_EXT_CREATE_PEN
+ // Only NT can display dashed or dotted lines with width > 1
+ static const int os = wxGetOsVersion();
+ if ( os != wxOS_WINDOWS_NT &&
+ (m_style == wxPENSTYLE_DOT ||
+ m_style == wxPENSTYLE_LONG_DASH ||
+ m_style == wxPENSTYLE_SHORT_DASH ||
+ m_style == wxPENSTYLE_DOT_DASH ||
+ m_style == wxPENSTYLE_USER_DASH) &&
+ m_width > 1 )
+ {
+ m_width = 1;
+ }
+
+ // check if it's a standard kind of pen which can be created with just
+ // CreatePen()
+ if ( m_join == wxJOIN_ROUND &&
+ m_cap == wxCAP_ROUND &&
+ m_style != wxPENSTYLE_USER_DASH &&
+ m_style != wxPENSTYLE_STIPPLE &&
+ (m_width <= 1 || m_style == wxPENSTYLE_SOLID) )
+#endif // !wxHAVE_EXT_CREATE_PEN
+ {
+ m_hPen = ::CreatePen(ConvertPenStyle(m_style), m_width, col);
+ }
+#ifdef wxHAVE_EXT_CREATE_PEN
+ else // need to use ExtCreatePen()
+ {
+ DWORD styleMSW = PS_GEOMETRIC |
+ ConvertPenStyle(m_style) |
+ ConvertJoinStyle(m_join) |
+ ConvertCapStyle(m_cap);
+
+ LOGBRUSH lb;
+ switch( m_style )
+ {
+ case wxPENSTYLE_STIPPLE:
+ lb.lbStyle = BS_PATTERN;
+ lb.lbHatch = wxPtrToUInt(m_stipple.GetHBITMAP());
+ break;
+
+ case wxPENSTYLE_BDIAGONAL_HATCH:
+ lb.lbStyle = BS_HATCHED;
+ lb.lbHatch = HS_BDIAGONAL;
+ break;
+
+ case wxPENSTYLE_CROSSDIAG_HATCH:
+ lb.lbStyle = BS_HATCHED;
+ lb.lbHatch = HS_DIAGCROSS;
+ break;
+
+ case wxPENSTYLE_FDIAGONAL_HATCH:
+ lb.lbStyle = BS_HATCHED;
+ lb.lbHatch = HS_FDIAGONAL;
+ break;
+
+ case wxPENSTYLE_CROSS_HATCH:
+ lb.lbStyle = BS_HATCHED;
+ lb.lbHatch = HS_CROSS;
+ break;
+
+ case wxPENSTYLE_HORIZONTAL_HATCH:
+ lb.lbStyle = BS_HATCHED;
+ lb.lbHatch = HS_HORIZONTAL;
+ break;
+
+ case wxPENSTYLE_VERTICAL_HATCH:
+ lb.lbStyle = BS_HATCHED;
+ lb.lbHatch = HS_VERTICAL;
+ break;
+
+ default:
+ lb.lbStyle = BS_SOLID;
+ // this should be unnecessary (it's unused) but suppresses the
+ // Purify messages about uninitialized memory read
+ lb.lbHatch = 0;
+ break;
+ }
+
+ lb.lbColor = col;
+
+ DWORD *dash;
+ if ( m_style == wxPENSTYLE_USER_DASH && m_nbDash && m_dash )
+ {
+ dash = new DWORD[m_nbDash];
+ int rw = m_width > 1 ? m_width : 1;
+ for ( int i = 0; i < m_nbDash; i++ )
+ dash[i] = m_dash[i] * rw;
+ }
+ else
+ {
+ dash = NULL;
+ }
+
+ m_hPen = ::ExtCreatePen(styleMSW, m_width, &lb, m_nbDash, (LPDWORD)dash);
+
+ delete [] dash;
+ }
+#endif // wxHAVE_EXT_CREATE_PEN
+
+ return m_hPen != 0;
+}
+
+bool wxPenRefData::Free()
+{
+ if ( !m_hPen )
+ return false;
+
+ ::DeleteObject(m_hPen);
+ m_hPen = 0;
+
+ return true;
+}
+
+WXHPEN wxPenRefData::GetHPEN() const
+{
+ if ( !m_hPen )
+ const_cast<wxPenRefData *>(this)->Alloc();
+
+ return (WXHPEN)m_hPen;
+}
+
+// ----------------------------------------------------------------------------
+// wxPen
+// ----------------------------------------------------------------------------
+
+IMPLEMENT_DYNAMIC_CLASS(wxPen, wxGDIObject)
+
+wxPen::wxPen(const wxColour& col, int width, wxPenStyle style)
+{
+ m_refData = new wxPenRefData(col, width, style);
+}
+
+#if FUTURE_WXWIN_COMPATIBILITY_3_0
+wxPen::wxPen(const wxColour& colour, int width, int style)
+{
+ m_refData = new wxPenRefData(colour, width, (wxPenStyle)style);
+}