From 5707e433a3cac5a69fe3ba4e8e8664ffe749f402 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Wed, 20 Jul 2011 11:41:07 +0000 Subject: [PATCH] Don't use template member function in drawing sample to placate VC6. VC6 can't instantiate member template functions so get rid of it and use ugly dynamic casts in the non-template function to construct wxGCDC correctly. See #13327. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@68311 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- samples/drawing/drawing.cpp | 41 ++++++++++++++++++++++++++++--------- 1 file changed, 31 insertions(+), 10 deletions(-) diff --git a/samples/drawing/drawing.cpp b/samples/drawing/drawing.cpp index edb821c26b..bf1a09c7ed 100644 --- a/samples/drawing/drawing.cpp +++ b/samples/drawing/drawing.cpp @@ -149,7 +149,7 @@ public: #if wxUSE_GRAPHICS_CONTEXT void UseGraphicContext(bool use) { m_useContext = use; Refresh(); } #endif - template void Draw(T& dc); + void Draw(wxDC& dc); protected: enum DrawMode @@ -1487,26 +1487,47 @@ void MyCanvas::DrawRegionsHelper(wxDC& dc, wxCoord x, bool firstTime) } } -#if TEST_CAIRO_EVERYWHERE -extern wxGraphicsRenderer* gCairoRenderer; -#endif - void MyCanvas::OnPaint(wxPaintEvent &WXUNUSED(event)) { wxPaintDC pdc(this); Draw(pdc); } -template -void MyCanvas::Draw(T& pdc) +void MyCanvas::Draw(wxDC& pdc) { #if wxUSE_GRAPHICS_CONTEXT -#if TEST_CAIRO_EVERYWHERE wxGCDC gdc; - gdc.SetGraphicsContext( gCairoRenderer->CreateContext( pdc ) ); + wxGraphicsRenderer* const renderer = wxGraphicsRenderer:: +#if TEST_CAIRO_EVERYWHERE + GetCairoRenderer() #else - wxGCDC gdc( pdc ) ; + GetDefaultRenderer() #endif + ; + + wxGraphicsContext* context; + if ( wxPaintDC *paintdc = wxDynamicCast(&pdc, wxPaintDC) ) + { + context = renderer->CreateContext(*paintdc); + } + else if ( wxMemoryDC *memdc = wxDynamicCast(&pdc, wxMemoryDC) ) + { + context = renderer->CreateContext(*memdc); + } +#if wxUSE_METAFILE && defined(wxMETAFILE_IS_ENH) + else if ( wxMetafileDC *metadc = wxDynamicCast(&pdc, wxMetafileDC) ) + { + context = renderer->CreateContext(*metadc); + } +#endif + else + { + wxFAIL_MSG( "Unknown wxDC kind" ); + return; + } + + gdc.SetGraphicsContext(context); + wxDC &dc = m_useContext ? (wxDC&) gdc : (wxDC&) pdc ; #else wxDC &dc = pdc ; -- 2.45.2