]> git.saurik.com Git - wxWidgets.git/commitdiff
Implement wxGraphicsContext::GetSize() for Cairo.
authorVadim Zeitlin <vadim@wxwidgets.org>
Thu, 31 Mar 2011 09:38:03 +0000 (09:38 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Thu, 31 Mar 2011 09:38:03 +0000 (09:38 +0000)
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
include/wx/graphics.h
src/common/graphcmn.cpp
src/generic/graphicc.cpp
src/msw/graphics.cpp
src/osx/carbon/graphics.cpp

index 3d187934912074e83e2628c07c1b44d7b5800113..297b4a2737c1c19fecab00b7c6eaca04b08ef479 100644 (file)
@@ -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:
 
index 4a2b42c974ab33741f89dcd4e1e2e43f58700a7c..98d8a376f3de6ef33f5f7cdf3a81efc25159cf5b 100644 (file)
@@ -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;
index 5bc8a8824a60d945926ccaccb44428545ebd9dc1..1ba501788fa5caf0d0f481001ab343b06af334b3 100644 (file)
@@ -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;
index 482befad692558d1a8b3c6ffbe4030555249ff4b..942357e984a6681ff53856db058ccfe9d0799c2c 100644 (file)
@@ -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
 }
 
index 3ea411303c59602d50feef56e6530d5ca1b6a9d6..423947ee239c7a7a8aab35f8312bab08b9a661d9 100644 (file)
@@ -387,9 +387,6 @@ private:
     GraphicsState m_state1;
     GraphicsState m_state2;
 
-    wxDouble m_width;
-    wxDouble m_height;
-
     DECLARE_DYNAMIC_CLASS_NO_COPY(wxGDIPlusContext)
 };
 
index 9b5ba916361f12264e2231c77b9f92b01c1192a2..f165cbfdaaca3859684f862ffe8a367cd03dd2bc 100644 (file)
@@ -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 )
 {