]> git.saurik.com Git - wxWidgets.git/commitdiff
Always use UTF-8 for file names passed to GTK+ functions under MSW.
authorVadim Zeitlin <vadim@wxwidgets.org>
Sun, 8 Apr 2012 18:10:29 +0000 (18:10 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Sun, 8 Apr 2012 18:10:29 +0000 (18:10 +0000)
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
src/gtk/animate.cpp
src/gtk/app.cpp
src/gtk/bitmap.cpp
src/gtk/dirdlg.cpp
src/gtk/filectrl.cpp
src/gtk/filedlg.cpp
src/gtk/filehistory.cpp

index 728a24e1b18f162b3ee4e1c9e8fb278854fc9b6d..9892e2fd5c0d57a39c9def812a916177670c3038 100644 (file)
@@ -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
 // ----------------------------------------------------------------------------
index 01034dee8b1ea8eb2c830a1a6b870475e25acb1e..6526c699a177a034bb96a62c882a81d3c621a1fd 100644 (file)
@@ -23,6 +23,7 @@
 #endif
 
 #include "wx/wfstream.h"
+#include "wx/gtk/private.h"
 
 #include <gtk/gtk.h>
 
@@ -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();
 }
 
index 7de062baa1cecd8952aeb7d025ae643e76421f95..ebe21af915cd4a0d0e05e272ef79edc845928dfe 100644 (file)
@@ -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;
index 4519ea932e65da8389cd7f4c66136f05aeda7b1a..9a730d853426f5968d1f87fd3b03d48a34df0c2b 100644 (file)
@@ -21,6 +21,7 @@
 #include "wx/rawbmp.h"
 
 #include "wx/gtk/private/object.h"
+#include "wx/gtk/private.h"
 
 #include <gtk/gtk.h>
 
@@ -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();
index 3843eb3ac500ae87db67361a1c8d898b6b75cc4b..a877cbabfe792bba816c8d49cdce2972837cb80d 100644 (file)
@@ -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));
     }
 }
 
index eec4ce2a7a21bfd2065bde5ef890319fd2c1661f..5d608029045668ee48e83114ac1170a105f51768 100644 (file)
@@ -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()) );
         }
     }
 
index b1a370e37606f43a4b9901064d5bf9eb54dc9770..ef6f3e0eea47465e23780d697f41714822f25364 100644 (file)
@@ -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()));
         }
     }
 
index c85267fa7839f5ebbd0a294e00815023df8c3963..0f482597dddd5b73eb888ee8aa76e9b605df1bd5 100644 (file)
@@ -32,6 +32,7 @@
 #include <glib.h>
 #include <gtk/gtk.h>
 #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);