Correctly initialize wxGtkPrintNativeData members.
In particular, create a valid GtkPrintOperation object instead of using an uninitialized pointer to it in wxGtkPrintDialog::ShowModal(), resulting in crashes or, at best, GTK errors. Closes #12483. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@65828 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -196,7 +196,6 @@ public:
|
|||||||
GtkPrintSettings* GetPrintConfig() { return m_config; }
|
GtkPrintSettings* GetPrintConfig() { return m_config; }
|
||||||
void SetPrintConfig( GtkPrintSettings * config );
|
void SetPrintConfig( GtkPrintSettings * config );
|
||||||
|
|
||||||
void SetPrintJob( GtkPrintOperation *job ) { m_job = job; }
|
|
||||||
GtkPrintOperation* GetPrintJob() { return m_job; }
|
GtkPrintOperation* GetPrintJob() { return m_job; }
|
||||||
|
|
||||||
GtkPrintContext *GetPrintContext() { return m_context; }
|
GtkPrintContext *GetPrintContext() { return m_context; }
|
||||||
|
@@ -222,11 +222,14 @@ IMPLEMENT_CLASS(wxGtkPrintNativeData, wxPrintNativeDataBase)
|
|||||||
wxGtkPrintNativeData::wxGtkPrintNativeData()
|
wxGtkPrintNativeData::wxGtkPrintNativeData()
|
||||||
{
|
{
|
||||||
m_config = gtk_print_settings_new();
|
m_config = gtk_print_settings_new();
|
||||||
|
m_job = gtk_print_operation_new();
|
||||||
|
m_context = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
wxGtkPrintNativeData::~wxGtkPrintNativeData()
|
wxGtkPrintNativeData::~wxGtkPrintNativeData()
|
||||||
{
|
{
|
||||||
g_object_unref (m_config);
|
g_object_unref(m_job);
|
||||||
|
g_object_unref(m_config);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convert datas stored in m_config to a wxPrintData.
|
// Convert datas stored in m_config to a wxPrintData.
|
||||||
@@ -629,17 +632,19 @@ int wxGtkPrintDialog::ShowModal()
|
|||||||
gtk_print_settings_set_page_ranges (settings, range, 1);
|
gtk_print_settings_set_page_ranges (settings, range, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GtkPrintOperation * const printOp = native->GetPrintJob();
|
||||||
|
|
||||||
// If the settings are OK, we restore it.
|
// If the settings are OK, we restore it.
|
||||||
if (settings != NULL)
|
if (settings != NULL)
|
||||||
gtk_print_operation_set_print_settings (native->GetPrintJob(), settings);
|
gtk_print_operation_set_print_settings (printOp, settings);
|
||||||
gtk_print_operation_set_default_page_setup (native->GetPrintJob(), native->GetPageSetupFromSettings(settings));
|
gtk_print_operation_set_default_page_setup (printOp, native->GetPageSetupFromSettings(settings));
|
||||||
|
|
||||||
// Show the dialog if needed.
|
// Show the dialog if needed.
|
||||||
GError* gError = NULL;
|
GError* gError = NULL;
|
||||||
if (GetShowDialog())
|
if (GetShowDialog())
|
||||||
response = gtk_print_operation_run (native->GetPrintJob(), GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG, GTK_WINDOW(gtk_widget_get_toplevel(m_parent->m_widget) ), &gError);
|
response = gtk_print_operation_run (printOp, GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG, GTK_WINDOW(gtk_widget_get_toplevel(m_parent->m_widget) ), &gError);
|
||||||
else
|
else
|
||||||
response = gtk_print_operation_run (native->GetPrintJob(), GTK_PRINT_OPERATION_ACTION_PRINT, GTK_WINDOW(gtk_widget_get_toplevel(m_parent->m_widget)), &gError);
|
response = gtk_print_operation_run (printOp, GTK_PRINT_OPERATION_ACTION_PRINT, GTK_WINDOW(gtk_widget_get_toplevel(m_parent->m_widget)), &gError);
|
||||||
|
|
||||||
// Does everything went well?
|
// Does everything went well?
|
||||||
if (response == GTK_PRINT_OPERATION_RESULT_CANCEL)
|
if (response == GTK_PRINT_OPERATION_RESULT_CANCEL)
|
||||||
@@ -654,7 +659,7 @@ int wxGtkPrintDialog::ShowModal()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Now get the settings and save it.
|
// Now get the settings and save it.
|
||||||
GtkPrintSettings* newSettings = gtk_print_operation_get_print_settings (native->GetPrintJob());
|
GtkPrintSettings* newSettings = gtk_print_operation_get_print_settings(printOp);
|
||||||
native->SetPrintConfig(newSettings);
|
native->SetPrintConfig(newSettings);
|
||||||
data.ConvertFromNative();
|
data.ConvertFromNative();
|
||||||
|
|
||||||
@@ -832,9 +837,7 @@ bool wxGtkPrinter::Print(wxWindow *parent, wxPrintout *printout, bool prompt )
|
|||||||
wxPrintData printdata = GetPrintDialogData().GetPrintData();
|
wxPrintData printdata = GetPrintDialogData().GetPrintData();
|
||||||
wxGtkPrintNativeData *native = (wxGtkPrintNativeData*) printdata.GetNativeData();
|
wxGtkPrintNativeData *native = (wxGtkPrintNativeData*) printdata.GetNativeData();
|
||||||
|
|
||||||
GtkPrintOperation *printOp = gtk_print_operation_new ();
|
GtkPrintOperation * const printOp = native->GetPrintJob();
|
||||||
|
|
||||||
native->SetPrintJob( printOp );
|
|
||||||
|
|
||||||
wxPrinterToGtkData dataToSend;
|
wxPrinterToGtkData dataToSend;
|
||||||
dataToSend.printer = this;
|
dataToSend.printer = this;
|
||||||
@@ -863,8 +866,6 @@ bool wxGtkPrinter::Print(wxWindow *parent, wxPrintout *printout, bool prompt )
|
|||||||
wxFAIL_MSG(_("The print dialog returned an error."));
|
wxFAIL_MSG(_("The print dialog returned an error."));
|
||||||
}
|
}
|
||||||
|
|
||||||
g_object_unref (printOp);
|
|
||||||
|
|
||||||
return (sm_lastError == wxPRINTER_NO_ERROR);
|
return (sm_lastError == wxPRINTER_NO_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user