#include <vlc/vlc.h>
#include <vlc/intf.h>
+#include "charset.h"
#include <wx/wx.h>
#define SLIDER_MAX_POS 10000
* 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
+static inline char *wxDnDFromLocale( const wxChar *stupid )
+{
+ /*
+ * FIXME: this is yet another awful and ugly bug-to-bug work-around
+ * for the painfully broken and brain-dead wxWidgets character
+ * encoding internals. Maybe, one day the wxWidgets team will find out
+ * and we will have to remove (phew) this kludge or autodetect whether
+ * to trigger it (damn).
+ *
+ * In Unicode mode, wxWidgets will encode file names in the locale
+ * encoding with each **bytes** (rather than characters) represented
+ * by a 32 bits unsigned integer. If you are lucky enough to be using
+ * ISO-8859-1 as your local character encoding, that lame encoding
+ * scheme happens to be identical to UTF-32 with your arch native
+ * byte-endianess. If you are using anything else, including not only
+ * UTF-8 but also Windows-1252(!) and ISO-8859-15(!) or any
+ * non-western encoding, it obviously fails.
+ */
+ const wxChar *braindead;
+ for (braindead = stupid; *braindead; braindead++);
+
+ size_t i = (braindead - stupid);
+ char psz_local[i + 1];
+ do
+ psz_local[i] = (char)stupid[i];
+ while (i--);
+
+ return FromLocaleDup( psz_local );
+}
+# define wxDnDLocaleFree( string ) free( string )
+#else
+# define wxDnDFromLocale( string ) wxFromLocale( string )
+# define wxDnDLocaleFree( string ) wxLocaleFree( string )
+#endif
#define WRAPCOUNT 80