Add wxGraphicsRenderer::CreateContextFromUnknownDC()

It seems wrong to have this function in wxGraphicsContext only and not
in wxGraphicsRenderer, as this makes it impossible to create a context
associated with a non-default renderer while it doesn't cost us anything
to allow doing this.
This commit is contained in:
Vadim Zeitlin
2019-02-02 21:22:19 +01:00
parent 46188ff56f
commit 8bbac921f3
3 changed files with 31 additions and 4 deletions

View File

@@ -876,6 +876,8 @@ public:
#endif #endif
#endif #endif
wxGraphicsContext* CreateContextFromUnknownDC(const wxDC& dc);
virtual wxGraphicsContext * CreateContextFromNativeContext( void * context ) = 0; virtual wxGraphicsContext * CreateContextFromNativeContext( void * context ) = 0;
virtual wxGraphicsContext * CreateContextFromNativeWindow( void * window ) = 0; virtual wxGraphicsContext * CreateContextFromNativeWindow( void * window ) = 0;

View File

@@ -456,6 +456,8 @@ public:
with wxDC and doesn't known its exact type. Use Create() instead if with wxDC and doesn't known its exact type. Use Create() instead if
you know that the DC is e.g. wxWindowDC. you know that the DC is e.g. wxWindowDC.
@see wxGraphicsRenderer::CreateContextFromUnknownDC()
@since 3.1.1 @since 3.1.1
*/ */
static wxGraphicsContext* CreateFromUnknownDC(wxDC& dc); static wxGraphicsContext* CreateFromUnknownDC(wxDC& dc);
@@ -1341,6 +1343,24 @@ public:
*/ */
virtual wxGraphicsContext* CreateContext(const wxEnhMetaFileDC& metaFileDC) = 0; virtual wxGraphicsContext* CreateContext(const wxEnhMetaFileDC& metaFileDC) = 0;
/**
Creates a wxGraphicsContext from a DC of unknown specific type.
Creates a wxGraphicsContext if @a dc is a supported type (i.e. has a
corresponding CreateContext() method, e.g. wxWindowDC or wxMemoryDC).
Returns @NULL if the DC is unsupported.
This method is only useful as a helper in generic code that operates
with wxDC and doesn't known its exact type. Use the appropriate
CreateContext() overload instead if you know that the DC is e.g.
wxWindowDC.
@see wxGraphicsContext::CreateFromUnknownDC()
@since 3.1.3
*/
static wxGraphicsContext* CreateContextFromUnknownDC(wxDC& dc);
/** /**
Creates a wxGraphicsContext associated with a wxImage. Creates a wxGraphicsContext associated with a wxImage.

View File

@@ -988,22 +988,27 @@ wxGraphicsBitmap wxGraphicsContext::CreateSubBitmap( const wxGraphicsBitmap &bmp
#endif #endif
wxGraphicsContext* wxGraphicsContext::CreateFromUnknownDC(const wxDC& dc) wxGraphicsContext* wxGraphicsContext::CreateFromUnknownDC(const wxDC& dc)
{
return wxGraphicsRenderer::GetDefaultRenderer()->CreateContextFromUnknownDC(dc);
}
wxGraphicsContext* wxGraphicsRenderer::CreateContextFromUnknownDC(const wxDC& dc)
{ {
if ( const wxWindowDC *windc = wxDynamicCast(&dc, wxWindowDC) ) if ( const wxWindowDC *windc = wxDynamicCast(&dc, wxWindowDC) )
return Create(*windc); return CreateContext(*windc);
if ( const wxMemoryDC *memdc = wxDynamicCast(&dc, wxMemoryDC) ) if ( const wxMemoryDC *memdc = wxDynamicCast(&dc, wxMemoryDC) )
return Create(*memdc); return CreateContext(*memdc);
#if wxUSE_PRINTING_ARCHITECTURE #if wxUSE_PRINTING_ARCHITECTURE
if ( const wxPrinterDC *printdc = wxDynamicCast(&dc, wxPrinterDC) ) if ( const wxPrinterDC *printdc = wxDynamicCast(&dc, wxPrinterDC) )
return Create(*printdc); return CreateContext(*printdc);
#endif #endif
#ifdef __WXMSW__ #ifdef __WXMSW__
#if wxUSE_ENH_METAFILE #if wxUSE_ENH_METAFILE
if ( const wxEnhMetaFileDC *mfdc = wxDynamicCast(&dc, wxEnhMetaFileDC) ) if ( const wxEnhMetaFileDC *mfdc = wxDynamicCast(&dc, wxEnhMetaFileDC) )
return Create(*mfdc); return CreateContext(*mfdc);
#endif #endif
#endif #endif