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
This commit is contained in:
Robert Roebling
2008-04-28 20:39:57 +00:00
parent c3f941621e
commit 0b822969a6
18 changed files with 94 additions and 107 deletions

View File

@@ -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

View File

@@ -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;

View File

@@ -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; }

View File

@@ -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

View File

@@ -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();

View File

@@ -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:

View File

@@ -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;

View File

@@ -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:
//@{
/**
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(const wxRegion& region);
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.

View File

@@ -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

View File

@@ -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);
}

View File

@@ -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);

View File

@@ -31,11 +31,6 @@
#include <gdk/gdkx.h>
#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;

View File

@@ -16,10 +16,6 @@
#include <gdk/gdk.h>
#include <gtk/gtk.h>
#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();

View File

@@ -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),

View File

@@ -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);

View File

@@ -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?") );

View File

@@ -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 ;

View File

@@ -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();