X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/2bda0e173844e8e0f8acf4e8ad8b5c26e5c6fe5d..69659fd770f615210efac4b4fa741b3ad6223616:/src/msw/pen.cpp?ds=sidebyside diff --git a/src/msw/pen.cpp b/src/msw/pen.cpp index 12dd825ec7..cd58107ac9 100644 --- a/src/msw/pen.cpp +++ b/src/msw/pen.cpp @@ -1,457 +1,583 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: pen.cpp +// Name: src/msw/pen.cpp // Purpose: wxPen // Author: Julian Smart -// Modified by: +// Modified by: Vadim Zeitlin: refactored wxPen code to wxPenRefData // Created: 04/01/98 // RCS-ID: $Id$ -// Copyright: (c) Julian Smart and Markus Holzem -// Licence: wxWindows license +// Copyright: (c) Julian Smart +// Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// -#ifdef __GNUG__ -#pragma implementation "pen.h" -#endif +// ============================================================================ +// declarations +// ============================================================================ + +// ---------------------------------------------------------------------------- +// headers +// ---------------------------------------------------------------------------- // For compilers that support precompilation, includes "wx.h". #include "wx/wxprec.h" #ifdef __BORLANDC__ -#pragma hdrstop + #pragma hdrstop #endif -#ifndef WX_PRECOMP -#include -#include "wx/setup.h" -#include "wx/list.h" -#include "wx/utils.h" -#include "wx/app.h" #include "wx/pen.h" + +#ifndef WX_PRECOMP + #include "wx/bitmap.h" + #include "wx/utils.h" #endif #include "wx/msw/private.h" -#include "assert.h" -#if !USE_SHARED_LIBRARIES -IMPLEMENT_DYNAMIC_CLASS(wxPen, wxGDIObject) +#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::wxPenRefData(void) -{ -// m_stipple = NULL ; - m_style = wxSOLID; - m_width = 1; - m_join = wxJOIN_ROUND ; - m_cap = wxCAP_ROUND ; - m_nbDash = 0 ; - m_dash = 0 ; - m_hPen = 0; -} +// ---------------------------------------------------------------------------- +// wxPenRefData: contains information about an HPEN and its handle +// ---------------------------------------------------------------------------- -wxPenRefData::~wxPenRefData(void) +class WXDLLEXPORT wxPenRefData : public wxGDIRefData { - if ( m_hPen ) - ::DeleteObject((HPEN) m_hPen); -} +public: + // ctors and dtor + // -------------- -// Pens + wxPenRefData(); + wxPenRefData(const wxPenRefData& data); + wxPenRefData(const wxColour& col, int width, int style); + wxPenRefData(const wxBitmap& stipple, int width); + virtual ~wxPenRefData(); -wxPen::wxPen(void) -{ - if ( wxThePenList ) - wxThePenList->AddPen(this); -} + 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 != wxSTIPPLE || m_stipple.IsSameAs(data.m_stipple)) && + (m_style != wxUSER_DASH || + (m_nbDash == data.m_nbDash && + memcmp(m_dash, data.m_dash, m_nbDash*sizeof(wxDash)) == 0)); + } -wxPen::~wxPen() -{ - if (wxThePenList) - wxThePenList->RemovePen(this); -} -// Should implement Create -wxPen::wxPen(const wxColour& col, const int Width, const int Style) -{ - m_refData = new wxPenRefData; + // accessors and setters + // --------------------- + + wxColour& GetColour() const { return wx_const_cast(wxColour&, m_colour); } + int GetWidth() const { return m_width; } + int GetStyle() const { return m_style; } + int GetJoin() const { return m_join; } + int 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(int style) { Free(); m_style = style; } + void SetStipple(const wxBitmap& stipple) + { + Free(); + + m_style = wxSTIPPLE; + 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(int join) { Free(); m_join = join; } + void SetCap(int cap) { Free(); m_cap = cap; } + + + // HPEN management + // --------------- + + // create the HPEN if we don't have it yet + bool Alloc(); - M_PENDATA->m_colour = col; -// M_PENDATA->m_stipple = NULL; - M_PENDATA->m_width = Width; - M_PENDATA->m_style = Style; - M_PENDATA->m_join = wxJOIN_ROUND ; - M_PENDATA->m_cap = wxCAP_ROUND ; - M_PENDATA->m_nbDash = 0 ; - M_PENDATA->m_dash = 0 ; - M_PENDATA->m_hPen = 0 ; + // get the HPEN creating it on demand + WXHPEN GetHPEN() const; -#ifndef __WIN32__ - // In Windows, only a pen of width = 1 can be dotted or dashed! - if ((Style == wxDOT) || (Style == wxLONG_DASH) || - (Style == wxSHORT_DASH) || (Style == wxDOT_DASH) || - (Style == wxUSER_DASH)) - M_PENDATA->m_width = 1; -#else -/*** - DWORD vers = GetVersion() ; - WORD high = HIWORD(vers) ; // high bit=0 for NT, 1 for Win32s - // Win32s doesn't support wide dashed pens + // return true if we have a valid HPEN + bool HasHPEN() const { return m_hPen != 0; } - if ((high&0x8000)!=0) -***/ - if (wxGetOsVersion()==wxWIN32S) - { - // In Windows, only a pen of width = 1 can be dotted or dashed! - if ((Style == wxDOT) || (Style == wxLONG_DASH) || - (Style == wxSHORT_DASH) || (Style == wxDOT_DASH) || - (Style == wxUSER_DASH)) - M_PENDATA->m_width = 1; - } -#endif - RealizeResource(); + // return true if we had a valid handle before, false otherwise + bool Free(); - if ( wxThePenList ) - wxThePenList->AddPen(this); +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; + int m_style; + int m_join; + int 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 +// ---------------------------------------------------------------------------- + +wxPenRefData::wxPenRefData() +{ + Init(); + + m_style = wxSOLID; + m_width = 1; } -wxPen::wxPen(const wxBitmap& stipple, const int Width) +wxPenRefData::wxPenRefData(const wxPenRefData& data) + :wxGDIRefData() { - m_refData = new wxPenRefData; + m_style = data.m_style; + m_width = data.m_width; + m_join = data.m_join; + m_cap = data.m_cap; + m_nbDash = data.m_nbDash; + m_dash = data.m_dash; + m_colour = data.m_colour; + m_hPen = 0; +} -// M_PENDATA->m_colour = col; - M_PENDATA->m_stipple = stipple; - M_PENDATA->m_width = Width; - M_PENDATA->m_style = wxSTIPPLE; - M_PENDATA->m_join = wxJOIN_ROUND ; - M_PENDATA->m_cap = wxCAP_ROUND ; - M_PENDATA->m_nbDash = 0 ; - M_PENDATA->m_dash = 0 ; - M_PENDATA->m_hPen = 0 ; +wxPenRefData::wxPenRefData(const wxColour& col, int width, int style) +{ + Init(); - RealizeResource(); + m_style = style; + m_width = width; - if ( wxThePenList ) - wxThePenList->AddPen(this); + m_colour = col; } -wxPen::wxPen(const wxString& col, const int Width, const int Style) +wxPenRefData::wxPenRefData(const wxBitmap& stipple, int width) { - m_refData = new wxPenRefData; + Init(); - M_PENDATA->m_colour = col; -// M_PENDATA->m_stipple = NULL ; - M_PENDATA->m_width = Width; - M_PENDATA->m_style = Style; - M_PENDATA->m_join = wxJOIN_ROUND ; - M_PENDATA->m_cap = wxCAP_ROUND ; - M_PENDATA->m_nbDash = 0 ; - M_PENDATA->m_dash = 0 ; - M_PENDATA->m_hPen = 0 ; + m_style = wxSTIPPLE; + m_width = width; - // In Windows, only a pen of width = 1 can be dotted or dashed! - if ((Style == wxDOT) || (Style == wxLONG_DASH) || (Style == wxSHORT_DASH) || (Style == wxDOT_DASH)) - M_PENDATA->m_width = 1; - - RealizeResource(); + m_stipple = stipple; +} - if ( wxThePenList ) - wxThePenList->AddPen(this); +wxPenRefData::~wxPenRefData() +{ + if ( m_hPen ) + ::DeleteObject(m_hPen); } -bool wxPen::RealizeResource(void) +// ---------------------------------------------------------------------------- +// wxPenRefData HPEN management +// ---------------------------------------------------------------------------- + +#ifdef wxHAVE_EXT_CREATE_PEN + +static int ConvertPenStyle(int style) { - if (M_PENDATA && (M_PENDATA->m_hPen == 0)) - { - if (M_PENDATA->m_style==wxTRANSPARENT) + switch ( style ) { - M_PENDATA->m_hPen = (WXHPEN) ::GetStockObject(NULL_PEN); - return TRUE; - } + case wxDOT: + return PS_DOT; - COLORREF ms_colour = 0 ; - ms_colour = M_PENDATA->m_colour.GetPixel() ; - - // Join style, Cap style, Pen Stippling only on Win32. - // Currently no time to find equivalent on Win3.1, sorry - // [if such equiv exist!!] -#ifdef __WIN32__ - if (M_PENDATA->m_join==wxJOIN_ROUND && - M_PENDATA->m_cap==wxCAP_ROUND && - M_PENDATA->m_style!=wxUSER_DASH && - M_PENDATA->m_style!=wxSTIPPLE - ) - M_PENDATA->m_hPen = (WXHPEN) CreatePen(wx2msPenStyle(M_PENDATA->m_style), M_PENDATA->m_width, ms_colour); - else - { - DWORD ms_style = PS_GEOMETRIC|wx2msPenStyle(M_PENDATA->m_style) ; + case wxDOT_DASH: + return PS_DASHDOT; - LOGBRUSH logb ; + case wxSHORT_DASH: + case wxLONG_DASH: + return PS_DASH; - switch(M_PENDATA->m_join) - { - case wxJOIN_BEVEL: ms_style |= PS_JOIN_BEVEL ; break ; - case wxJOIN_MITER: ms_style |= PS_JOIN_MITER ; break ; - default: - case wxJOIN_ROUND: ms_style |= PS_JOIN_ROUND ; break ; - } + case wxTRANSPARENT: + return PS_NULL; + + case wxUSER_DASH: + return PS_USERSTYLE; - switch(M_PENDATA->m_cap) - { - case wxCAP_PROJECTING: ms_style |= PS_ENDCAP_SQUARE ; break ; - case wxCAP_BUTT: ms_style |= PS_ENDCAP_FLAT ; break ; default: - case wxCAP_ROUND: ms_style |= PS_ENDCAP_ROUND ; break ; - } + wxFAIL_MSG( _T("unknown pen style") ); + // fall through - switch(M_PENDATA->m_style) - { case wxSTIPPLE: - logb.lbStyle = BS_PATTERN ; - if (M_PENDATA->m_stipple.Ok()) - logb.lbHatch = (LONG)M_PENDATA->m_stipple.GetHBITMAP() ; - else - logb.lbHatch = (LONG)0 ; - break ; case wxBDIAGONAL_HATCH: - logb.lbStyle = BS_HATCHED ; - logb.lbHatch = HS_BDIAGONAL ; - break ; case wxCROSSDIAG_HATCH: - logb.lbStyle = BS_HATCHED ; - logb.lbHatch = HS_DIAGCROSS ; - break ; case wxFDIAGONAL_HATCH: - logb.lbStyle = BS_HATCHED ; - logb.lbHatch = HS_FDIAGONAL ; - break ; case wxCROSS_HATCH: - logb.lbStyle = BS_HATCHED ; - logb.lbHatch = HS_CROSS ; - break ; case wxHORIZONTAL_HATCH: - logb.lbStyle = BS_HATCHED ; - logb.lbHatch = HS_HORIZONTAL ; - break ; case wxVERTICAL_HATCH: - logb.lbStyle = BS_HATCHED ; - logb.lbHatch = HS_VERTICAL ; - break ; + case wxSOLID: + return PS_SOLID; + } +} + +static int ConvertJoinStyle(int join) +{ + switch( join ) + { + case wxJOIN_BEVEL: + return PS_JOIN_BEVEL; + + case wxJOIN_MITER: + return PS_JOIN_MITER; + default: - logb.lbStyle = BS_SOLID ; - break ; - } - logb.lbColor = ms_colour ; - wxDash *real_dash ; - if (M_PENDATA->m_style==wxUSER_DASH && M_PENDATA->m_nbDash && M_PENDATA->m_dash) - { - real_dash = new wxDash[M_PENDATA->m_nbDash] ; - int i; - for (i=0;im_nbDash;i++) - real_dash[i] = M_PENDATA->m_dash[i] * M_PENDATA->m_width ; - } - else - real_dash = 0 ; - - // Win32s doesn't have ExtCreatePen function... - if (wxGetOsVersion()==wxWINDOWS_NT || wxGetOsVersion()==wxWIN95) - M_PENDATA->m_hPen = (WXHPEN) ExtCreatePen(ms_style,M_PENDATA->m_width,&logb, - M_PENDATA->m_style==wxUSER_DASH ? M_PENDATA->m_nbDash:0, (const DWORD *)real_dash); - else - M_PENDATA->m_hPen = (WXHPEN) CreatePen(wx2msPenStyle(M_PENDATA->m_style), M_PENDATA->m_width, ms_colour); - - if (real_dash) - delete [] real_dash ; + wxFAIL_MSG( _T("unknown pen join style") ); + // fall through + + case wxJOIN_ROUND: + return PS_JOIN_ROUND; } -#else - M_PENDATA->m_hPen = (WXHPEN) CreatePen(wx2msPenStyle(M_PENDATA->m_style), M_PENDATA->m_width, ms_colour); -#endif -#ifdef DEBUG_CREATE - if (M_PENDATA->m_hPen==0) - wxError("Cannot create pen","Internal error") ; +} + +static int ConvertCapStyle(int cap) +{ + switch ( cap ) + { + case wxCAP_PROJECTING: + return PS_ENDCAP_SQUARE; + + case wxCAP_BUTT: + return PS_ENDCAP_FLAT; + + default: + wxFAIL_MSG( _T("unknown pen cap style") ); + // fall through + + case wxCAP_ROUND: + return PS_ENDCAP_ROUND; + } +} + +#endif // wxHAVE_EXT_CREATE_PEN + +bool wxPenRefData::Alloc() +{ + if ( m_hPen ) + return false; + + if ( m_style == wxTRANSPARENT ) + { + 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 == wxDOT || + m_style == wxLONG_DASH || + m_style == wxSHORT_DASH || + m_style == wxDOT_DASH || + m_style == wxUSER_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 != wxUSER_DASH && + m_style != wxSTIPPLE && + (m_width <= 1 || m_style == wxSOLID) ) +#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 wxSTIPPLE: + lb.lbStyle = BS_PATTERN; + lb.lbHatch = (LONG)m_stipple.GetHBITMAP(); + break; + + case wxBDIAGONAL_HATCH: + lb.lbStyle = BS_HATCHED; + lb.lbHatch = HS_BDIAGONAL; + break; + + case wxCROSSDIAG_HATCH: + lb.lbStyle = BS_HATCHED; + lb.lbHatch = HS_DIAGCROSS; + break; + + case wxFDIAGONAL_HATCH: + lb.lbStyle = BS_HATCHED; + lb.lbHatch = HS_FDIAGONAL; + break; + + case wxCROSS_HATCH: + lb.lbStyle = BS_HATCHED; + lb.lbHatch = HS_CROSS; + break; + + case wxHORIZONTAL_HATCH: + lb.lbStyle = BS_HATCHED; + lb.lbHatch = HS_HORIZONTAL; + break; + + case wxVERTICAL_HATCH: + lb.lbStyle = BS_HATCHED; + lb.lbHatch = HS_VERTICAL; + break; + + default: + lb.lbStyle = BS_SOLID; +#ifdef __WXDEBUG__ + // this should be unnecessary (it's unused) but suppresses the + // Purify messages about uninitialized memory read + lb.lbHatch = 0; #endif - return TRUE; - } - return FALSE; + break; + } + + lb.lbColor = col; + + DWORD *dash; + if ( m_style == wxUSER_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; } -WXHANDLE wxPen::GetResourceHandle(void) +bool wxPenRefData::Free() { - if ( !M_PENDATA ) - return 0; - else - return (WXHANDLE)M_PENDATA->m_hPen; + if ( !m_hPen ) + return false; + + ::DeleteObject(m_hPen); + m_hPen = 0; + + return true; } -bool wxPen::FreeResource(bool force) +WXHPEN wxPenRefData::GetHPEN() const { - if (M_PENDATA && (M_PENDATA->m_hPen != 0)) - { - DeleteObject((HPEN) M_PENDATA->m_hPen); - M_PENDATA->m_hPen = 0; - return TRUE; - } - else return FALSE; + if ( !m_hPen ) + wx_const_cast(wxPenRefData *, this)->Alloc(); + + return (WXHPEN)m_hPen; } -/* -bool wxPen::UseResource(void) +// ---------------------------------------------------------------------------- +// wxPen +// ---------------------------------------------------------------------------- + +IMPLEMENT_DYNAMIC_CLASS(wxPen, wxGDIObject) + +wxPen::wxPen(const wxColour& col, int width, int style) { - IncrementResourceUsage(); - return TRUE; + m_refData = new wxPenRefData(col, width, style); } -bool wxPen::ReleaseResource(void) +wxPen::wxPen(const wxBitmap& stipple, int width) { - DecrementResourceUsage(); - return TRUE; + m_refData = new wxPenRefData(stipple, width); } -*/ -bool wxPen::IsFree(void) +bool wxPen::operator==(const wxPen& pen) const { - return (M_PENDATA && M_PENDATA->m_hPen == 0); + const wxPenRefData * + penData = wx_static_cast(const wxPenRefData *, pen.m_refData); + + // an invalid pen is only equal to another invalid pen + return m_refData ? penData && *M_PENDATA == *penData : !penData; } -void wxPen::SetColour(const wxColour& col) +bool wxPen::RealizeResource() +{ + return M_PENDATA && M_PENDATA->Alloc(); +} + +WXHANDLE wxPen::GetResourceHandle() const +{ + return M_PENDATA ? M_PENDATA->GetHPEN() : 0; +} + +bool wxPen::FreeResource(bool WXUNUSED(force)) +{ + return M_PENDATA && M_PENDATA->Free(); +} + +bool wxPen::IsFree() const { - if ( !M_PENDATA ) - m_refData = new wxPenRefData; + return M_PENDATA && !M_PENDATA->HasHPEN(); +} + +wxObjectRefData* wxPen::CreateRefData() const +{ + return new wxPenRefData; +} - M_PENDATA->m_colour = col; - - if (FreeResource()) - RealizeResource(); +wxObjectRefData* wxPen::CloneRefData(const wxObjectRefData* data) const +{ + return new wxPenRefData(*wx_static_cast(const wxPenRefData*, data)); } -void wxPen::SetColour(const wxString& col) +void wxPen::SetColour(const wxColour& col) { - if ( !M_PENDATA ) - m_refData = new wxPenRefData; + AllocExclusive(); - M_PENDATA->m_colour = col; - - if (FreeResource()) - RealizeResource(); + M_PENDATA->SetColour(col); } -void wxPen::SetColour(const unsigned char r, const unsigned char g, const unsigned char b) +void wxPen::SetColour(unsigned char r, unsigned char g, unsigned char b) { - if ( !M_PENDATA ) - m_refData = new wxPenRefData; + SetColour(wxColour(r, g, b)); +} - M_PENDATA->m_colour.Set(r, g, b); - - if (FreeResource()) - RealizeResource(); +void wxPen::SetWidth(int width) +{ + AllocExclusive(); + + M_PENDATA->SetWidth(width); } -void wxPen::SetWidth(const int Width) +void wxPen::SetStyle(int style) { - if ( !M_PENDATA ) - m_refData = new wxPenRefData; + AllocExclusive(); + + M_PENDATA->SetStyle(style); +} - M_PENDATA->m_width = Width; +void wxPen::SetStipple(const wxBitmap& stipple) +{ + AllocExclusive(); - if (FreeResource()) - RealizeResource(); + M_PENDATA->SetStipple(stipple); } -void wxPen::SetStyle(const int Style) +void wxPen::SetDashes(int nb_dashes, const wxDash *dash) { - if ( !M_PENDATA ) - m_refData = new wxPenRefData; + AllocExclusive(); - M_PENDATA->m_style = Style; + M_PENDATA->SetDashes(nb_dashes, dash); +} + +void wxPen::SetJoin(int join) +{ + AllocExclusive(); - if (FreeResource()) - RealizeResource(); + M_PENDATA->SetJoin(join); } -void wxPen::SetStipple(const wxBitmap& Stipple) +void wxPen::SetCap(int cap) { - if ( !M_PENDATA ) - m_refData = new wxPenRefData; + AllocExclusive(); - M_PENDATA->m_stipple = Stipple; - M_PENDATA->m_style = wxSTIPPLE; - - if (FreeResource()) - RealizeResource(); + M_PENDATA->SetCap(cap); } -void wxPen::SetDashes(const int nb_dashes, const wxDash *Dash) +wxColour& wxPen::GetColour() const { - if ( !M_PENDATA ) - m_refData = new wxPenRefData; + return m_refData ? M_PENDATA->GetColour() : wxNullColour; +} - M_PENDATA->m_nbDash = nb_dashes; - M_PENDATA->m_dash = (wxDash *)Dash; - - if (FreeResource()) - RealizeResource(); +int wxPen::GetWidth() const +{ + return m_refData ? M_PENDATA->GetWidth() : 0; } -void wxPen::SetJoin(const int Join) +int wxPen::GetStyle() const { - if ( !M_PENDATA ) - m_refData = new wxPenRefData; + return m_refData ? M_PENDATA->GetStyle() : 0; +} - M_PENDATA->m_join = Join; +int wxPen::GetJoin() const +{ + return m_refData ? M_PENDATA->GetJoin() : 0; +} - if (FreeResource()) - RealizeResource(); +int wxPen::GetCap() const +{ + return m_refData ? M_PENDATA->GetCap() : 0; } -void wxPen::SetCap(const int Cap) +int wxPen::GetDashes(wxDash** ptr) const { - if ( !M_PENDATA ) - m_refData = new wxPenRefData; + if ( !m_refData ) + { + *ptr = NULL; + return 0; + } - M_PENDATA->m_cap = Cap; + *ptr = M_PENDATA->GetDash(); + return M_PENDATA->GetDashCount(); +} - if (FreeResource()) - RealizeResource(); +wxDash* wxPen::GetDash() const +{ + return m_refData ? M_PENDATA->GetDash() : NULL; } -int wx2msPenStyle(int wx_style) +int wxPen::GetDashCount() const { - int cstyle; -/*** -#ifdef __WIN32__ - DWORD vers = GetVersion() ; - WORD high = HIWORD(vers) ; // high bit=0 for NT, 1 for Win32s -#endif -***/ - switch (wx_style) - { - case wxDOT: - cstyle = PS_DOT; - break; - case wxSHORT_DASH: - case wxLONG_DASH: - cstyle = PS_DASH; - break; - case wxTRANSPARENT: - cstyle = PS_NULL; - break; - case wxUSER_DASH: - // User dash style not supported on Win3.1, sorry... -#ifdef __WIN32__ - // Win32s doesn't have PS_USERSTYLE -/*** - if ((high&0x8000)==0) -***/ - if (wxGetOsVersion()==wxWINDOWS_NT) - cstyle = PS_USERSTYLE ; - else - cstyle = PS_DOT ; // We must make a choice... This is mine! -#else - cstyle = PS_DASH ; -#endif - break ; - case wxSOLID: - default: - cstyle = PS_SOLID; - break; - } - return cstyle; + return m_refData ? M_PENDATA->GetDashCount() : 0; } +wxBitmap* wxPen::GetStipple() const +{ + return m_refData ? M_PENDATA->GetStipple() : NULL; +}