From 0b822969a677939811d9fb966177031fb5fc625b Mon Sep 17 00:00:00 2001 From: Robert Roebling Date: Mon, 28 Apr 2008 20:39:57 +0000 Subject: [PATCH] Added new wxGraphicsContext:Create( wxPrinterDC ) instead of wxDC:CreateGraphicsContext git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@53406 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/dc.h | 17 ++--------- include/wx/graphics.h | 3 ++ include/wx/gtk/dcclient.h | 4 --- include/wx/gtk/dcmemory.h | 4 --- include/wx/gtk/print.h | 4 +-- include/wx/msw/dcclient.h | 4 --- include/wx/msw/dcmemory.h | 4 --- interface/graphics.h | 55 ++++++++++++++++++++++++----------- samples/printing/printing.cpp | 11 ++++++- src/common/graphcmn.cpp | 9 ++++-- src/generic/graphicc.cpp | 11 +++++++ src/gtk/dcclient.cpp | 13 --------- src/gtk/dcmemory.cpp | 12 -------- src/gtk/print.cpp | 6 ++-- src/mac/carbon/graphics.cpp | 11 +++++++ src/msw/dcclient.cpp | 12 -------- src/msw/dcmemory.cpp | 12 -------- src/msw/graphics.cpp | 9 ++++++ 18 files changed, 94 insertions(+), 107 deletions(-) diff --git a/include/wx/dc.h b/include/wx/dc.h index e500f1f49a..3131286296 100644 --- a/include/wx/dc.h +++ b/include/wx/dc.h @@ -42,11 +42,6 @@ class WXDLLIMPEXP_FWD_CORE wxMemoryDC; class WXDLLIMPEXP_FWD_CORE wxPrinterDC; class WXDLLIMPEXP_FWD_CORE wxPrintData; - -#if wxUSE_GRAPHICS_CONTEXT -class WXDLLIMPEXP_FWD_CORE wxGraphicsContext; -#endif - //----------------------------------------------------------------------------- // wxDrawObject helper class //----------------------------------------------------------------------------- @@ -187,14 +182,11 @@ public: virtual bool CanDrawBitmap() const = 0; virtual bool CanGetTextExtent() const = 0; - // get graphics context from - -#if wxUSE_GRAPHICS_CONTEXT - virtual wxGraphicsContext* CreateGraphicsContext() + // get Cairo context + virtual void* GetCairoContext() const { return NULL; } -#endif // query dimension, colour deps, resolution @@ -634,11 +626,6 @@ public: bool IsOk() const { return m_pimpl && m_pimpl->IsOk(); } -#if wxUSE_GRAPHICS_CONTEXT - wxGraphicsContext* CreateGraphicsContext() - { return m_pimpl->CreateGraphicsContext(); } -#endif - // query capabilities bool CanDrawBitmap() const diff --git a/include/wx/graphics.h b/include/wx/graphics.h index 488e8dcd54..4ab38f42c7 100644 --- a/include/wx/graphics.h +++ b/include/wx/graphics.h @@ -21,6 +21,7 @@ class WXDLLIMPEXP_FWD_CORE wxWindowDC; class WXDLLIMPEXP_FWD_CORE wxMemoryDC; +class WXDLLIMPEXP_FWD_CORE wxPrinterDC; class WXDLLIMPEXP_FWD_CORE wxGraphicsContext; class WXDLLIMPEXP_FWD_CORE wxGraphicsPath; class WXDLLIMPEXP_FWD_CORE wxGraphicsMatrix; @@ -277,6 +278,7 @@ public: static wxGraphicsContext* Create( const wxWindowDC& dc) ; static wxGraphicsContext * Create( const wxMemoryDC& dc) ; + static wxGraphicsContext * Create( const wxPrinterDC& dc) ; static wxGraphicsContext* CreateFromNative( void * context ) ; @@ -543,6 +545,7 @@ public : virtual wxGraphicsContext * CreateContext( const wxWindowDC& dc) = 0 ; virtual wxGraphicsContext * CreateContext( const wxMemoryDC& dc) = 0 ; + virtual wxGraphicsContext * CreateContext( const wxPrinterDC& dc) = 0 ; virtual wxGraphicsContext * CreateContextFromNativeContext( void * context ) = 0; diff --git a/include/wx/gtk/dcclient.h b/include/wx/gtk/dcclient.h index 9a3a13d1a4..29e35429a5 100644 --- a/include/wx/gtk/dcclient.h +++ b/include/wx/gtk/dcclient.h @@ -28,10 +28,6 @@ public: virtual ~wxWindowDCImpl(); -#if wxUSE_GRAPHICS_CONTEXT - virtual wxGraphicsContext* CreateGraphicsContext(); -#endif - virtual bool CanDrawBitmap() const { return true; } virtual bool CanGetTextExtent() const { return true; } diff --git a/include/wx/gtk/dcmemory.h b/include/wx/gtk/dcmemory.h index 44296bdb6d..ff470015c8 100644 --- a/include/wx/gtk/dcmemory.h +++ b/include/wx/gtk/dcmemory.h @@ -26,10 +26,6 @@ public: virtual ~wxMemoryDCImpl(); -#if wxUSE_GRAPHICS_CONTEXT - virtual wxGraphicsContext* CreateGraphicsContext(); -#endif - // these get reimplemented for mono-bitmaps to behave // more like their Win32 couterparts. They now interpret // wxWHITE, wxWHITE_BRUSH and wxWHITE_PEN as drawing 0 diff --git a/include/wx/gtk/print.h b/include/wx/gtk/print.h index 5cc313bde9..b6f26630b0 100644 --- a/include/wx/gtk/print.h +++ b/include/wx/gtk/print.h @@ -227,9 +227,7 @@ public: bool Ok() const { return IsOk(); } bool IsOk() const; -#if wxUSE_GRAPHICS_CONTEXT - virtual wxGraphicsContext* CreateGraphicsContext(); -#endif + virtual void* GetCairoContext() const; bool CanDrawBitmap() const { return true; } void Clear(); diff --git a/include/wx/msw/dcclient.h b/include/wx/msw/dcclient.h index 5957aa5c22..eed5e21e59 100644 --- a/include/wx/msw/dcclient.h +++ b/include/wx/msw/dcclient.h @@ -43,10 +43,6 @@ public: // Create a DC corresponding to the whole window wxWindowDCImpl( wxDC *owner, wxWindow *win ); -#if wxUSE_GRAPHICS_CONTEXT - virtual wxGraphicsContext* CreateGraphicsContext(); -#endif - virtual void DoGetSize(int *width, int *height) const; protected: diff --git a/include/wx/msw/dcmemory.h b/include/wx/msw/dcmemory.h index 23b75e9048..5b78fead33 100644 --- a/include/wx/msw/dcmemory.h +++ b/include/wx/msw/dcmemory.h @@ -22,10 +22,6 @@ public: wxMemoryDCImpl( wxMemoryDC *owner, wxBitmap& bitmap ); wxMemoryDCImpl( wxMemoryDC *owner, wxDC *dc ); // Create compatible DC -#if wxUSE_GRAPHICS_CONTEXT - virtual wxGraphicsContext* CreateGraphicsContext(); -#endif - // override some base class virtuals virtual void DoDrawRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height); virtual void DoGetSize(int* width, int* height) const; diff --git a/interface/graphics.h b/interface/graphics.h index a701b38bca..d1cdf137b2 100644 --- a/interface/graphics.h +++ b/interface/graphics.h @@ -192,9 +192,9 @@ public: @wxheader{graphics.h} A wxGraphicsContext instance is the object that is drawn upon. It is created by - a renderer using the CreateContext calls.., this can be either directly using a renderer - instance, or indirectly using the static convenience CreateXXX functions of - wxGraphicsContext that always delegate the task to the default renderer. + a renderer using wxGraphicsRenderer::CreateContext(). This can be either directly + using a renderer instance, or indirectly using the static convenience Create() + functions of wxGraphicsContext that always delegate the task to the default renderer. @code void MyCanvas::OnPaint(wxPaintEvent &event) @@ -203,11 +203,11 @@ public: wxPaintDC dc(this); // Create graphics context from it - wxGraphicsContext *gc = dc.CreateGraphicsContext(); + wxGraphicsContext *gc = wxGraphicsContext::CreateContext( dc ); if (gc) { - // make a path that contains a circle and some lines, centered at 100,100 + // make a path that contains a circle and some lines gc->SetPen( *wxRED_PEN ); wxGraphicsPath path = gc->CreatePath(); path.AddCircle( 50.0, 50.0, 50.0 ); @@ -234,28 +234,49 @@ public: class wxGraphicsContext : public wxGraphicsObject { public: - //@{ /** - Clips drawings to the rectangle. + Creates a wxGraphicsContext from a wxWindow. + + @see wxGraphicsRenderer::CreateContext() + */ + static wxGraphicsContext* Create( wxWindow* window ) ; + + /** + Creates a wxGraphicsContext from a wxWindowDC + + @see wxGraphicsRenderer::CreateContext() + */ + static wxGraphicsContext* Create( const wxWindowDC& dc) ; + + /** + Creates a wxGraphicsContext from a wxMemoryDC + + @see wxGraphicsRenderer::CreateContext() + */ + static wxGraphicsContext * Create( const wxMemoryDC& dc) ; + + /** + Creates a wxGraphicsContext from a wxPrinterDC + + @see wxGraphicsRenderer::CreateContext() + */ + static wxGraphicsContext * Create( const wxPrinterDC& dc) ; + + /** + Clips drawings to the region */ void Clip(const wxRegion& region); + + /** + Clips drawings to the rectangle. + */ void Clip(wxDouble x, wxDouble y, wxDouble w, wxDouble h); - //@} /** Concatenates the passed in transform with the current transform of this context */ void ConcatTransform(const wxGraphicsMatrix& matrix); - //@{ - /** - Creates a wxGraphicsContext from a wxWindow. - - @see wxGraphicsRenderer:: CreateContext - */ - wxGraphicsContext* Create(const wxWindowDC& dc); - wxGraphicsContext* Create(wxWindow* window); - //@} /** Creates a native brush from a wxBrush. diff --git a/samples/printing/printing.cpp b/samples/printing/printing.cpp index e0a29dc9dd..0b4c31accc 100644 --- a/samples/printing/printing.cpp +++ b/samples/printing/printing.cpp @@ -412,7 +412,16 @@ void MyFrame::Draw(wxDC& dc) dc.DrawBitmap( m_bitmap, 10, 10 ); #if wxUSE_GRAPHICS_CONTEXT - wxGraphicsContext *gc = dc.CreateGraphicsContext(); + wxGraphicsContext *gc = NULL; + + wxPrinterDC *printer_dc = wxDynamicCast( &dc, wxPrinterDC ); + if (printer_dc) + gc = wxGraphicsContext::Create( *printer_dc ); + + wxWindowDC *window_dc = wxDynamicCast( &dc, wxWindowDC ); + if (window_dc) + gc = wxGraphicsContext::Create( *window_dc ); + if (gc) { // make a path that contains a circle and some lines, centered at 100,100 diff --git a/src/common/graphcmn.cpp b/src/common/graphcmn.cpp index 3b3c05d9d2..d3166c26dd 100644 --- a/src/common/graphcmn.cpp +++ b/src/common/graphcmn.cpp @@ -790,12 +790,17 @@ wxGraphicsBitmap wxGraphicsContext::CreateSubBitmap( const wxGraphicsBitmap &bmp #endif } -wxGraphicsContext* wxGraphicsContext::Create( const wxWindowDC& dc) +/* static */ wxGraphicsContext* wxGraphicsContext::Create( const wxWindowDC& dc) { return wxGraphicsRenderer::GetDefaultRenderer()->CreateContext(dc); } -wxGraphicsContext* wxGraphicsContext::Create( const wxMemoryDC& dc) +/* static */ wxGraphicsContext* wxGraphicsContext::Create( const wxMemoryDC& dc) +{ + return wxGraphicsRenderer::GetDefaultRenderer()->CreateContext(dc); +} + +/* static */ wxGraphicsContext* wxGraphicsContext::Create( const wxPrinterDC& dc) { return wxGraphicsRenderer::GetDefaultRenderer()->CreateContext(dc); } diff --git a/src/generic/graphicc.cpp b/src/generic/graphicc.cpp index 0c6ff55590..9fdbbf8a70 100644 --- a/src/generic/graphicc.cpp +++ b/src/generic/graphicc.cpp @@ -1481,6 +1481,7 @@ public : virtual wxGraphicsContext * CreateContext( const wxWindowDC& dc); virtual wxGraphicsContext * CreateContext( const wxMemoryDC& dc); + virtual wxGraphicsContext * CreateContext( const wxPrinterDC& dc); virtual wxGraphicsContext * CreateContextFromNativeContext( void * context ); @@ -1562,6 +1563,16 @@ wxGraphicsContext * wxCairoRenderer::CreateContext( const wxMemoryDC& dc) return new wxCairoContext(this,dc); } +wxGraphicsContext * wxCairoRenderer::CreateContext( const wxPrinterDC& dc) +{ + const wxDCImpl *impl = dc.GetImpl(); + cairo_t* context = (cairo_t*) impl->GetCairoContext(); + if (context) + return new wxCairoContext(this,context); + else + return NULL; +} + wxGraphicsContext * wxCairoRenderer::CreateContextFromNativeContext( void * context ) { return new wxCairoContext(this,(cairo_t*)context); diff --git a/src/gtk/dcclient.cpp b/src/gtk/dcclient.cpp index 1c4a313d5c..5589029861 100644 --- a/src/gtk/dcclient.cpp +++ b/src/gtk/dcclient.cpp @@ -31,11 +31,6 @@ #include -#if wxUSE_GRAPHICS_CONTEXT -#include "wx/graphics.h" -#endif - - //----------------------------------------------------------------------------- // local defines //----------------------------------------------------------------------------- @@ -370,14 +365,6 @@ wxWindowDCImpl::~wxWindowDCImpl() pango_font_description_free( m_fontdesc ); } -#if wxUSE_GRAPHICS_CONTEXT -wxGraphicsContext* wxWindowDCImpl::CreateGraphicsContext() -{ - wxWindowDC *windowdc = (wxWindowDC*) GetOwner(); - return wxGraphicsRenderer::GetDefaultRenderer()->CreateContext( *windowdc ); -} -#endif - void wxWindowDCImpl::SetUpDC( bool isMemDC ) { m_ok = true; diff --git a/src/gtk/dcmemory.cpp b/src/gtk/dcmemory.cpp index d77d307dc5..3c22ca1fc1 100644 --- a/src/gtk/dcmemory.cpp +++ b/src/gtk/dcmemory.cpp @@ -16,10 +16,6 @@ #include #include -#if wxUSE_GRAPHICS_CONTEXT -#include "wx/graphics.h" -#endif - //----------------------------------------------------------------------------- // wxMemoryDCImpl //----------------------------------------------------------------------------- @@ -64,14 +60,6 @@ void wxMemoryDCImpl::Init() m_fontdesc = pango_font_description_copy( pango_context_get_font_description( m_context ) ); } -#if wxUSE_GRAPHICS_CONTEXT -wxGraphicsContext* wxMemoryDCImpl::CreateGraphicsContext() -{ - wxMemoryDC *memdc = (wxMemoryDC*) GetOwner(); - return wxGraphicsRenderer::GetDefaultRenderer()->CreateContext( *memdc ); -} -#endif - void wxMemoryDCImpl::DoSelect( const wxBitmap& bitmap ) { Destroy(); diff --git a/src/gtk/print.cpp b/src/gtk/print.cpp index d84ee92ffc..0c0792d37c 100644 --- a/src/gtk/print.cpp +++ b/src/gtk/print.cpp @@ -1159,12 +1159,10 @@ bool wxGtkPrinterDCImpl::IsOk() const return m_gpc != NULL; } -#if wxUSE_GRAPHICS_CONTEXT -wxGraphicsContext* wxGtkPrinterDCImpl::CreateGraphicsContext() +void* wxGtkPrinterDCImpl::GetCairoContext() const { - return wxGraphicsRenderer::GetDefaultRenderer()->CreateContextFromNativeContext( (void*) m_cairo ); + return (void*) cairo_reference( m_cairo ); } -#endif bool wxGtkPrinterDCImpl::DoFloodFill(wxCoord WXUNUSED(x1), wxCoord WXUNUSED(y1), diff --git a/src/mac/carbon/graphics.cpp b/src/mac/carbon/graphics.cpp index b7a64d5726..83fc525b3f 100644 --- a/src/mac/carbon/graphics.cpp +++ b/src/mac/carbon/graphics.cpp @@ -2259,6 +2259,7 @@ public : virtual wxGraphicsContext * CreateContext( const wxWindowDC& dc); virtual wxGraphicsContext * CreateContext( const wxMemoryDC& dc); + virtual wxGraphicsContext * CreateContext( const wxPrinterDC& dc); virtual wxGraphicsContext * CreateContextFromNativeContext( void * context ); @@ -2355,6 +2356,16 @@ wxGraphicsContext * wxMacCoreGraphicsRenderer::CreateContext( const wxMemoryDC& return NULL; } +wxGraphicsContext * wxMacCoreGraphicsRenderer::CreateContext( const wxPrinterDC& dc ) +{ +#ifdef __WXMAC__ + const wxDCImpl* impl = dc.GetImpl(); + + // TODO +#endif + return NULL; +} + wxGraphicsContext * wxMacCoreGraphicsRenderer::CreateContextFromNativeContext( void * context ) { return new wxMacCoreGraphicsContext(this,(CGContextRef)context); diff --git a/src/msw/dcclient.cpp b/src/msw/dcclient.cpp index b965c68430..e97fe01af2 100644 --- a/src/msw/dcclient.cpp +++ b/src/msw/dcclient.cpp @@ -33,10 +33,6 @@ #include "wx/window.h" #endif -#if wxUSE_GRAPHICS_CONTEXT -#include "wx/graphics.h" -#endif - #include "wx/msw/private.h" // ---------------------------------------------------------------------------- @@ -122,14 +118,6 @@ void wxWindowDCImpl::InitDC() #endif } -#if wxUSE_GRAPHICS_CONTEXT -wxGraphicsContext* wxWindowDCImpl::CreateGraphicsContext() -{ - wxWindowDC *windowdc = (wxWindowDC*) GetOwner(); - return wxGraphicsRenderer::GetDefaultRenderer()->CreateContext( *windowdc ); -} -#endif - void wxWindowDCImpl::DoGetSize(int *width, int *height) const { wxCHECK_RET( m_window, _T("wxWindowDCImpl without a window?") ); diff --git a/src/msw/dcmemory.cpp b/src/msw/dcmemory.cpp index 7da1ce87c5..6869e6f4e4 100644 --- a/src/msw/dcmemory.cpp +++ b/src/msw/dcmemory.cpp @@ -32,10 +32,6 @@ #include "wx/log.h" #endif -#if wxUSE_GRAPHICS_CONTEXT -#include "wx/graphics.h" -#endif - #include "wx/msw/private.h" // ---------------------------------------------------------------------------- @@ -82,14 +78,6 @@ void wxMemoryDCImpl::Init() } } -#if wxUSE_GRAPHICS_CONTEXT -wxGraphicsContext* wxMemoryDCImpl::CreateGraphicsContext() -{ - wxMemoryDC *memdc = (wxMemoryDC*) GetOwner(); - return wxGraphicsRenderer::GetDefaultRenderer()->CreateContext( *memdc ); -} -#endif - bool wxMemoryDCImpl::CreateCompatible(wxDC *dc) { wxDCImpl *impl = dc ? dc->GetImpl() : NULL ; diff --git a/src/msw/graphics.cpp b/src/msw/graphics.cpp index 15e3bd87d4..e2b875612a 100644 --- a/src/msw/graphics.cpp +++ b/src/msw/graphics.cpp @@ -1408,6 +1408,8 @@ public : virtual wxGraphicsContext * CreateContext( const wxMemoryDC& dc); + virtual wxGraphicsContext * CreateContext( const wxPrinterDC& dc); + virtual wxGraphicsContext * CreateContextFromNativeContext( void * context ); virtual wxGraphicsContext * CreateContextFromNativeWindow( void * window ); @@ -1507,6 +1509,13 @@ wxGraphicsContext * wxGDIPlusRenderer::CreateContext( const wxWindowDC& dc) return new wxGDIPlusContext(this,(HDC) msw->GetHDC()); } +wxGraphicsContext * wxGDIPlusRenderer::CreateContext( const wxPrinterDC& dc) +{ + EnsureIsLoaded(); + wxMSWDCImpl *msw = wxDynamicCast( dc.GetImpl() , wxMSWDCImpl ); + return new wxGDIPlusContext(this,(HDC) msw->GetHDC()); +} + wxGraphicsContext * wxGDIPlusRenderer::CreateContext( const wxMemoryDC& dc) { EnsureIsLoaded(); -- 2.45.2