Fixes and optimizations for determining wxCairoContext size (wxMSW).

1. Because Cairo uses internally GetClipBox Win API to determine surface size so we can employ the same approach in wxGraphicsRenderer::CreateContextFromNativeContext and just call this API instead of executing complicated code to determine size of underlying objects selected into DC.
2. Determine context size (and initialize respective data members with proper values) for wxCairoContext created from wxWindow.
3. Initialize respective data members with 0 values for generic wxCairoContext (with no source object provided).
This commit is contained in:
Artur Wieczorek
2016-04-14 20:47:40 +02:00
parent 0ae78d608a
commit a1a3f7309b

View File

@@ -2059,25 +2059,11 @@ wxCairoContext::wxCairoContext( wxGraphicsRenderer* renderer, HDC handle )
// Try to determine DC size.
if ( m_context )
{
HBITMAP hBmp = (HBITMAP)::GetCurrentObject(handle, OBJ_BITMAP);
if ( hBmp )
RECT r;
if( ::GetClipBox(handle, &r) != ERROR )
{
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;
}
m_width = r.right - r.left;
m_height = r.bottom - r.top;
}
}
}
@@ -2148,7 +2134,11 @@ wxCairoContext::wxCairoContext( wxGraphicsRenderer* renderer, wxWindow *window)
m_mswStateSavedDC = 0;
m_mswSurface = cairo_win32_surface_create((HDC)m_mswWindowHDC);
Init(cairo_create(m_mswSurface));
#endif
wxSize sz = window->GetSize();
m_width = sz.x;
m_height = sz.y;
#endif // __WXMSW__
#ifdef __WXQT__
// direct m_qtSurface is not being used yet (this needs cairo qt surface)
@@ -2163,6 +2153,8 @@ wxCairoContext::wxCairoContext(wxGraphicsRenderer* renderer) :
m_mswStateSavedDC = 0;
#endif // __WXMSW__
m_context = NULL;
m_width = 0;
m_height = 0;
}
wxCairoContext::~wxCairoContext()