From c282e47d8f2179954ca40688677961c169688084 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 8 Apr 2012 18:10:29 +0000 Subject: [PATCH] Always use UTF-8 for file names passed to GTK+ functions under MSW. When building wxGTK under MSW, always use UTF-8 as file name encoding because GTK+ doesn't use G_FILENAME_ENCODING there. Add a helper wxGTK_CONV_FN() macro to hide the difference between the platforms. Closes #14035. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@71154 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/gtk/private.h | 11 +++++++++++ src/gtk/animate.cpp | 3 ++- src/gtk/app.cpp | 2 ++ src/gtk/bitmap.cpp | 5 +++-- src/gtk/dirdlg.cpp | 5 +++-- src/gtk/filectrl.cpp | 6 +++--- src/gtk/filedlg.cpp | 6 +++--- src/gtk/filehistory.cpp | 3 ++- 8 files changed, 29 insertions(+), 12 deletions(-) diff --git a/include/wx/gtk/private.h b/include/wx/gtk/private.h index 728a24e1b1..9892e2fd5c 100644 --- a/include/wx/gtk/private.h +++ b/include/wx/gtk/private.h @@ -87,6 +87,17 @@ extern const gchar *wx_pango_version_check(int major, int minor, int micro); #define wxGTK_CONV_BACK_SYS(s) wxConvertFromGTK((s)) #endif +// Define a macro for converting wxString to char* in appropriate encoding for +// the file names. +#ifdef G_OS_WIN32 + // Under MSW, UTF-8 file name encodings are always used. + #define wxGTK_CONV_FN(s) (s).utf8_str() +#else + // Under Unix use GLib file name encoding (which is also UTF-8 by default + // but may be different from it). + #define wxGTK_CONV_FN(s) (s).fn_str() +#endif + // ---------------------------------------------------------------------------- // various private helper functions // ---------------------------------------------------------------------------- diff --git a/src/gtk/animate.cpp b/src/gtk/animate.cpp index 01034dee8b..6526c699a1 100644 --- a/src/gtk/animate.cpp +++ b/src/gtk/animate.cpp @@ -23,6 +23,7 @@ #endif #include "wx/wfstream.h" +#include "wx/gtk/private.h" #include @@ -84,7 +85,7 @@ wxAnimation& wxAnimation::operator=(const wxAnimation& that) bool wxAnimation::LoadFile(const wxString &name, wxAnimationType WXUNUSED(type)) { UnRef(); - m_pixbuf = gdk_pixbuf_animation_new_from_file(name.fn_str(), NULL); + m_pixbuf = gdk_pixbuf_animation_new_from_file(wxGTK_CONV_FN(name), NULL); return IsOk(); } diff --git a/src/gtk/app.cpp b/src/gtk/app.cpp index 7de062baa1..ebe21af915 100644 --- a/src/gtk/app.cpp +++ b/src/gtk/app.cpp @@ -297,6 +297,7 @@ bool wxApp::Initialize(int& argc_, wxChar **argv_) // gtk+ 2.0 supports Unicode through UTF-8 strings wxConvCurrent = &wxConvUTF8; +#ifdef __UNIX__ // decide which conversion to use for the file names // (1) this variable exists for the sole purpose of specifying the encoding @@ -345,6 +346,7 @@ bool wxApp::Initialize(int& argc_, wxChar **argv_) #endif // wxUSE_INTL static wxConvBrokenFileNames fileconv(encName); wxConvFileName = &fileconv; +#endif // __UNIX__ bool init_result; diff --git a/src/gtk/bitmap.cpp b/src/gtk/bitmap.cpp index 4519ea932e..9a730d8534 100644 --- a/src/gtk/bitmap.cpp +++ b/src/gtk/bitmap.cpp @@ -21,6 +21,7 @@ #include "wx/rawbmp.h" #include "wx/gtk/private/object.h" +#include "wx/gtk/private.h" #include @@ -677,7 +678,7 @@ bool wxBitmap::SaveFile( const wxString &name, wxBitmapType type, const wxPalett default: break; } return type_name && - gdk_pixbuf_save(GetPixbuf(), name.fn_str(), type_name, NULL, NULL); + gdk_pixbuf_save(GetPixbuf(), wxGTK_CONV_FN(name), type_name, NULL, NULL); } bool wxBitmap::LoadFile( const wxString &name, wxBitmapType type ) @@ -691,7 +692,7 @@ bool wxBitmap::LoadFile( const wxString &name, wxBitmapType type ) { wxUnusedVar(type); // The type is detected automatically by GDK. - *this = wxBitmap(gdk_pixbuf_new_from_file(name.fn_str(), NULL)); + *this = wxBitmap(gdk_pixbuf_new_from_file(wxGTK_CONV_FN(name), NULL)); } return IsOk(); diff --git a/src/gtk/dirdlg.cpp b/src/gtk/dirdlg.cpp index 3843eb3ac5..a877cbabfe 100644 --- a/src/gtk/dirdlg.cpp +++ b/src/gtk/dirdlg.cpp @@ -157,7 +157,8 @@ bool wxDirDialog::Create(wxWindow* parent, if ( !defaultPath.empty() ) gtk_file_chooser_set_current_folder( GTK_FILE_CHOOSER(m_widget), - defaultPath.fn_str() ); + wxGTK_CONV_FN(defaultPath) ); + return true; } @@ -179,7 +180,7 @@ void wxDirDialog::SetPath(const wxString& dir) if (wxDirExists(dir)) { gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(m_widget), - dir.fn_str()); + wxGTK_CONV_FN(dir)); } } diff --git a/src/gtk/filectrl.cpp b/src/gtk/filectrl.cpp index eec4ce2a7a..5d60802904 100644 --- a/src/gtk/filectrl.cpp +++ b/src/gtk/filectrl.cpp @@ -362,7 +362,7 @@ bool wxGtkFileCtrl::Create( wxWindow *parent, if ( !dir.empty() ) { gtk_file_chooser_set_current_folder( m_fcWidget, - dir.fn_str() ); + wxGTK_CONV_FN(dir) ); } const wxString fname = fn.GetFullName(); @@ -371,7 +371,7 @@ bool wxGtkFileCtrl::Create( wxWindow *parent, if ( !fname.empty() ) { gtk_file_chooser_set_current_name( m_fcWidget, - fname.fn_str() ); + wxGTK_CONV_FN(fname) ); } } else // wxFC_OPEN @@ -379,7 +379,7 @@ bool wxGtkFileCtrl::Create( wxWindow *parent, if ( !fname.empty() ) { gtk_file_chooser_set_filename( m_fcWidget, - fn.GetFullPath().fn_str() ); + wxGTK_CONV_FN(fn.GetFullPath()) ); } } diff --git a/src/gtk/filedlg.cpp b/src/gtk/filedlg.cpp index b1a370e376..ef6f3e0eea 100644 --- a/src/gtk/filedlg.cpp +++ b/src/gtk/filedlg.cpp @@ -288,7 +288,7 @@ bool wxFileDialog::Create(wxWindow *parent, const wxString& message, const wxString dir = fn.GetPath(); if ( !dir.empty() ) { - gtk_file_chooser_set_current_folder(file_chooser, dir.fn_str()); + gtk_file_chooser_set_current_folder(file_chooser, wxGTK_CONV_FN(dir)); } const wxString fname = fn.GetFullName(); @@ -296,7 +296,7 @@ bool wxFileDialog::Create(wxWindow *parent, const wxString& message, { if ( !fname.empty() ) { - gtk_file_chooser_set_current_name(file_chooser, fname.fn_str()); + gtk_file_chooser_set_current_name(file_chooser, wxGTK_CONV_FN(fname)); } #if GTK_CHECK_VERSION(2,7,3) @@ -309,7 +309,7 @@ bool wxFileDialog::Create(wxWindow *parent, const wxString& message, if ( !fname.empty() ) { gtk_file_chooser_set_filename(file_chooser, - fn.GetFullPath().fn_str()); + wxGTK_CONV_FN(fn.GetFullPath())); } } diff --git a/src/gtk/filehistory.cpp b/src/gtk/filehistory.cpp index c85267fa78..0f482597dd 100644 --- a/src/gtk/filehistory.cpp +++ b/src/gtk/filehistory.cpp @@ -32,6 +32,7 @@ #include #include #include "wx/gtk/private/string.h" +#include "wx/gtk/private.h" // ============================================================================ // implementation @@ -45,7 +46,7 @@ void wxFileHistory::AddFileToHistory(const wxString& file) const wxString fullPath = wxFileName(file).GetFullPath(); if ( !gtk_check_version(2,10,0) ) { - wxGtkString uri(g_filename_to_uri(fullPath.fn_str(), NULL, NULL)); + wxGtkString uri(g_filename_to_uri(wxGTK_CONV_FN(fullPath), NULL, NULL)); if ( uri ) gtk_recent_manager_add_item(gtk_recent_manager_get_default(), uri); -- 2.45.2