]> git.saurik.com Git - wxWidgets.git/commitdiff
fix the bug which prevented the same wxFile/DirDialog object from being used twice...
authorVadim Zeitlin <vadim@wxwidgets.org>
Sun, 28 May 2006 23:01:21 +0000 (23:01 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Sun, 28 May 2006 23:01:21 +0000 (23:01 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@39397 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/gtk/dirdlg.h
include/wx/gtk/filedlg.h
src/gtk/dirdlg.cpp
src/gtk/filedlg.cpp

index ea078fd2ab480444d014541009e36bcf247aea18..d62bcead0a706b748ce04f48cde94bc69bf64c9f 100644 (file)
@@ -29,7 +29,7 @@ public:
                 const wxSize& size = wxDefaultSize,
                 const wxString& name = wxDirDialogNameStr);
 
-    virtual ~wxDirDialogGTK();
+    virtual ~wxDirDialogGTK() {}
 
 
 public:     // overrides from wxGenericDirDialog
@@ -41,9 +41,6 @@ public:     // overrides from wxGenericDirDialog
     virtual bool Show( bool show = true );
 
 
-//private:      must be accessible by GTK callback
-    bool m_destroyed_by_delete;
-
 protected:
     // override this from wxTLW since the native
     // form doesn't have any m_wxwindow
index 096f50920d015b0a7302595c2824a8b5a9d89be2..bd6527f0b220a5f2552573da869a70e5efd120ed 100644 (file)
@@ -29,7 +29,7 @@ public:
                  long style = 0,
                  const wxPoint& pos = wxDefaultPosition);
 
-    virtual ~wxFileDialog();
+    virtual ~wxFileDialog() {}
 
     virtual wxString GetPath() const;
     virtual void GetPaths(wxArrayString& paths) const;
@@ -48,8 +48,7 @@ public:
     virtual int ShowModal();
     virtual bool Show( bool show = true );
 
-//private:
-    bool m_destroyed_by_delete;
+
 
 protected:
     // override this from wxTLW since the native
index c75c1ceb9eaf60612215cfe85409d5db8ab3d5c9..a4e8100ac70eaf72c4cd35b2f45950865ec157da 100644 (file)
@@ -87,13 +87,8 @@ static void gtk_dirdialog_response_callback(GtkWidget *w,
 
     if (response == GTK_RESPONSE_ACCEPT)
         gtk_dirdialog_ok_callback(w, dialog);
-    else if (response == GTK_RESPONSE_CANCEL)
+    else // GTK_RESPONSE_CANCEL or GTK_RESPONSE_NONE
         gtk_dirdialog_cancel_callback(w, dialog);
-    else // "delete"
-    {
-        gtk_dirdialog_cancel_callback(w, dialog);
-        dialog->m_destroyed_by_delete = true;
-    }
 }
 }
 
