From c7e7c3873d313856efd530d9eaf18ee3c476fe81 Mon Sep 17 00:00:00 2001 From: Artur Wieczorek Date: Sun, 10 Apr 2016 20:41:52 +0200 Subject: [PATCH] Fixed determining wxCairoContext size (wxMSW). Determine actual size of wxCairoContext created from native DC and HWND. This allows to report proper size of wxGraphicsContext created by wxGraphicsRenderer::CreateContextFromNativeContext / CreateContextFromNativeWindow. --- src/generic/graphicc.cpp | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/src/generic/graphicc.cpp b/src/generic/graphicc.cpp index b02f4df8af..218d1d7435 100644 --- a/src/generic/graphicc.cpp +++ b/src/generic/graphicc.cpp @@ -2001,8 +2001,32 @@ wxCairoContext::wxCairoContext( wxGraphicsRenderer* renderer, HDC handle ) { m_mswSurface = cairo_win32_surface_create(handle); Init( cairo_create(m_mswSurface) ); - m_width = + m_width = 0; m_height = 0; + // Try to determine DC size. + if ( m_context ) + { + HBITMAP hBmp = (HBITMAP)::GetCurrentObject(handle, OBJ_BITMAP); + if ( hBmp ) + { + BITMAP info; + if ( ::GetObject(hBmp, sizeof(info), &info) == sizeof(info) ) + { + m_width = info.bmWidth; + m_height = info.bmHeight; + } + } + else + { + HWND hWnd = ::WindowFromDC(handle); + if ( hWnd ) + { + RECT r = wxGetWindowRect(hWnd); + m_width = r.right - r.left; + m_height = r.bottom - r.top; + } + } + } } wxCairoContext::wxCairoContext(wxGraphicsRenderer* renderer, HWND hWnd) @@ -2015,6 +2039,14 @@ wxCairoContext::wxCairoContext(wxGraphicsRenderer* renderer, HWND hWnd) m_mswSurface = cairo_win32_surface_create((HDC)m_mswWindowHDC); Init(cairo_create(m_mswSurface)); + m_width = 0; + m_height = 0; + if ( m_context ) + { + RECT r = wxGetWindowRect(hWnd); + m_width = r.right - r.left; + m_height = r.bottom - r.top; + } } #endif // __WXMSW__