#if wxUSE_INTL
// standard headers
+
+#ifndef __WXWINCE__
#include <locale.h>
+#endif
+
#include <ctype.h>
#include <stdlib.h>
#ifdef HAVE_LANGINFO_H
#include "wx/dynarray.h"
#endif // WX_PRECOMP
+#ifdef __WIN32__
+ #include "wx/msw/private.h"
+#elif defined(__UNIX_LIKE__)
+ #include "wx/fontmap.h" // for CharsetToEncoding()
+#endif
+
#include "wx/file.h"
#include "wx/tokenzr.h"
#include "wx/module.h"
#include "wx/encconv.h"
#include "wx/hashmap.h"
-#ifdef __WIN32__
- #include "wx/msw/private.h"
-#elif defined(__UNIX_LIKE__)
- #include "wx/fontmap.h" // for CharsetToEncoding()
-#endif
-
#if defined(__WXMAC__)
#include "wx/mac/private.h" // includes mac headers
#endif
// all data is stored here, NULL if no data loaded
size_t8 *m_pData;
+ // amount of memory pointed to by m_pData.
+ size_t32 m_nSize;
+
// data description
size_t32 m_numStrings; // number of strings in this domain
wxMsgTableEntry *m_pOrigTable, // pointer to original strings
*m_pTransTable; // translated
- const char *StringAtOfs(wxMsgTableEntry *pTable, size_t32 index) const
- { return (const char *)(m_pData + Swap(pTable[index].ofsString)); }
+ // swap the 2 halves of 32 bit integer if needed
+ size_t32 Swap(size_t32 ui) const
+ {
+ return m_bSwapped ? (ui << 24) | ((ui & 0xff00) << 8) |
+ ((ui >> 8) & 0xff00) | (ui >> 24)
+ : ui;
+ }
- wxString GetCharset() const;
+ const char *StringAtOfs(wxMsgTableEntry *pTable, size_t32 n) const
+ {
+ const wxMsgTableEntry * const ent = pTable + n;
+
+ // this check could fail for a corrupt message catalog
+ size_t32 ofsString = Swap(ent->ofsString);
+ if ( ofsString + Swap(ent->nLen) > m_nSize)
+ return NULL;
+
+ return (const char *)(m_pData + ofsString);
+ }
- // utility functions
- // big<->little endian
- inline size_t32 Swap(size_t32 ui) const;
+ wxString GetCharset() const;
- bool m_bSwapped; // wrong endianness?
+ bool m_bSwapped; // wrong endianness?
DECLARE_NO_COPY_CLASS(wxMsgCatalogFile)
};
// wxMsgCatalogFile class
// ----------------------------------------------------------------------------
-// swap the 2 halves of 32 bit integer if needed
-size_t32 wxMsgCatalogFile::Swap(size_t32 ui) const
-{
- return m_bSwapped ? (ui << 24) | ((ui & 0xff00) << 8) |
- ((ui >> 8) & 0xff00) | (ui >> 24)
- : ui;
-}
-
wxMsgCatalogFile::wxMsgCatalogFile()
{
- m_pData = NULL;
+ m_pData = NULL;
+ m_nSize = 0;
}
wxMsgCatalogFile::~wxMsgCatalogFile()
{
- wxDELETEA(m_pData);
+ wxDELETEA(m_pData);
}
// return all directories to search for given prefix
// LC_PATH is a standard env var containing the search path for the .mo
// files
+#ifndef __WXWINCE__
const wxChar *pszLcPath = wxGetenv(wxT("LC_PATH"));
if ( pszLcPath != NULL )
searchPath << GetAllMsgCatalogSubdirs(pszLcPath, lang);
+#endif
#ifdef __UNIX__
// add some standard ones and the one in the tree where wxWin was installed:
Swap(pHeader->ofsOrigTable));
m_pTransTable = (wxMsgTableEntry *)(m_pData +
Swap(pHeader->ofsTransTable));
+ m_nSize = nSize;
// everything is fine
return TRUE;
wxCHECK_MSG( szLocale, FALSE, _T("no locale to set in wxLocale::Init()") );
}
+#ifdef __WXWINCE__
+ // FIXME: I'm guessing here
+ wxChar localeName[256];
+ int ret = GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_SLANGUAGE, localeName,
+ 256);
+ if (ret != 0)
+ {
+ m_pszOldLocale = wxStrdup(localeName);
+ }
+ else
+ m_pszOldLocale = NULL;
+
+ // TODO: how to find languageId
+ // SetLocaleInfo(languageId, SORT_DEFAULT, localeName);
+#else
m_pszOldLocale = wxStrdup(wxSetlocale(LC_ALL, szLocale));
+#endif
+
if ( m_pszOldLocale == NULL )
wxLogError(_("locale '%s' can not be set."), szLocale);
static wxWCharBuffer wxSetlocaleTryUTF(int c, const wxChar *lc)
{
wxMB2WXbuf l = wxSetlocale(c, lc);
- if ( lc && lc[0] != 0 && !l )
+ if ( !l && lc && lc[0] != 0 )
{
wxString buf(lc);
- buf += wxT(".utf8");
- l = wxSetlocale(c, buf.c_str());
+ wxString buf2;
+ buf2 = buf + wxT(".UTF-8");
+ l = wxSetlocale(c, buf2.c_str());
+ if ( !l )
+ {
+ buf2 = buf + wxT(".utf-8");
+ l = wxSetlocale(c, buf2.c_str());
+ }
+ if ( !l )
+ {
+ buf2 = buf + wxT(".UTF8");
+ l = wxSetlocale(c, buf2.c_str());
+ }
+ if ( !l )
+ {
+ buf2 = buf + wxT(".utf8");
+ l = wxSetlocale(c, buf2.c_str());
+ }
}
return l;
}
int codepage = -1;
wxUint32 lcid = MAKELCID(MAKELANGID(info->WinLang, info->WinSublang),
SORT_DEFAULT);
+ // FIXME
+#ifndef __WXWINCE__
SetThreadLocale(lcid);
+#endif
// NB: we must translate LCID to CRT's setlocale string ourselves,
// because SetThreadLocale does not modify change the
// interpretation of setlocale(LC_ALL, "") call:
}
else
{
+ // FIXME
+#ifndef __WXWINCE__
retloc = wxSetlocale(LC_ALL, locale);
+#endif
#ifdef SETLOCALE_FAILS_ON_UNICODE_LANGS
if (codepage == 0 && (const wxChar*)retloc == NULL)
{
}
else
{
+ // FIXME
+#ifndef __WXWINCE__
retloc = wxSetlocale(LC_ALL, wxEmptyString);
+#else
+ retloc = NULL;
+#endif
#ifdef SETLOCALE_FAILS_ON_UNICODE_LANGS
if ((const wxChar*)retloc == NULL)
{
wxString wxLocale::GetSysName() const
{
+ // FIXME
+#ifndef __WXWINCE__
return wxSetlocale(LC_ALL, NULL);
+#else
+ return wxEmptyString;
+#endif
}
// clean up
// restore old locale
wxSetLocale(m_pOldLocale);
+ // FIXME
+#ifndef __WXWINCE__
wxSetlocale(LC_ALL, m_pszOldLocale);
+#endif
free((wxChar *)m_pszOldLocale); // const_cast
}