+
+// ----------------------------------------------------------------------------
+// wxConvBrokenFileNames is made for GTK2 in Unicode mode when
+// files are accidentally written in an encoding which is not
+// the system encoding. Typically, the system encoding will be
+// UTF8 but there might be files stored in ISO8859-1 on disk.
+// ----------------------------------------------------------------------------
+
+class wxConvBrokenFileNames: public wxMBConvLibc
+{
+public:
+ wxConvBrokenFileNames() : m_utf8conv(wxMBConvUTF8::MAP_INVALID_UTF8_TO_OCTAL) { }
+ virtual size_t MB2WC(wchar_t *outputBuf, const char *psz, size_t outputSize) const;
+ virtual size_t WC2MB(char *outputBuf, const wchar_t *psz, size_t outputSize) const;
+ inline bool UseUTF8() const;
+private:
+ wxMBConvUTF8 m_utf8conv;
+};
+
+bool wxConvBrokenFileNames::UseUTF8() const
+{
+#if defined HAVE_LANGINFO_H && defined CODESET
+ char *codeset = nl_langinfo(CODESET);
+ return strcmp(codeset, "UTF-8") == 0;
+#else
+ return false;
+#endif
+}
+
+size_t wxConvBrokenFileNames::MB2WC(wchar_t *outputBuf, const char *psz, size_t outputSize) const
+{
+ if (UseUTF8())
+ return m_utf8conv.MB2WC( outputBuf, psz, outputSize );
+ else
+ return wxMBConvLibc::MB2WC( outputBuf, psz, outputSize );
+}
+
+size_t wxConvBrokenFileNames::WC2MB(char *outputBuf, const wchar_t *psz, size_t outputSize) const
+{
+ if (UseUTF8())
+ return m_utf8conv.WC2MB( outputBuf, psz, outputSize );
+ else
+ return wxMBConvLibc::WC2MB( outputBuf, psz, outputSize );
+}
+