From bb03d283bef07de18d0dd584eb047d2f7e1b3856 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Mon, 8 Oct 2012 12:09:37 +0000 Subject: [PATCH] Recreate GtkPrintOperation every time when printing in wxGTK. Apparently reusing GtkPrintOperation is not allowed, so create a new one every time we need it. Closes #14731. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@72642 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/gtk/print.h | 3 +++ src/gtk/print.cpp | 9 ++++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/include/wx/gtk/print.h b/include/wx/gtk/print.h index c0110a9678..90626ee549 100644 --- a/include/wx/gtk/print.h +++ b/include/wx/gtk/print.h @@ -197,6 +197,7 @@ public: void SetPrintConfig( GtkPrintSettings * config ); GtkPrintOperation* GetPrintJob() { return m_job; } + void SetPrintJob(GtkPrintOperation *job) { m_job = job; } GtkPrintContext *GetPrintContext() { return m_context; } void SetPrintContext(GtkPrintContext *context) {m_context = context; } @@ -206,6 +207,8 @@ public: void SetPageSetupToSettings(GtkPrintSettings* settings, GtkPageSetup* page_setup); private: + // NB: m_config is created and owned by us, but the other objects are not + // and their accessors don't change their ref count. GtkPrintSettings *m_config; GtkPrintOperation *m_job; GtkPrintContext *m_context; diff --git a/src/gtk/print.cpp b/src/gtk/print.cpp index 34143e4b73..3c689cbba9 100644 --- a/src/gtk/print.cpp +++ b/src/gtk/print.cpp @@ -33,6 +33,7 @@ #include "wx/fontutil.h" #include "wx/dynlib.h" #include "wx/paper.h" +#include "wx/scopeguard.h" #include @@ -234,13 +235,12 @@ IMPLEMENT_CLASS(wxGtkPrintNativeData, wxPrintNativeDataBase) 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); } @@ -904,7 +904,10 @@ bool wxGtkPrinter::Print(wxWindow *parent, wxPrintout *printout, bool prompt ) wxPrintData printdata = GetPrintDialogData().GetPrintData(); wxGtkPrintNativeData *native = (wxGtkPrintNativeData*) printdata.GetNativeData(); - GtkPrintOperation * const printOp = native->GetPrintJob(); + wxGtkObject printOp(gtk_print_operation_new()); + native->SetPrintJob(printOp); + wxON_BLOCK_EXIT_OBJ1(*native, wxGtkPrintNativeData::SetPrintJob, + static_cast(NULL)); wxPrinterToGtkData dataToSend; dataToSend.printer = this; -- 2.45.2