Permalink
Browse files

Add API to create wxGraphicsContext from win32 HDC

Add wxGraphicsContext::CreateFromNativeHDC() and wxGraphicsRenderer::
CreateContextFromNativeHDC() to allow creation not only from native
renderer object, but also from HDC, which is something universally
supported by win32 implementations.
  • Loading branch information...
1 parent e99abe5 commit e71be91ebe1b190e83c119a0fa42264a3a071338 @vslavik vslavik committed with vslavik Jan 5, 2017
Showing with 59 additions and 0 deletions.
  1. +8 −0 include/wx/graphics.h
  2. +16 −0 interface/wx/graphics.h
  3. +7 −0 src/common/graphcmn.cpp
  4. +13 −0 src/generic/graphicc.cpp
  5. +8 −0 src/msw/graphics.cpp
  6. +7 −0 src/msw/graphicsd2d.cpp
@@ -445,6 +445,10 @@ class WXDLLIMPEXP_CORE wxGraphicsContext : public wxGraphicsObject
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 @@ class WXDLLIMPEXP_CORE wxGraphicsRenderer : public wxObject
virtual wxGraphicsContext * CreateContextFromNativeWindow( void * window ) = 0;
+#ifdef __WXMSW__
+ virtual wxGraphicsContext * CreateContextFromNativeHDC(WXHDC dc) = 0;
+#endif
+
virtual wxGraphicsContext * CreateContext( wxWindow* window ) = 0;
#if wxUSE_IMAGE
@@ -483,6 +483,15 @@ class wxGraphicsContext : public wxGraphicsObject
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.
*/
static wxGraphicsContext* Create();
@@ -1322,6 +1331,13 @@ class wxGraphicsRenderer : public wxObject
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.
*/
@@ -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);
@@ -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)
{
@@ -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);
@@ -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());

0 comments on commit e71be91

Please sign in to comment.