#include <string.h>
#include <stdlib.h>
+
+#include "wx/debug.h"
+#include "wx/strconv.h"
+#include "wx/intl.h"
+#include "wx/log.h"
+
+// ----------------------------------------------------------------------------
+// globals
+// ----------------------------------------------------------------------------
+
+WXDLLEXPORT_DATA(wxMBConv *) wxConvCurrent = &wxConvLibc;
+
+
+// ============================================================================
+// implementation
+// ============================================================================
+
+#if wxUSE_WCHAR_T
+
#ifdef __SALFORDC__
#include <clib.h>
#endif
#include <windows.h>
#endif
-#include "wx/debug.h"
-#include "wx/strconv.h"
-#include "wx/intl.h"
-#include "wx/log.h"
-
#define BSWAP_UCS4(str, len) { unsigned _c; for (_c=0; _c<len; _c++) str[_c]=wxUINT32_SWAP_ALWAYS(str[_c]); }
#define BSWAP_UTF16(str, len) { unsigned _c; for (_c=0; _c<len; _c++) str[_c]=wxUINT16_SWAP_ALWAYS(str[_c]); }
#error "Weird sizeof(wchar_t): please report your platform details to wx-users mailing list"
#endif
-// ----------------------------------------------------------------------------
-// globals
-// ----------------------------------------------------------------------------
-
-WXDLLEXPORT_DATA(wxMBConv *) wxConvCurrent = &wxConvLibc;
-
-// ============================================================================
-// implementation
-// ============================================================================
-
-#if wxUSE_WCHAR_T
#ifdef WC_UTF16
// - move wxEncodingConverter meat in here
#if defined(__WIN32__) && !defined(__WXMICROWIN__)
+
+#if wxUSE_GUI
+
+// VZ: the new version of wxCharsetToCodepage() is more politically correct
+// and should work on other Windows versions as well but the old version is
+// still needed for !wxUSE_FONTMAP || !wxUSE_GUI case
+
+extern long wxEncodingToCodepage(wxFontEncoding encoding)
+{
+ // translate encoding into the Windows CHARSET
+ wxNativeEncodingInfo natveEncInfo;
+ if ( !wxGetNativeFontEncoding(encoding, &natveEncInfo) )
+ return -1;
+
+ // translate CHARSET to code page
+ CHARSETINFO csetInfo;
+ if ( !::TranslateCharsetInfo((DWORD *)(DWORD)natveEncInfo.charset,
+ &csetInfo,
+ TCI_SRCCHARSET) )
+ {
+ wxLogLastError(_T("TranslateCharsetInfo(TCI_SRCCHARSET)"));
+
+ return -1;
+ }
+
+ return csetInfo.ciACP;
+}
+
+#if wxUSE_FONTMAP
+
+extern long wxCharsetToCodepage(const wxChar *name)
+{
+ // first get the font encoding for this charset
+ if ( !name )
+ return -1;
+
+ wxFontEncoding enc = wxTheFontMapper->CharsetToEncoding(name, FALSE);
+ if ( enc == wxFONTENCODING_SYSTEM )
+ return -1;
+
+ // the use the helper function
+ return wxEncodingToCodepage(enc);
+}
+
+#endif // wxUSE_FONTMAP
+
+#endif // wxUSE_GUI
+
+// include old wxCharsetToCodepage() by OK if needed
+#if !wxUSE_GUI || !wxUSE_FONTMAP
+
#include "wx/msw/registry.h"
-// this should work if M$ Internet Exploiter is installed
-static long CharsetToCodepage(const wxChar *name)
+
+// this should work if Internet Exploiter is installed
+extern long wxCharsetToCodepage(const wxChar *name)
{
if (!name)
return GetACP();
return CP;
}
-#endif
+
+#endif // !wxUSE_GUI || !wxUSE_FONTMAP
+
+#endif // Win32
class wxCharacterSet
{
size_t outbuf = n;
size_t res, cres;
- wchar_t *tmpbuf;
+ wchar_t *tmpbuf = 0;
if (g_wcNeedsSwap)
{
class CP_CharSet : public wxCharacterSet
{
public:
- CP_CharSet(const wxChar*name)
- : wxCharacterSet(name), CodePage(CharsetToCodepage(name)) {}
+ 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(CodePage, 0, psz, -1, buf, buf ? n : 0);
+ 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(CodePage, 0, psz, -1, buf,
+ 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
}
bool usable()
- { return CodePage != -1; }
+ { return m_CodePage != -1; }
public:
- long CodePage;
+ long m_CodePage;
};
#endif // __WIN32__
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)
+ EC_CharSet(const wxChar* name) : wxCharacterSet(name),
+ enc(wxFONTENCODING_SYSTEM)
{
if (name)
enc = wxTheFontMapper->CharsetToEncoding(name, FALSE);
size_t WC2MB(char *buf, const wchar_t *psz, size_t n)
{
-#if defined(__BORLANDC__) && (__BORLANDC__ > 0x530)
+#if ( defined(__BORLANDC__) && (__BORLANDC__ > 0x530) ) \
+ || ( defined(__MWERKS__) && defined(__WXMSW__) )
size_t inbuf = std::wcslen(psz);
#else
size_t inbuf = ::wcslen(psz);
return m_cset->WC2MB(buf, psz, n);
// latin-1 (direct)
-#if defined(__BORLANDC__) && (__BORLANDC__ > 0x530)
+#if ( defined(__BORLANDC__) && (__BORLANDC__ > 0x530) ) \
+ || ( defined(__MWERKS__) && defined(__WXMSW__) )
size_t len=std::wcslen(psz);
#else
size_t len=::wcslen(psz);