// Author: Anthony Bretaudeau
// Purpose: GTK printing support
// Created: 2007-08-25
-// RCS-ID: $Id$
// Copyright: (c) 2007 wxWidgets development team
// Licence: wxWindows Licence
/////////////////////////////////////////////////////////////////////////////
#include "wx/fontutil.h"
#include "wx/dynlib.h"
#include "wx/paper.h"
+#include "wx/scopeguard.h"
+#include "wx/modalhook.h"
#include <gtk/gtk.h>
bool wxGtkPrintModule::OnInit()
{
+#ifndef __WXGTK3__
if (gtk_check_version(2,10,0) == NULL)
+#endif
+ {
wxPrintFactory::SetPrintFactory( new wxGtkPrintFactory );
+ }
return true;
}
wxGtkPrintNativeData::wxGtkPrintNativeData()
{
m_config = gtk_print_settings_new();
- m_job = gtk_print_operation_new();
+ m_job = NULL;
m_context = NULL;
}
wxGtkPrintNativeData::~wxGtkPrintNativeData()
{
- g_object_unref(m_job);
g_object_unref(m_config);
}
// This is called even if we actually don't want the dialog to appear.
int wxGtkPrintDialog::ShowModal()
{
+ WX_HOOK_MODAL_DIALOG();
+
// We need to restore the settings given in the constructor.
wxPrintData data = m_printDialogData.GetPrintData();
wxGtkPrintNativeData *native =
int wxGtkPageSetupDialog::ShowModal()
{
+ WX_HOOK_MODAL_DIALOG();
+
// Get the config.
m_pageDialogData.GetPrintData().ConvertToNative();
wxGtkPrintNativeData *native = (wxGtkPrintNativeData*) m_pageDialogData.GetPrintData().GetNativeData();
wxPrintData printdata = GetPrintDialogData().GetPrintData();
wxGtkPrintNativeData *native = (wxGtkPrintNativeData*) printdata.GetNativeData();
- GtkPrintOperation * const printOp = native->GetPrintJob();
+ wxGtkObject<GtkPrintOperation> printOp(gtk_print_operation_new());
+ native->SetPrintJob(printOp);
+ wxON_BLOCK_EXIT_OBJ1(*native, wxGtkPrintNativeData::SetPrintJob,
+ static_cast<GtkPrintOperation*>(NULL));
wxPrinterToGtkData dataToSend;
dataToSend.printer = this;
#if wxCAIRO_SCALE
m_PS2DEV = 1.0;
m_DEV2PS = 1.0;
-
- cairo_scale( m_cairo, 72.0 / (double)m_resolution, 72.0 / (double)m_resolution );
#else
m_PS2DEV = (double)m_resolution / 72.0;
m_DEV2PS = 72.0 / (double)m_resolution;
m_signX = 1; // default x-axis left to right.
m_signY = 1; // default y-axis bottom up -> top down.
-
- // By default the origin of the Cairo context is in the upper left
- // corner of the printable area. We need to translate it so that it
- // is in the upper left corner of the paper (without margins)
- GtkPageSetup *setup = gtk_print_context_get_page_setup( m_gpc );
- gdouble ml, mt;
- ml = gtk_page_setup_get_left_margin (setup, GTK_UNIT_POINTS);
- mt = gtk_page_setup_get_top_margin (setup, GTK_UNIT_POINTS);
- cairo_translate(m_cairo, -ml, -mt);
}
wxGtkPrinterDCImpl::~wxGtkPrinterDCImpl()
void* wxGtkPrinterDCImpl::GetCairoContext() const
{
- return (void*) cairo_reference( m_cairo );
+ return m_cairo;
+}
+
+void* wxGtkPrinterDCImpl::GetHandle() const
+{
+ return GetCairoContext();
}
bool wxGtkPrinterDCImpl::DoFloodFill(wxCoord WXUNUSED(x1),
CalcBoundingBox( x, y );
}
-void wxGtkPrinterDCImpl::DoDrawLines(int n, wxPoint points[], wxCoord xoffset, wxCoord yoffset)
+void wxGtkPrinterDCImpl::DoDrawLines(int n, const wxPoint points[], wxCoord xoffset, wxCoord yoffset)
{
if ( m_pen.IsTransparent() )
return;
cairo_stroke ( m_cairo);
}
-void wxGtkPrinterDCImpl::DoDrawPolygon(int n, wxPoint points[],
+void wxGtkPrinterDCImpl::DoDrawPolygon(int n, const wxPoint points[],
wxCoord xoffset, wxCoord yoffset,
wxPolygonFillMode fillStyle)
{
int i;
for (i = 1; i < n; i++)
{
- int x = points[i].x + xoffset;
- int y = points[i].y + yoffset;
- cairo_line_to( m_cairo, XLOG2DEV(x), YLOG2DEV(y) );
+ int xx = points[i].x + xoffset;
+ int yy = points[i].y + yoffset;
+ cairo_line_to( m_cairo, XLOG2DEV(xx), YLOG2DEV(yy) );
}
cairo_close_path(m_cairo);
cairo_restore(m_cairo);
}
-void wxGtkPrinterDCImpl::DoDrawPolyPolygon(int n, int count[], wxPoint points[],
+void wxGtkPrinterDCImpl::DoDrawPolyPolygon(int n, const int count[], const wxPoint points[],
wxCoord xoffset, wxCoord yoffset,
wxPolygonFillMode fillStyle)
{
y = wxCoord(YLOG2DEV(y));
int bw = bitmap.GetWidth();
int bh = bitmap.GetHeight();
+#ifndef __WXGTK3__
wxBitmap bmpSource = bitmap; // we need a non-const instance.
if (!useMask && !bitmap.HasPixbuf() && bitmap.GetMask())
bmpSource.SetMask(NULL);
+#endif
cairo_save(m_cairo);
wxDouble scaleY = (wxDouble) YLOG2DEVREL(bh) / (wxDouble) bh;
cairo_scale(m_cairo, scaleX, scaleY);
+#ifdef __WXGTK3__
+ bitmap.Draw(m_cairo, 0, 0, useMask, &m_textForegroundColour, &m_textBackgroundColour);
+#else
gdk_cairo_set_source_pixbuf(m_cairo, bmpSource.GetPixbuf(), 0, 0);
cairo_pattern_set_filter(cairo_get_source(m_cairo), CAIRO_FILTER_NEAREST);
// Use the original size here since the context is scaled already.
cairo_rectangle(m_cairo, 0, 0, bw, bh);
// Fill the rectangle using the pattern.
cairo_fill(m_cairo);
+#endif
CalcBoundingBox(0,0);
CalcBoundingBox(bw,bh);
{
cairo_rectangle ( m_cairo, XLOG2DEV(x), YLOG2DEV(y), XLOG2DEVREL(width), YLOG2DEVREL(height));
cairo_clip(m_cairo);
+
+ wxDCImpl::DoSetClippingRegion(x, y, width, height);
}
void wxGtkPrinterDCImpl::DestroyClippingRegion()
void wxGtkPrinterDCImpl::StartPage()
{
- return;
+ // Notice that we may change the Cairo transformation matrix only here and
+ // not before (e.g. in wxGtkPrinterDCImpl ctor as we used to do) in order
+ // to not affect _gtk_print_context_rotate_according_to_orientation() which
+ // is used in GTK+ itself and wouldn't work correctly if we applied these
+ // transformations before it is called.
+
+ // By default the origin of the Cairo context is in the upper left
+ // corner of the printable area. We need to translate it so that it
+ // is in the upper left corner of the paper (without margins)
+ GtkPageSetup *setup = gtk_print_context_get_page_setup( m_gpc );
+ gdouble ml, mt;
+ ml = gtk_page_setup_get_left_margin (setup, GTK_UNIT_POINTS);
+ mt = gtk_page_setup_get_top_margin (setup, GTK_UNIT_POINTS);
+ cairo_translate(m_cairo, -ml, -mt);
+
+#if wxCAIRO_SCALE
+ cairo_scale( m_cairo, 72.0 / (double)m_resolution, 72.0 / (double)m_resolution );
+#endif
}
void wxGtkPrinterDCImpl::EndPage()