Don't crash when using wxPrintDialog with NULL parent under GTK.

Check that we have a valid parent before using it.

Also simplify the code a little.

Closes #14033.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@70669 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2012-02-22 13:41:11 +00:00
parent 8cddee2d0e
commit e3efa5c1ec

View File

@@ -619,8 +619,6 @@ wxGtkPrintDialog::~wxGtkPrintDialog()
// This is called even if we actually don't want the dialog to appear. // This is called even if we actually don't want the dialog to appear.
int wxGtkPrintDialog::ShowModal() int wxGtkPrintDialog::ShowModal()
{ {
GtkPrintOperationResult response;
// We need to restore the settings given in the constructor. // We need to restore the settings given in the constructor.
wxPrintData data = m_printDialogData.GetPrintData(); wxPrintData data = m_printDialogData.GetPrintData();
wxGtkPrintNativeData *native = wxGtkPrintNativeData *native =
@@ -654,10 +652,17 @@ int wxGtkPrintDialog::ShowModal()
// Show the dialog if needed. // Show the dialog if needed.
GError* gError = NULL; GError* gError = NULL;
if (GetShowDialog()) GtkPrintOperationResult response = gtk_print_operation_run
response = gtk_print_operation_run (printOp, GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG, GTK_WINDOW(gtk_widget_get_toplevel(m_parent->m_widget) ), &gError); (
else printOp,
response = gtk_print_operation_run (printOp, GTK_PRINT_OPERATION_ACTION_PRINT, GTK_WINDOW(gtk_widget_get_toplevel(m_parent->m_widget)), &gError); GetShowDialog()
? GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG
: GTK_PRINT_OPERATION_ACTION_PRINT,
m_parent
? GTK_WINDOW(gtk_widget_get_toplevel(m_parent->m_widget))
: NULL,
&gError
);
// Does everything went well? // Does everything went well?
if (response == GTK_PRINT_OPERATION_RESULT_CANCEL) if (response == GTK_PRINT_OPERATION_RESULT_CANCEL)
@@ -770,7 +775,9 @@ int wxGtkPageSetupDialog::ShowModal()
title = _("Page Setup"); title = _("Page Setup");
GtkWidget * GtkWidget *
dlg = gtk_page_setup_unix_dialog_new(title.utf8_str(), dlg = gtk_page_setup_unix_dialog_new(title.utf8_str(),
GTK_WINDOW(m_parent->m_widget)); m_parent
? GTK_WINDOW(m_parent->m_widget)
: NULL);
gtk_page_setup_unix_dialog_set_print_settings( gtk_page_setup_unix_dialog_set_print_settings(
GTK_PAGE_SETUP_UNIX_DIALOG(dlg), nativeData); GTK_PAGE_SETUP_UNIX_DIALOG(dlg), nativeData);