]> git.sesse.net Git - vlc/blobdiff - modules/gui/wxwidgets/wxwidgets.hpp
* modules/gui/wxwidgets: small code cleanup.
[vlc] / modules / gui / wxwidgets / wxwidgets.hpp
index c8e20df230ae609e66960603d99ec79a05ec7ddb..59c47862c165d56806b47d46f0456de7a60565f3 100644 (file)
@@ -39,6 +39,7 @@
 
 #include <vlc/vlc.h>
 #include <vlc/intf.h>
+#include "charset.h"
 
 #include <wx/wx.h>
 #define SLIDER_MAX_POS 10000
@@ -68,36 +69,48 @@ DECLARE_LOCAL_EVENT_TYPE( wxEVT_INTF, 1 );
  * I18N macros
  ***************************************************************************/
 
-/* wxU is used to convert ansi/utf8 strings to unicode strings (wchar_t) */
-#if defined( ENABLE_NLS )
+/*
+ * wxU() is used to convert UTF-8 strings (typically from gettext)
+ * to unicode strings (wchar_t).
+ */
 #if wxUSE_UNICODE
 #   define wxU(utf8) wxString(utf8, wxConvUTF8)
 #else
 #   define wxU(utf8) wxString(wxConvUTF8.cMB2WC(utf8), *wxConvCurrent)
 #endif
-#else // ENABLE_NLS
-#if wxUSE_UNICODE
-#   define wxU(ansi) wxString(ansi, wxConvLocal)
-#else
-#   define wxU(ansi) (ansi)
-#endif
-#endif
 
-/* wxL2U (locale to unicode) is used to convert ansi strings to unicode
- * strings (wchar_t) */
-#define wxL2U(ansi) wxU(ansi)
+/*
+ * wxL2U() use to convert localized “data” strings (while wxU() would convert
+ * strings from gettext messages). Nowadays, the core use UTF-8 internally
+ * and wxL2U() is only an obsoleted name for wxU().
+ */
+#define wxL2U(utf8) wxU(utf8)
 
+/*
+ * wxFromLocale() is a replacement for LibVLC FromLocale() that accepts
+ * a wxString. It was originally introduced because wxString::mb_str()
+ * sucks on Linux with Unicode wxWidgets. It then turned out wxWidgets
+ * did not support wc_str() when Unicode was not enabled.
+ *
+ * But heh, that's wxWidgets; you can't really expect it to actually
+ * work, let alone work like its documentation says.
+ *
+ * Did it work, we would be able to catch non-ANSI characters on Windows
+ * through wxString::wc_str(); while they are lost when using mb_str().
+ * This would be particularly useful to open files whose names contain
+ * non-ACP characters.
+ */
 #if wxUSE_UNICODE
-#   define wxFromLocale(wxstring) FromUTF32(wxstring.wc_str())
+#   define wxFromLocale(wxstring) FromWide(wxstring.wc_str())
 #   define wxLocaleFree(string) free(string)
 #else
 #   define wxFromLocale(wxstring) FromLocale(wxstring.mb_str())
 #   define wxLocaleFree(string) LocaleFree(string)
 #endif
-
+       
 /* From Locale functions to use for File Drop targets ... go figure */
 #ifdef wxUSE_UNICODE
-inline const char *wxDnDFromLocale( const wxChar *stupid )
+static inline char *wxDnDFromLocale( const wxChar *stupid )
 {
     /*
      * FIXME: this is yet another awful and ugly bug-to-bug work-around
@@ -119,19 +132,18 @@ inline const char *wxDnDFromLocale( const wxChar *stupid )
     for (braindead = stupid; *braindead; braindead++);
 
     size_t i = (braindead - stupid);
-    char *psz_local = (char *)malloc( i + 1 );
+    char psz_local[i + 1];
     do
         psz_local[i] = (char)stupid[i];
     while (i--);
 
-    const char *psz_utf8 = FromLocale( psz_local );
-    free( psz_local );
-    return psz_utf8;
+    return FromLocaleDup( psz_local );
 }
+#   define wxDnDLocaleFree( string ) free( string )
 #else
 #   define wxDnDFromLocale( string ) wxFromLocale( string )
+#   define wxDnDLocaleFree( string ) wxLocaleFree( string )
 #endif
-#define wxDnDLocaleFree(string) LocaleFree( string )
 
 #define WRAPCOUNT 80
 
@@ -151,10 +163,6 @@ namespace wxvlc {
 
 using namespace wxvlc;
 
-class DialogsProvider;
-class PrefsTreeCtrl;
-class AutoBuiltPanel;
-
 /*****************************************************************************
  * intf_sys_t: description and status of wxwindows interface
  *****************************************************************************/