git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@23728
c3d73ce0-8a6f-49c7-b76d-
6d57e0e08775
// wxCSConv (for conversion based on loadable char sets)
// ----------------------------------------------------------------------------
// wxCSConv (for conversion based on loadable char sets)
// ----------------------------------------------------------------------------
+#include "wx/fontenc.h"
+
class WXDLLIMPEXP_BASE wxCharacterSet;
class WXDLLIMPEXP_BASE wxCSConv : public wxMBConv
{
public:
wxCSConv(const wxChar *charset);
class WXDLLIMPEXP_BASE wxCharacterSet;
class WXDLLIMPEXP_BASE wxCSConv : public wxMBConv
{
public:
wxCSConv(const wxChar *charset);
+ wxCSConv(wxFontEncoding encoding);
wxCSConv(const wxCSConv& conv);
virtual ~wxCSConv();
wxCSConv(const wxCSConv& conv);
virtual ~wxCSConv();
+ // common part of all ctors
+ void Init();
+
void SetName(const wxChar *charset);
// note that we can't use wxString here because of compilation
// dependencies: we're included from wx/string.h
wxChar *m_name;
wxCharacterSet *m_cset;
void SetName(const wxChar *charset);
// note that we can't use wxString here because of compilation
// dependencies: we're included from wx/string.h
wxChar *m_name;
wxCharacterSet *m_cset;
+ wxFontEncoding m_encoding;
const char* cWX2MB(const char *psz) const { return psz; }
};
const char* cWX2MB(const char *psz) const { return psz; }
};
-WXDLLIMPEXP_DATA_BASE(extern wxMBConv) wxConvLibc, wxConvFile, wxConvLocal, wxConvISO8859_1, wxConvUTF8;
+WXDLLIMPEXP_DATA_BASE(extern wxMBConv) wxConvLibc,
+ wxConvFile,
+ wxConvLocal,
+ wxConvISO8859_1,
+ wxConvUTF8;
WXDLLIMPEXP_DATA_BASE(extern wxMBConv *) wxConvCurrent;
#define wxFNCONV(name) name
WXDLLIMPEXP_DATA_BASE(extern wxMBConv *) wxConvCurrent;
#define wxFNCONV(name) name
class wxCharacterSet
{
public:
class wxCharacterSet
{
public:
- wxCharacterSet(const wxChar*name) : cname(name) {}
virtual ~wxCharacterSet() {}
virtual ~wxCharacterSet() {}
virtual size_t MB2WC(wchar_t *buf, const char *psz, size_t n) = 0;
virtual size_t WC2MB(char *buf, const wchar_t *psz, size_t n) = 0;
virtual bool usable() const = 0;
virtual size_t MB2WC(wchar_t *buf, const char *psz, size_t n) = 0;
virtual size_t WC2MB(char *buf, const wchar_t *psz, size_t n) = 0;
virtual bool usable() const = 0;
-public:
- const wxChar*cname;
};
// ----------------------------------------------------------------------------
};
// ----------------------------------------------------------------------------
class ID_CharSet : public wxCharacterSet
{
public:
class ID_CharSet : public wxCharacterSet
{
public:
- ID_CharSet(const wxChar *name, wxMBConv *cnv)
- : wxCharacterSet(name), work(cnv) {}
+ ID_CharSet(wxMBConv *cnv) : work(cnv) {}
size_t MB2WC(wchar_t *buf, const char *psz, size_t n)
{ return work ? work->MB2WC(buf,psz,n) : (size_t)-1; }
size_t MB2WC(wchar_t *buf, const char *psz, size_t n)
{ return work ? work->MB2WC(buf,psz,n) : (size_t)-1; }
#if defined(__WIN32__) && !defined(__WXMICROWIN__) && !defined(__WXUNIVERSAL__)
#if defined(__WIN32__) && !defined(__WXMICROWIN__) && !defined(__WXUNIVERSAL__)
-extern long wxCharsetToCodepage(const wxChar *charset); // from utils.cpp
+// from utils.cpp
+extern WXDLLIMPEXP_BASE long wxCharsetToCodepage(const wxChar *charset);
+extern WXDLLIMPEXP_BASE long wxEncodingToCodepage(wxFontEncoding encoding);
class CP_CharSet : public wxCharacterSet
{
public:
CP_CharSet(const wxChar* name)
class CP_CharSet : public wxCharacterSet
{
public:
CP_CharSet(const wxChar* name)
{
m_CodePage = wxCharsetToCodepage(name);
}
{
m_CodePage = wxCharsetToCodepage(name);
}
+ CP_CharSet(wxFontEncoding encoding)
+ {
+ m_CodePage = wxEncodingToCodepage(encoding);
+ }
+
size_t MB2WC(wchar_t *buf, const char *psz, size_t n)
{
const size_t len = ::MultiByteToWideChar
size_t MB2WC(wchar_t *buf, const char *psz, size_t n)
{
const size_t len = ::MultiByteToWideChar
class EC_CharSet : public wxCharacterSet
{
class EC_CharSet : public wxCharacterSet
{
+private:
+ void Init()
+ {
+ m_ok = m2w.Init(m_enc, wxFONTENCODING_UNICODE) &&
+ w2m.Init(wxFONTENCODING_UNICODE, m_enc);
+ }
+
public:
// temporarily just use wxEncodingConverter stuff,
// so that it works while a better implementation is built
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)
- enc = wxFontMapper::Get()->CharsetToEncoding(name, FALSE);
+ m_enc = wxFontMapper::Get()->CharsetToEncoding(name, FALSE);
+ else
+ m_enc = wxFONTENCODING_SYSTEM;
- m_ok = m2w.Init(enc, wxFONTENCODING_UNICODE) &&
- w2m.Init(wxFONTENCODING_UNICODE, enc);
+ Init();
+ }
+
+ EC_CharSet(wxFontEncoding enc)
+ {
+ m_enc = enc;
+
+ Init();
}
size_t MB2WC(wchar_t *buf, const char *psz, size_t WXUNUSED(n))
}
size_t MB2WC(wchar_t *buf, const char *psz, size_t WXUNUSED(n))
bool usable() const { return m_ok; }
public:
bool usable() const { return m_ok; }
public:
wxEncodingConverter m2w, w2m;
// were we initialized successfully?
wxEncodingConverter m2w, w2m;
// were we initialized successfully?
// ----------------------------------------------------------------------------
// the function creating the wxCharacterSet for the specified charset on the
// current system, trying all possibilities
// ----------------------------------------------------------------------------
// the function creating the wxCharacterSet for the specified charset on the
// current system, trying all possibilities
+//
+// it uses the name if it is given or encoding if name == NULL
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
-static wxCharacterSet *wxGetCharacterSet(const wxChar *name)
+static wxCharacterSet *
+wxGetCharacterSet(const wxChar *name, wxFontEncoding encoding)
{
// check for the special case of ASCII charset
{
// check for the special case of ASCII charset
+ if ( (!name && encoding == wxFONTENCODING_DEFAULT)
- if ( wxFontMapper::Get()->CharsetToEncoding(name) == wxFONTENCODING_DEFAULT )
-#else // wxUSE_FONTMAP
- if ( !name )
-#endif // wxUSE_FONTMAP/!wxUSE_FONTMAP
+ || wxFontMapper::Get()->
+ CharsetToEncoding(name) == wxFONTENCODING_DEFAULT
+#endif // wxUSE_FONTMAP
+ )
{
// don't convert at all
return NULL;
}
{
// don't convert at all
return NULL;
}
- // the test above must have taken care of this case
- wxCHECK_MSG( name, NULL, _T("NULL name must be wxFONTENCODING_DEFAULT") );
-
- if ( wxStricmp(name, wxT("UTF8")) == 0 || wxStricmp(name, wxT("UTF-8")) == 0)
+ if ( (name &&
+ (wxStricmp(name, wxT("UTF8")) == 0 ||
+ wxStricmp(name, wxT("UTF-8")) == 0)) ||
+ encoding == wxFONTENCODING_UTF8 )
- cset = new ID_CharSet(name, &wxConvUTF8);
+ cset = new ID_CharSet(&wxConvUTF8);
- cset = new IC_CharSet(name);
-#else // !HAVE_ICONV
- cset = NULL;
-#endif // HAVE_ICONV/!HAVE_ICONV
+ if ( name )
+ {
+ cset = new IC_CharSet(name);
+ }
+ else
+#endif // HAVE_ICONV
+ {
+ cset = NULL;
+ }
}
// it can only be NULL in this case
}
// it can only be NULL in this case
}
#if defined(__WIN32__) && !defined(__WXMICROWIN__) && !defined(__WXUNIVERSAL__)
}
#if defined(__WIN32__) && !defined(__WXMICROWIN__) && !defined(__WXUNIVERSAL__)
- cset = new CP_CharSet(name);
+ cset = name ? new CP_CharSet(name) : new CP_CharSet(encoding);
if ( cset->usable() )
return cset;
if ( cset->usable() )
return cset;
#endif // defined(__WIN32__) && !defined(__WXMICROWIN__) && !defined(__WXUNIVERSAL__)
#if wxUSE_FONTMAP
#endif // defined(__WIN32__) && !defined(__WXMICROWIN__) && !defined(__WXUNIVERSAL__)
#if wxUSE_FONTMAP
- cset = new EC_CharSet(name);
+ cset = name ? new EC_CharSet(name) : new EC_CharSet(encoding);
if ( cset->usable() )
return cset;
if ( cset->usable() )
return cset;
cset = NULL;
#endif // wxUSE_FONTMAP
cset = NULL;
#endif // wxUSE_FONTMAP
- wxLogError(_("Cannot convert from encoding '%s'!"), name);
+ wxLogError(_("Cannot convert from encoding '%s'!"),
+ name ? name
+ :
+#if wxUSE_FONTMAP
+ wxFontMapper::GetEncodingDescription(encoding).c_str()
+#else // !wxUSE_FONTMAP
+ wxString::Format(_T("%s"), encoding).c_str()
+#endif // wxUSE_FONTMAP/!wxUSE_FONTMAP
+ );
// wxCSConv implementation
// ============================================================================
// wxCSConv implementation
// ============================================================================
-wxCSConv::wxCSConv(const wxChar *charset)
{
m_name = (wxChar *)NULL;
m_cset = (wxCharacterSet *) NULL;
m_deferred = TRUE;
{
m_name = (wxChar *)NULL;
m_cset = (wxCharacterSet *) NULL;
m_deferred = TRUE;
+}
+
+wxCSConv::wxCSConv(const wxChar *charset)
+{
+ Init();
+ m_encoding = wxFONTENCODING_DEFAULT;
+wxCSConv::wxCSConv(wxFontEncoding encoding)
+{
+ Init();
+
+ m_encoding = encoding;
+}
+
wxCSConv::~wxCSConv()
{
Clear();
}
wxCSConv::wxCSConv(const wxCSConv& conv)
wxCSConv::~wxCSConv()
{
Clear();
}
wxCSConv::wxCSConv(const wxCSConv& conv)
+ m_encoding = conv.m_encoding;
}
wxCSConv& wxCSConv::operator=(const wxCSConv& conv)
{
Clear();
}
wxCSConv& wxCSConv::operator=(const wxCSConv& conv)
{
Clear();
+ m_encoding = conv.m_encoding;
+
return *this;
}
void wxCSConv::Clear()
{
return *this;
}
void wxCSConv::Clear()
{
- if (m_name)
- free(m_name);
- if (m_cset)
- delete m_cset;
+ free(m_name);
+ delete m_cset;
+
m_name = NULL;
m_cset = NULL;
}
m_name = NULL;
m_cset = NULL;
}
// it would probably be better to make GetSystemEncodingName() always
// available (i.e. even when wxUSE_INTL == 0)?
#if wxUSE_INTL
// it would probably be better to make GetSystemEncodingName() always
// available (i.e. even when wxUSE_INTL == 0)?
#if wxUSE_INTL
+ if ( !m_name && m_encoding == wxFONTENCODING_DEFAULT )
{
wxString name = wxLocale::GetSystemEncodingName();
if ( !name.empty() )
{
wxString name = wxLocale::GetSystemEncodingName();
if ( !name.empty() )
#endif // wxUSE_INTL
// wxGetCharacterSet() complains about NULL name
#endif // wxUSE_INTL
// wxGetCharacterSet() complains about NULL name
- m_cset = m_name ? wxGetCharacterSet(m_name) : NULL;
+ m_cset = wxGetCharacterSet(m_name, m_encoding);