+ gtk_file_chooser_set_filename(
+ GTK_FILE_CHOOSER(m_widget),
+ wxConvFileName->cWX2MB( wxFileName(dir, defaultFileName).GetFullPath() ) );
+ }
+ else if ( !defaultDir.empty() )
+ gtk_file_chooser_set_current_folder( GTK_FILE_CHOOSER(m_widget),
+ wxConvFileName->cWX2MB(defaultDir) );
+ }
+ }
+ else
+#endif
+ 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__
+ if (!gtk_check_version(2,4,0))
+ wxDialog::OnOK( event );
+ else
+#endif
+ wxGenericFileDialog::OnListOk( event );
+}
+
+int wxFileDialog::ShowModal()
+{
+#ifdef __WXGTK24__
+ if (!gtk_check_version(2,4,0))
+ return wxDialog::ShowModal();
+ else
+#endif
+ return wxGenericFileDialog::ShowModal();
+}
+
+bool wxFileDialog::Show( bool show )
+{
+#ifdef __WXGTK24__
+ if (!gtk_check_version(2,4,0))
+ return wxDialog::Show( show );
+ else
+#endif
+ return wxGenericFileDialog::Show( show );
+}
+
+wxString wxFileDialog::GetPath() const
+{
+#ifdef __WXGTK24__
+ if (!gtk_check_version(2,4,0))
+ return wxConvFileName->cMB2WX(gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(m_widget)));
+ else
+#endif
+ return wxGenericFileDialog::GetPath();
+}
+
+void wxFileDialog::GetFilenames(wxArrayString& files) const
+{
+#ifdef __WXGTK24__
+ if (!gtk_check_version(2,4,0))
+ {
+ GetPaths(files);
+ for (size_t n = 0; n < files.GetCount(); ++n )
+ {
+ wxFileName file(files[n]);
+ files[n] = file.GetFullName();
+ }
+ }
+ else
+#endif
+ wxGenericFileDialog::GetFilenames( files );
+}
+
+void wxFileDialog::GetPaths(wxArrayString& paths) const
+{
+#ifdef __WXGTK24__
+ if (!gtk_check_version(2,4,0))
+ {
+ paths.Empty();
+ if (gtk_file_chooser_get_select_multiple(GTK_FILE_CHOOSER(m_widget)))
+ {
+ GSList *gpathsi = gtk_file_chooser_get_filenames(GTK_FILE_CHOOSER(m_widget));
+ GSList *gpaths = gpathsi;
+ while (gpathsi)
+ {
+ wxString file(wxConvFileName->cMB2WX((gchar*) gpathsi->data));
+ paths.Add(file);
+ g_free(gpathsi->data);
+ gpathsi = gpathsi->next;
+ }
+
+ g_slist_free(gpaths);
+ }
+ else
+ paths.Add(GetPath());
+ }
+ else
+#endif
+ wxGenericFileDialog::GetPaths( paths );
+}
+
+void wxFileDialog::SetMessage(const wxString& message)
+{
+#ifdef __WXGTK24__
+ if (!gtk_check_version(2,4,0))
+ {
+ m_message = message;
+ SetTitle(message);
+ }
+ else
+#endif
+ wxGenericFileDialog::SetMessage( message );
+}
+
+void wxFileDialog::SetPath(const wxString& path)
+{
+#ifdef __WXGTK24__
+ if (!gtk_check_version(2,4,0))
+ {
+ if (path.empty()) return;
+
+ gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(m_widget), wxConvFileName->cWX2MB(path));
+ }
+ else
+#endif
+ wxGenericFileDialog::SetPath( path );
+}
+
+void wxFileDialog::SetDirectory(const wxString& dir)
+{
+#ifdef __WXGTK24__
+ if (!gtk_check_version(2,4,0))
+ {
+ if (wxDirExists(dir))
+ {
+ gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(m_widget), wxConvFileName->cWX2MB(dir));
+ }
+ }
+ else
+#endif
+ wxGenericFileDialog::SetDirectory( dir );
+}
+
+wxString wxFileDialog::GetDirectory() const
+{
+#ifdef __WXGTK24__
+ if (!gtk_check_version(2,4,0))
+ return wxConvFileName->cMB2WX(
+ gtk_file_chooser_get_current_folder( GTK_FILE_CHOOSER(m_widget) ) );
+ else
+#endif
+ return wxGenericFileDialog::GetDirectory();
+}
+
+void wxFileDialog::SetFilename(const wxString& name)
+{
+#ifdef __WXGTK24__
+ if (!gtk_check_version(2,4,0))
+ {
+ if (GetStyle() & wxSAVE)
+ gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(m_widget), wxConvFileName->cWX2MB(name));
+ else
+ SetPath(wxFileName(GetDirectory(), name).GetFullPath());
+ }
+ else
+#endif
+ wxGenericFileDialog::SetFilename( name );
+}
+
+wxString wxFileDialog::GetFilename() const
+{
+#ifdef __WXGTK24__
+ if (!gtk_check_version(2,4,0))
+ return wxFileName(
+ wxConvFileName->cMB2WX(gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(m_widget))) ).GetFullName();
+ else
+#endif
+ return wxGenericFileDialog::GetFilename();
+}
+
+void wxFileDialog::SetWildcard(const wxString& wildCard)
+{
+#ifdef __WXGTK24__
+ if (!gtk_check_version(2,4,0))
+ {
+ // parse filters
+ wxArrayString wildDescriptions, wildFilters;
+ if (!wxParseCommonDialogsFilter(wildCard, wildDescriptions, wildFilters))
+ {
+ wxFAIL_MSG( wxT("wxFileDialog::SetWildCard - bad wildcard string") );
+ }
+ else
+ {
+ // Parsing went fine. Set m_wildCard to be returned by wxFileDialogBase::GetWildcard
+ m_wildCard = wildCard;
+
+ GtkFileChooser* chooser = GTK_FILE_CHOOSER(m_widget);
+
+ // empty current filter list:
+ GSList* ifilters = gtk_file_chooser_list_filters(chooser);
+ GSList* filters = ifilters;
+
+ while (ifilters)
+ {
+ gtk_file_chooser_remove_filter(chooser,GTK_FILE_FILTER(ifilters->data));
+ ifilters = ifilters->next;
+ }
+ g_slist_free(filters);
+
+ // add parsed to GtkChooser
+ for (size_t n = 0; n < wildFilters.GetCount(); ++n)
+ {
+ GtkFileFilter* filter = gtk_file_filter_new();
+ gtk_file_filter_set_name(filter, wxGTK_CONV(wildDescriptions[n]));
+
+ wxStringTokenizer exttok(wildFilters[n], wxT(";"));
+ while (exttok.HasMoreTokens())
+ {
+ wxString token = exttok.GetNextToken();
+ gtk_file_filter_add_pattern(filter, wxGTK_CONV(token));
+ }
+
+ gtk_file_chooser_add_filter(chooser, filter);
+ }
+
+ // Reset the filter index
+ SetFilterIndex(0);
+ }
+ }
+ else
+#endif
+ wxGenericFileDialog::SetWildcard( wildCard );
+}
+
+void wxFileDialog::SetFilterIndex(int filterIndex)
+{
+#ifdef __WXGTK24__
+ if (!gtk_check_version(2,4,0))
+ {
+ gpointer filter;
+ GtkFileChooser *chooser = GTK_FILE_CHOOSER(m_widget);
+ GSList *filters = gtk_file_chooser_list_filters(chooser);
+
+ filter = g_slist_nth_data(filters, filterIndex);
+
+ if (filter != NULL)
+ {
+ gtk_file_chooser_set_filter(chooser, GTK_FILE_FILTER(filter));
+ }
+ else
+ {
+ wxFAIL_MSG( wxT("wxFileDialog::SetFilterIndex - bad filter index") );
+ }
+
+ g_slist_free(filters);
+ }
+ else
+#endif
+ wxGenericFileDialog::SetFilterIndex( filterIndex );
+}
+
+int wxFileDialog::GetFilterIndex() const
+{
+#ifdef __WXGTK24__
+ if (!gtk_check_version(2,4,0))
+ {
+ GtkFileChooser *chooser = GTK_FILE_CHOOSER(m_widget);
+ GtkFileFilter *filter = gtk_file_chooser_get_filter(chooser);
+ GSList *filters = gtk_file_chooser_list_filters(chooser);
+ gint index = g_slist_index(filters, filter);
+ g_slist_free(filters);
+
+ if (index == -1)
+ {
+ wxFAIL_MSG( wxT("wxFileDialog::GetFilterIndex - bad filter index returned by gtk+") );
+ return 0;
+ }
+ else
+ return index;
+ }
+ else
+#endif
+ return wxGenericFileDialog::GetFilterIndex();
+}