X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/49a143664075d786078a899ae8b3c947330f4df2..33cc6200a8c797c72536ca319148c0f712cf658a:/src/gtk1/filedlg.cpp?ds=sidebyside diff --git a/src/gtk1/filedlg.cpp b/src/gtk1/filedlg.cpp index 2376366750..c2dc478759 100644 --- a/src/gtk1/filedlg.cpp +++ b/src/gtk1/filedlg.cpp @@ -21,6 +21,7 @@ #include "wx/intl.h" #include "wx/filename.h" #include "wx/msgdlg.h" +#include "wx/log.h" #include @@ -38,11 +39,18 @@ extern bool g_isIdle; // "clicked" for OK-button //----------------------------------------------------------------------------- +extern "C" { static void gtk_filedialog_ok_callback(GtkWidget *widget, wxFileDialog *dialog) { int style = dialog->GetStyle(); gchar* text = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(widget)); - wxString filename(wxGTK_CONV_BACK(text)); + wxString filename = wxConvFileName->cMB2WX( text ); + if ( filename.empty() ) + { + // this is totally lame but better than silent error + wxLogWarning(_("This filename can't be used by wxWidgets because it contains invalid UTF-8 characters, please rename the file.")); + return; + } if ((style & wxSAVE) && (style & wxOVERWRITE_PROMPT)) { @@ -86,16 +94,18 @@ static void gtk_filedialog_ok_callback(GtkWidget *widget, wxFileDialog *dialog) dialog->SetPath(filename); dialog->UpdateFromDialog(); - + wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, wxID_OK); event.SetEventObject(dialog); dialog->GetEventHandler()->ProcessEvent(event); } +} //----------------------------------------------------------------------------- // "clicked" for Cancel-button //----------------------------------------------------------------------------- +extern "C" { static void gtk_filedialog_cancel_callback(GtkWidget *WXUNUSED(w), wxFileDialog *dialog) { @@ -103,13 +113,15 @@ static void gtk_filedialog_cancel_callback(GtkWidget *WXUNUSED(w), event.SetEventObject(dialog); dialog->GetEventHandler()->ProcessEvent(event); } +} +extern "C" { static void gtk_filedialog_response_callback(GtkWidget *w, int response, wxFileDialog *dialog) { wxapp_install_idle_handler(); - + if (response == GTK_RESPONSE_ACCEPT) gtk_filedialog_ok_callback(w, dialog); else if (response == GTK_RESPONSE_CANCEL) @@ -117,10 +129,12 @@ static void gtk_filedialog_response_callback(GtkWidget *w, else // "delete" { gtk_filedialog_cancel_callback(w, dialog); - dialog->m_destroyed_by_delete = TRUE; + dialog->m_destroyed_by_delete = true; } } -#endif +} + +#endif // __WXGTK24__ //----------------------------------------------------------------------------- // wxFileDialog @@ -143,8 +157,8 @@ wxFileDialog::wxFileDialog(wxWindow *parent, const wxString& message, #ifdef __WXGTK24__ if (!gtk_check_version(2,4,0)) { - m_needParent = FALSE; - m_destroyed_by_delete = FALSE; + m_needParent = false; + m_destroyed_by_delete = false; if (!PreCreation(parent, pos, wxDefaultSize) || !CreateBase(parent, wxID_ANY, pos, wxDefaultSize, style, @@ -159,7 +173,7 @@ wxFileDialog::wxFileDialog(wxWindow *parent, const wxString& message, GtkWindow* gtk_parent = NULL; if (parent) gtk_parent = GTK_WINDOW(parent->m_widget); - + gchar* ok_btn_stock; if ((style & wxSAVE) == wxSAVE) { @@ -180,18 +194,18 @@ wxFileDialog::wxFileDialog(wxWindow *parent, const wxString& message, NULL); gtk_file_chooser_set_select_multiple(GTK_FILE_CHOOSER(m_widget), multiple); - + gtk_signal_connect(GTK_OBJECT(m_widget), - "response", + "response", GTK_SIGNAL_FUNC(gtk_filedialog_response_callback), (gpointer*)this); - + m_path = m_dir; if (!m_path.empty() && m_path.Last() != wxT('/')) m_path += wxT('/'); m_path += m_fileName; SetPath(m_path); - + SetWildcard(wildCard); SetFilterIndex(0); } @@ -241,7 +255,7 @@ bool wxFileDialog::Show( bool show ) return wxGenericFileDialog::Show( show ); } -void wxFileDialog::GetFilenames(wxArrayString& files) const +void wxFileDialog::GetFilenames(wxArrayString& files) const { #ifdef __WXGTK24__ if (!gtk_check_version(2,4,0)) @@ -251,7 +265,7 @@ void wxFileDialog::GetFilenames(wxArrayString& files) const { wxString name,ext; wxSplitPath(files[n], NULL, &name, &ext); - if (!ext.IsEmpty()) + if (!ext.empty()) { name += wxT("."); name += ext; @@ -264,15 +278,15 @@ void wxFileDialog::GetFilenames(wxArrayString& files) const wxGenericFileDialog::GetFilenames( files ); } -void wxFileDialog::GetPaths(wxArrayString& paths) const +void wxFileDialog::GetPaths(wxArrayString& paths) const { #ifdef __WXGTK24__ if (!gtk_check_version(2,4,0)) { - paths.Empty(); + paths.Empty(); if (GetWindowStyle() & wxMULTIPLE) { - GSList *gpathsi = + GSList *gpathsi = gtk_file_chooser_get_filenames(GTK_FILE_CHOOSER(m_widget)); GSList *gpaths = gpathsi; while (gpathsi) @@ -282,10 +296,11 @@ void wxFileDialog::GetPaths(wxArrayString& paths) const g_free(gpathsi->data); gpathsi = gpathsi->next; } - if (gpaths) + if (gpaths) g_slist_free(gpaths); } - else + + if ( paths.IsEmpty() ) { paths.Add(m_fileName); } @@ -304,7 +319,7 @@ void wxFileDialog::SetMessage(const wxString& message) SetTitle(message); } else -#endif +#endif wxGenericFileDialog::SetMessage( message ); } @@ -322,7 +337,7 @@ void wxFileDialog::SetPath(const wxString& path) UpdateDialog(); } else -#endif +#endif wxGenericFileDialog::SetPath( path ); } @@ -331,7 +346,7 @@ void wxFileDialog::SetDirectory(const wxString& dir) #ifdef __WXGTK24__ if (!gtk_check_version(2,4,0)) { - if (wxDirExists(dir)) + if (wxPathExists(dir)) { m_dir = dir; m_path = wxFileName(m_dir, m_fileName).GetFullPath(); @@ -339,7 +354,7 @@ void wxFileDialog::SetDirectory(const wxString& dir) } } else -#endif +#endif wxGenericFileDialog::SetDirectory( dir ); } @@ -364,7 +379,7 @@ void wxFileDialog::SetWildcard(const wxString& wildCard) { 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; @@ -374,7 +389,7 @@ void wxFileDialog::SetWildcard(const wxString& wildCard) ifilters = ifilters->next; } g_slist_free(filters); - + // parse filters wxArrayString wildDescriptions, wildFilters; if (!wxParseCommonDialogsFilter(m_wildCard, wildDescriptions, wildFilters)) @@ -398,7 +413,7 @@ void wxFileDialog::SetWildcard(const wxString& wildCard) after = after.AfterLast(wxT(';')); } while (!after.empty()); - + gtk_file_chooser_add_filter(chooser, filter); } } @@ -441,7 +456,7 @@ void wxFileDialog::UpdateDialog() { #ifdef __WXGTK24__ // set currently selected directory to match the path: - if (!m_dir.empty() && wxDirExists(m_dir)) + if (!m_dir.empty() && wxPathExists(m_dir)) { // NB: This is important -- if we set directory only and not the path, // then dialog will still remember old path set using previous @@ -456,18 +471,18 @@ void wxFileDialog::UpdateDialog() if (m_fileName.empty()) gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(m_widget), wxGTK_CONV(m_dir)); - + gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(m_widget), wxGTK_CONV(m_dir)); } - + // if the user set only the directory (e.g. by calling SetDirectory) // and not the default filename, then we don't want to set the filename: if (!m_fileName.empty()) { gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(m_widget), wxGTK_CONV(m_path)); - + // pre-fill the filename when saving, too (there's no text entry // control when opening a file, so it doesn't make sense to // do this when opening files): @@ -488,7 +503,7 @@ void wxFileDialog::UpdateFromDialog() GSList *filters = fnode; GtkFileFilter *current = gtk_file_chooser_get_filter(GTK_FILE_CHOOSER(m_widget)); - + int i = 0; m_filterIndex = 0; while (fnode)