+#endif // HAVE_ICONV
+
+// ============================================================================
+// Win32 conversion classes
+// ============================================================================
+
+#if defined(__WIN32__) && !defined(__WXMICROWIN__)
+
+extern long wxCharsetToCodepage(const wxChar *charset); // from utils.cpp
+
+class CP_CharSet : public wxCharacterSet
+{
+public:
+ CP_CharSet(const wxChar* name)
+ : wxCharacterSet(name)
+ {
+ m_CodePage = wxCharsetToCodepage(name);
+ }
+
+ size_t MB2WC(wchar_t *buf, const char *psz, size_t n)
+ {
+ size_t len =
+ MultiByteToWideChar(m_CodePage, 0, psz, -1, buf, buf ? n : 0);
+ //VS: returns # of written chars for buf!=NULL and *size*
+ // needed buffer for buf==NULL
+ return len ? (buf ? len : len-1) : (size_t)-1;
+ }
+
+ size_t WC2MB(char *buf, const wchar_t *psz, size_t n)
+ {
+ size_t len = WideCharToMultiByte(m_CodePage, 0, psz, -1, buf,
+ buf ? n : 0, NULL, NULL);
+ //VS: returns # of written chars for buf!=NULL and *size*
+ // needed buffer for buf==NULL
+ return len ? (buf ? len : len-1) : (size_t)-1;
+ }
+
+ bool usable() const
+ { return m_CodePage != -1; }
+
+public:
+ long m_CodePage;
+};
+#endif // __WIN32__
+
+// ============================================================================
+// wxEncodingConverter based conversion classes
+// ============================================================================
+
+#if wxUSE_FONTMAP
+
+class EC_CharSet : public wxCharacterSet
+{
+public:
+ // temporarily just use wxEncodingConverter stuff,
+ // so that it works while a better implementation is built
+ EC_CharSet(const wxChar* name) : wxCharacterSet(name),
+ enc(wxFONTENCODING_SYSTEM)
+ {
+ if (name)
+ enc = wxTheFontMapper->CharsetToEncoding(name, FALSE);
+
+ m_ok = m2w.Init(enc, wxFONTENCODING_UNICODE) &&
+ w2m.Init(wxFONTENCODING_UNICODE, enc);
+ }
+
+ size_t MB2WC(wchar_t *buf, const char *psz, size_t WXUNUSED(n))
+ {
+ size_t inbuf = strlen(psz);
+ if (buf)
+ m2w.Convert(psz,buf);
+ return inbuf;
+ }
+
+ size_t WC2MB(char *buf, const wchar_t *psz, size_t WXUNUSED(n))
+ {
+#if ( defined(__BORLANDC__) && (__BORLANDC__ > 0x530) ) \
+ || ( defined(__MWERKS__) && defined(__WXMSW__) )
+ size_t inbuf = std::wcslen(psz);
+#else
+ size_t inbuf = ::wcslen(psz);
+#endif
+ if (buf)
+ w2m.Convert(psz,buf);
+
+ return inbuf;
+ }
+
+ bool usable() const { return m_ok; }
+
+public:
+ wxFontEncoding enc;
+ wxEncodingConverter m2w, w2m;
+
+ // were we initialized successfully?
+ bool m_ok;
+};
+
+#endif // wxUSE_FONTMAP
+
+// ----------------------------------------------------------------------------
+// the function creating the wxCharacterSet for the specified charset on the
+// current system, trying all possibilities
+// ----------------------------------------------------------------------------
+
+static wxCharacterSet *wxGetCharacterSet(const wxChar *name)