@@ -119,7 +114,6 @@ wxDirDialogGTK::wxDirDialogGTK(wxWindow* parent, const wxString& title,
     {
         m_message = title;
         m_needParent = false;
-        m_destroyed_by_delete = false;
 
         if (!PreCreation(parent, pos, wxDefaultSize) ||
             !CreateBase(parent, wxID_ANY, pos, wxDefaultSize, style,
@@ -148,6 +142,14 @@ wxDirDialogGTK::wxDirDialogGTK(wxWindow* parent, const wxString& title,
 
         gtk_dialog_set_default_response(GTK_DIALOG(m_widget), GTK_RESPONSE_ACCEPT);
 
+        // gtk_widget_hide_on_delete is used here to avoid that Gtk automatically destroys
+        // the dialog when the user press ESC on the dialog: in that case a second call to
+        // ShowModal() would result in a bunch of Gtk-CRITICAL errors...
+        g_signal_connect (G_OBJECT(m_widget),
+                        "delete_event",
+                        G_CALLBACK (gtk_widget_hide_on_delete),
+                        (gpointer)this);
+
         // local-only property could be set to false to allow non-local files to be loaded.
         // In that case get/set_uri(s) should be used instead of get/set_filename(s) everywhere
         // and the GtkFileChooserDialog should probably also be created with a backend,
@@ -167,17 +169,6 @@ wxDirDialogGTK::wxDirDialogGTK(wxWindow* parent, const wxString& title,
         wxGenericDirDialog::Create(parent, title, defaultPath, style, pos, sz, name);
 }
 
-wxDirDialogGTK::~wxDirDialogGTK()
-{
-#ifdef __WXGTK24__
-    if (!gtk_check_version(2,4,0))
-    {
-        if (m_destroyed_by_delete)
-            m_widget = NULL;
-    }
-#endif
-}
-
 void wxDirDialogGTK::OnFakeOk( wxCommandEvent &event )
 {
 #ifdef __WXGTK24__
index 13c50895d2af479e7d636ab363e031e12f83fa0f..75e879ed1c78d075a835c0de05bc23474968881a 100644 (file)
@@ -89,8 +89,7 @@ static void gtk_filedialog_ok_callback(GtkWidget *widget, wxFileDialog *dialog)
 //-----------------------------------------------------------------------------
 
 extern "C" {
-static void gtk_filedialog_cancel_callback(GtkWidget *WXUNUSED(w),
-                                           wxFileDialog *dialog)
+static void gtk_filedialog_cancel_callback(GtkWidget *w, wxFileDialog *dialog)
 {
     wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, wxID_CANCEL);
     event.SetEventObject(dialog);
@@ -107,13 +106,8 @@ static void gtk_filedialog_response_callback(GtkWidget *w,
 
     if (response == GTK_RESPONSE_ACCEPT)
         gtk_filedialog_ok_callback(w, dialog);
-    else if (response == GTK_RESPONSE_CANCEL)
+    else    // GTK_RESPONSE_CANCEL or GTK_RESPONSE_NONE
         gtk_filedialog_cancel_callback(w, dialog);
-    else // "delete"
-    {
-        gtk_filedialog_cancel_callback(w, dialog);
-        dialog->m_destroyed_by_delete = true;
-    }
 }
 }
 
@@ -142,7 +136,6 @@ wxFileDialog::wxFileDialog(wxWindow *parent, const wxString& message,
     {
         wxASSERT_MSG( !( (style & wxSAVE) && (style & wxMULTIPLE) ), wxT("wxFileDialog - wxMULTIPLE used on a save dialog" ) );
         m_needParent = false;
-        m_destroyed_by_delete = false;
 
         if (!PreCreation(parent, pos, wxDefaultSize) ||
             !CreateBase(parent, wxID_ANY, pos, wxDefaultSize, style,
@@ -182,6 +175,14 @@ wxFileDialog::wxFileDialog(wxWindow *parent, const wxString& message,
         if ( style & wxMULTIPLE )
             gtk_file_chooser_set_select_multiple(GTK_FILE_CHOOSER(m_widget), true);
 
+        // gtk_widget_hide_on_delete is used here to avoid that Gtk automatically destroys
+        // the dialog when the user press ESC on the dialog: in that case a second call to
+        // ShowModal() would result in a bunch of Gtk-CRITICAL errors...
+        g_signal_connect (G_OBJECT(m_widget),
+                        "delete_event",
+                        G_CALLBACK (gtk_widget_hide_on_delete),
+                        (gpointer)this);
+
         // local-only property could be set to false to allow non-local files to be loaded.
         // In that case get/set_uri(s) should be used instead of get/set_filename(s) everywhere
         // and the GtkFileChooserDialog should probably also be created with a backend,
@@ -232,17 +233,6 @@ wxFileDialog::wxFileDialog(wxWindow *parent, const wxString& message,
         wxGenericFileDialog::Create( parent, message, defaultDir, defaultFileName, wildCard, style, pos );
 }
 
-wxFileDialog::~wxFileDialog()
-{
-#ifdef __WXGTK24__
-    if (!gtk_check_version(2,4,0))
-    {
-        if (m_destroyed_by_delete)
-            m_widget = NULL;
-    }
-#endif
-}
-
 void wxFileDialog::OnFakeOk( wxCommandEvent &event )
 {
 #ifdef __WXGTK24__