From b129eaa3772fc5c73e6e95cd94010a828ebf42c3 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Thu, 31 Mar 2011 09:38:03 +0000 Subject: [PATCH] Implement wxGraphicsContext::GetSize() for Cairo. As the implementation of this method is basically the same for all ports move it to the base class itself instead of requiring the derived classes to implement it. Now the derived classes need to fill in m_width and m_height members instead. Do fill them when creating wxGraphicsContext in Cairo version. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@67359 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- docs/changes.txt | 1 + include/wx/graphics.h | 11 ++++++++++- src/common/graphcmn.cpp | 6 ------ src/generic/graphicc.cpp | 35 ++++++++++++++++++++++++++++------- src/msw/graphics.cpp | 3 --- src/osx/carbon/graphics.cpp | 11 ----------- 6 files changed, 39 insertions(+), 28 deletions(-) diff --git a/docs/changes.txt b/docs/changes.txt index 3d18793491..297b4a2737 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -506,6 +506,7 @@ GTK: - Switch to GtkTooltip from deprecated GtkTooltips (Emilien Kia). - wxTLW generates wxEVT_MAXIMIZE. - Fix copying clipboard data to primary selection (David Hart). +- Implement wxGraphicsContext::GetSize() (Marcin Wojdyr). MSW: diff --git a/include/wx/graphics.h b/include/wx/graphics.h index 4a2b42c974..98d8a376f3 100644 --- a/include/wx/graphics.h +++ b/include/wx/graphics.h @@ -503,7 +503,13 @@ public: virtual bool SetCompositionMode(wxCompositionMode op) = 0; // returns the size of the graphics context in device coordinates - virtual void GetSize( wxDouble* width, wxDouble* height); + void GetSize(wxDouble* width, wxDouble* height) + { + if ( width ) + *width = m_width; + if ( height ) + *height = m_height; + } // returns the resolution of the graphics context in device points per inch virtual void GetDPI( wxDouble* dpiX, wxDouble* dpiY); @@ -638,6 +644,9 @@ public: virtual bool ShouldOffset() const { return false; } protected: + // These fields must be initialized in the derived class ctors. + wxDouble m_width, + m_height; wxGraphicsPen m_pen; wxGraphicsBrush m_brush; diff --git a/src/common/graphcmn.cpp b/src/common/graphcmn.cpp index 5bc8a8824a..1ba501788f 100644 --- a/src/common/graphcmn.cpp +++ b/src/common/graphcmn.cpp @@ -575,12 +575,6 @@ wxDouble wxGraphicsContext::GetAlpha() const } #endif -void wxGraphicsContext::GetSize( wxDouble* width, wxDouble* height) -{ - *width = 10000.0; - *height = 10000.0; -} - void wxGraphicsContext::GetDPI( wxDouble* dpiX, wxDouble* dpiY) { *dpiX = 72.0; diff --git a/src/generic/graphicc.cpp b/src/generic/graphicc.cpp index 482befad69..942357e984 100644 --- a/src/generic/graphicc.cpp +++ b/src/generic/graphicc.cpp @@ -1189,6 +1189,10 @@ wxCairoContext::wxCairoContext( wxGraphicsRenderer* renderer, const wxPrinterDC& const wxDCImpl *impl = dc.GetImpl(); Init( (cairo_t*) impl->GetCairoContext() ); + wxSize sz = dc.GetSize(); + m_width = sz.x; + m_height = sz.y; + wxPoint org = dc.GetDeviceOrigin(); cairo_translate( m_context, org.x, org.y ); @@ -1204,6 +1208,11 @@ wxCairoContext::wxCairoContext( wxGraphicsRenderer* renderer, const wxPrinterDC& wxCairoContext::wxCairoContext( wxGraphicsRenderer* renderer, const wxWindowDC& dc ) : wxGraphicsContext(renderer) { + int width, height; + dc.GetSize( &width, &height ); + m_width = width; + m_height = height; + #ifdef __WXGTK20__ wxGTKDCImpl *impldc = (wxGTKDCImpl*) dc.GetImpl(); Init( gdk_cairo_create( impldc->GetGDKWindow() ) ); @@ -1226,8 +1235,6 @@ wxCairoContext::wxCairoContext( wxGraphicsRenderer* renderer, const wxWindowDC& #endif #ifdef __WXMAC__ - int width, height; - dc.GetSize( &width, &height ); CGContextRef cgcontext = (CGContextRef)dc.GetWindow()->MacGetCGContextRef(); cairo_surface_t* surface = cairo_quartz_surface_create_for_cg_context(cgcontext, width, height); Init( cairo_create( surface ) ); @@ -1238,6 +1245,11 @@ wxCairoContext::wxCairoContext( wxGraphicsRenderer* renderer, const wxWindowDC& wxCairoContext::wxCairoContext( wxGraphicsRenderer* renderer, const wxMemoryDC& dc ) : wxGraphicsContext(renderer) { + int width, height; + dc.GetSize( &width, &height ); + m_width = width; + m_height = height; + #ifdef __WXGTK20__ wxGTKDCImpl *impldc = (wxGTKDCImpl*) dc.GetImpl(); Init( gdk_cairo_create( impldc->GetGDKWindow() ) ); @@ -1260,8 +1272,6 @@ wxCairoContext::wxCairoContext( wxGraphicsRenderer* renderer, const wxMemoryDC& #endif #ifdef __WXMAC__ - int width, height; - dc.GetSize( &width, &height ); CGContextRef cgcontext = (CGContextRef)dc.GetWindow()->MacGetCGContextRef(); cairo_surface_t* surface = cairo_quartz_surface_create_for_cg_context(cgcontext, width, height); Init( cairo_create( surface ) ); @@ -1274,6 +1284,11 @@ wxCairoContext::wxCairoContext( wxGraphicsRenderer* renderer, GdkDrawable *drawa : wxGraphicsContext(renderer) { Init( gdk_cairo_create( drawable ) ); + + int width, height; + gdk_drawable_get_size( drawable, &width, &height ); + m_width = width; + m_height = height; } #endif @@ -1282,9 +1297,9 @@ wxCairoContext::wxCairoContext( wxGraphicsRenderer* renderer, HDC handle ) : wxGraphicsContext(renderer) { m_mswSurface = cairo_win32_surface_create(handle); - m_context = cairo_create(m_mswSurface); - PushState(); - PushState(); + Init( cairo_create(m_mswSurface) ); + m_width = + m_height = 0; } #endif @@ -1293,6 +1308,8 @@ wxCairoContext::wxCairoContext( wxGraphicsRenderer* renderer, cairo_t *context ) : wxGraphicsContext(renderer) { Init( context ); + m_width = + m_height = 0; } wxCairoContext::wxCairoContext( wxGraphicsRenderer* renderer, wxWindow *window) @@ -1312,6 +1329,10 @@ wxCairoContext::wxCairoContext( wxGraphicsRenderer* renderer, wxWindow *window) wxASSERT_MSG( window->m_wxwindow, wxT("wxCairoContext needs a widget") ); Init(gdk_cairo_create(window->GTKGetDrawingWindow())); + + wxSize sz = window->GetSize(); + m_width = sz.x; + m_height = sz.y; #endif } diff --git a/src/msw/graphics.cpp b/src/msw/graphics.cpp index 3ea411303c..423947ee23 100644 --- a/src/msw/graphics.cpp +++ b/src/msw/graphics.cpp @@ -387,9 +387,6 @@ private: GraphicsState m_state1; GraphicsState m_state2; - wxDouble m_width; - wxDouble m_height; - DECLARE_DYNAMIC_CLASS_NO_COPY(wxGDIPlusContext) }; diff --git a/src/osx/carbon/graphics.cpp b/src/osx/carbon/graphics.cpp index 9b5ba91636..f165cbfdaa 100644 --- a/src/osx/carbon/graphics.cpp +++ b/src/osx/carbon/graphics.cpp @@ -1390,9 +1390,6 @@ public: void Init(); - // returns the size of the graphics context in device coordinates - virtual void GetSize( wxDouble* width, wxDouble* height); - virtual void StartPage( wxDouble width, wxDouble height ); virtual void EndPage(); @@ -1506,8 +1503,6 @@ private: #endif bool m_contextSynthesized; CGAffineTransform m_windowTransform; - wxDouble m_width; - wxDouble m_height; bool m_invisible; #if wxOSX_USE_COCOA_OR_CARBON @@ -1644,12 +1639,6 @@ wxMacCoreGraphicsContext::~wxMacCoreGraphicsContext() SetNativeContext(NULL); } -void wxMacCoreGraphicsContext::GetSize( wxDouble* width, wxDouble* height) -{ - *width = m_width; - *height = m_height; -} - void wxMacCoreGraphicsContext::StartPage( wxDouble width, wxDouble height ) {