diff --git a/include/wx/graphics.h b/include/wx/graphics.h index ee1879f91d..17915a48af 100644 --- a/include/wx/graphics.h +++ b/include/wx/graphics.h @@ -445,6 +445,10 @@ public: static wxGraphicsContext* CreateFromNativeWindow( void * window ); +#ifdef __WXMSW__ + static wxGraphicsContext* CreateFromNativeHDC(WXHDC dc); +#endif + static wxGraphicsContext* Create( wxWindow* window ); #if wxUSE_IMAGE @@ -830,6 +834,10 @@ public: virtual wxGraphicsContext * CreateContextFromNativeWindow( void * window ) = 0; +#ifdef __WXMSW__ + virtual wxGraphicsContext * CreateContextFromNativeHDC(WXHDC dc) = 0; +#endif + virtual wxGraphicsContext * CreateContext( wxWindow* window ) = 0; #if wxUSE_IMAGE diff --git a/interface/wx/graphics.h b/interface/wx/graphics.h index 62e4c47fb4..fc27a2fb39 100644 --- a/interface/wx/graphics.h +++ b/interface/wx/graphics.h @@ -482,6 +482,15 @@ public: */ static wxGraphicsContext* CreateFromNativeWindow(void* window); + /** + Creates a wxGraphicsContext from a native DC handle. Windows only. + + @see wxGraphicsRenderer::CreateContextFromNativeHDC() + + @since 3.1.1 + */ + static wxGraphicsContext* CreateFromNativeHDC(WXHDC dc); + /** Create a lightweight context that can be used only for measuring text. */ @@ -1321,6 +1330,13 @@ public: */ virtual wxGraphicsContext* CreateContextFromNativeWindow(void* window) = 0; + /** + Creates a wxGraphicsContext from a native DC handle. Windows only. + + @since 3.1.1 + */ + static wxGraphicsContext* CreateContextFromNativeHDC(WXHDC dc); + /** Creates a wxGraphicsContext that can be used for measuring texts only. No drawing commands are allowed. diff --git a/src/common/graphcmn.cpp b/src/common/graphcmn.cpp index 56cd73ecdd..111fa17d7c 100644 --- a/src/common/graphcmn.cpp +++ b/src/common/graphcmn.cpp @@ -961,6 +961,13 @@ wxGraphicsContext* wxGraphicsContext::CreateFromNativeWindow( void * window ) return wxGraphicsRenderer::GetDefaultRenderer()->CreateContextFromNativeWindow(window); } +#ifdef __WXMSW__ +wxGraphicsContext* wxGraphicsContext::CreateFromNativeHDC(WXHDC dc) +{ + return wxGraphicsRenderer::GetDefaultRenderer()->CreateContextFromNativeHDC(dc); +} +#endif + wxGraphicsContext* wxGraphicsContext::Create( wxWindow* window ) { return wxGraphicsRenderer::GetDefaultRenderer()->CreateContext(window); diff --git a/src/generic/graphicc.cpp b/src/generic/graphicc.cpp index 6441acb581..d7026db8e5 100644 --- a/src/generic/graphicc.cpp +++ b/src/generic/graphicc.cpp @@ -2823,6 +2823,11 @@ public : virtual wxGraphicsContext * CreateContextFromNativeContext( void * context ) wxOVERRIDE; virtual wxGraphicsContext * CreateContextFromNativeWindow( void * window ) wxOVERRIDE; + +#ifdef __WXMSW__ + virtual wxGraphicsContext * CreateContextFromNativeHDC(WXHDC dc) wxOVERRIDE; +#endif + #if wxUSE_IMAGE virtual wxGraphicsContext * CreateContextFromImage(wxImage& image) wxOVERRIDE; #endif // wxUSE_IMAGE @@ -2961,6 +2966,14 @@ wxGraphicsContext * wxCairoRenderer::CreateContextFromNativeWindow( void * windo #endif } +#ifdef __WXMSW__ +wxGraphicsContext * wxCairoRenderer::CreateContextFromNativeHDC(WXHDC dc) +{ + ENSURE_LOADED_OR_RETURN(NULL); + return new wxCairoContext(this, (HDC)dc); +} +#endif + #if wxUSE_IMAGE wxGraphicsContext * wxCairoRenderer::CreateContextFromImage(wxImage& image) { diff --git a/src/msw/graphics.cpp b/src/msw/graphics.cpp index fe4e115e03..9aeea9ed01 100644 --- a/src/msw/graphics.cpp +++ b/src/msw/graphics.cpp @@ -553,6 +553,8 @@ public : virtual wxGraphicsContext * CreateContextFromNativeWindow( void * window ) wxOVERRIDE; + virtual wxGraphicsContext * CreateContextFromNativeHDC(WXHDC dc) wxOVERRIDE; + virtual wxGraphicsContext * CreateContext( wxWindow* window ) wxOVERRIDE; #if wxUSE_IMAGE @@ -2409,6 +2411,12 @@ wxGraphicsContext * wxGDIPlusRenderer::CreateContextFromNativeWindow( void * win return new wxGDIPlusContext(this,(HWND) window); } +wxGraphicsContext * wxGDIPlusRenderer::CreateContextFromNativeHDC(WXHDC dc) +{ + ENSURE_LOADED_OR_RETURN(NULL); + return new wxGDIPlusContext(this, new Graphics((HDC)dc)); +} + wxGraphicsContext * wxGDIPlusRenderer::CreateContext( wxWindow* window ) { ENSURE_LOADED_OR_RETURN(NULL); diff --git a/src/msw/graphicsd2d.cpp b/src/msw/graphicsd2d.cpp index df2da983c9..8a7e44ea6b 100644 --- a/src/msw/graphicsd2d.cpp +++ b/src/msw/graphicsd2d.cpp @@ -4346,6 +4346,8 @@ public : wxGraphicsContext* CreateContextFromNativeWindow(void* window) wxOVERRIDE; + wxGraphicsContext * CreateContextFromNativeHDC(WXHDC dc) wxOVERRIDE; + wxGraphicsContext* CreateContext(wxWindow* window) wxOVERRIDE; #if wxUSE_IMAGE @@ -4486,6 +4488,11 @@ wxGraphicsContext* wxD2DRenderer::CreateContextFromNativeWindow(void* window) return new wxD2DContext(this, m_direct2dFactory, (HWND)window); } +wxGraphicsContext* wxD2DRenderer::CreateContextFromNativeHDC(WXHDC dc) +{ + return new wxD2DContext(this, m_direct2dFactory, (HDC)dc, wxSize(0, 0)); +} + wxGraphicsContext* wxD2DRenderer::CreateContext(wxWindow* window) { return new wxD2DContext(this, m_direct2dFactory, (HWND)window->GetHWND());