diff --git a/include/wx/dcgraph.h b/include/wx/dcgraph.h index c29ab57876..fd413d0835 100644 --- a/include/wx/dcgraph.h +++ b/include/wx/dcgraph.h @@ -242,6 +242,10 @@ private: // is assumed to be newly created. void Init(wxGraphicsContext*); + // This method initializes m_graphicContext, m_ok and m_matrixOriginal + // fields, returns true if the context was valid. + bool DoInitContext(wxGraphicsContext* ctx); + wxDECLARE_CLASS(wxGCDCImpl); wxDECLARE_NO_COPY_CLASS(wxGCDCImpl); }; diff --git a/src/common/dcgraph.cpp b/src/common/dcgraph.cpp index 88cf61c3e0..e0baafa06d 100644 --- a/src/common/dcgraph.cpp +++ b/src/common/dcgraph.cpp @@ -126,8 +126,7 @@ wxGCDCImpl::wxGCDCImpl(wxDC *owner, wxGraphicsContext* context) : { CommonInit(); - m_graphicContext = context; - m_ok = m_graphicContext != NULL; + DoInitContext(context); // We can't currently initialize m_font, m_pen and m_brush here as we don't // have any way of converting the corresponding wxGraphicsXXX objects to @@ -146,13 +145,10 @@ wxGCDCImpl::wxGCDCImpl( wxDC *owner ) : void wxGCDCImpl::SetGraphicsContext( wxGraphicsContext* ctx ) { delete m_graphicContext; - m_graphicContext = ctx; - if ( m_graphicContext ) + + if ( DoInitContext(ctx) ) { - m_matrixOriginal = m_graphicContext->GetTransform(); - m_ok = true; - // apply the stored transformations to the passed in context - ComputeScaleAndOrigin(); + // Reapply our attributes to the context. m_graphicContext->SetFont( m_font , m_textForegroundColour ); m_graphicContext->SetPen( m_pen ); m_graphicContext->SetBrush( m_brush); @@ -220,6 +216,21 @@ void wxGCDCImpl::Init(wxGraphicsContext* ctx) SetGraphicsContext(ctx); } +bool wxGCDCImpl::DoInitContext(wxGraphicsContext* ctx) +{ + m_graphicContext = ctx; + m_ok = m_graphicContext != NULL; + + if ( m_ok ) + { + // apply the stored transformations to the passed in context + m_matrixOriginal = m_graphicContext->GetTransform(); + ComputeScaleAndOrigin(); + } + + return m_ok; +} + wxGCDCImpl::~wxGCDCImpl() { delete m_graphicContext;