Refactor platform checks in wxLocale::Init()
Avoid the need for ugly WX_NO_LOCALE_SUPPORT macro at the cost of a couple of extra #ifs, which seems to be a worthy trade-off. This also allows making the code calling setlocale("") for the default language platform-independent. No real changes.
This commit is contained in:
@@ -508,8 +508,18 @@ bool wxLocale::Init(int lang, int flags)
|
|||||||
DoInit(name, shortName, lang);
|
DoInit(name, shortName, lang);
|
||||||
|
|
||||||
// Set the locale:
|
// Set the locale:
|
||||||
|
|
||||||
|
#if defined(__UNIX__) || defined(__WIN32__)
|
||||||
|
|
||||||
|
// We prefer letting the CRT to set its locale on its own when using
|
||||||
|
// default locale, as it does a better job of it than we do. We also have
|
||||||
|
// to do this when we didn't recognize the default language at all.
|
||||||
|
const char *retloc = lang == wxLANGUAGE_DEFAULT ? wxSetlocale(LC_ALL, "")
|
||||||
|
: NULL;
|
||||||
|
|
||||||
#if defined(__UNIX__)
|
#if defined(__UNIX__)
|
||||||
const char *retloc = wxSetlocaleTryAll(LC_ALL, shortName);
|
if ( !retloc )
|
||||||
|
retloc = wxSetlocaleTryAll(LC_ALL, shortName);
|
||||||
|
|
||||||
if ( !retloc )
|
if ( !retloc )
|
||||||
{
|
{
|
||||||
@@ -546,16 +556,12 @@ bool wxLocale::Init(int lang, int flags)
|
|||||||
#endif // __AIX__
|
#endif // __AIX__
|
||||||
|
|
||||||
#elif defined(__WIN32__)
|
#elif defined(__WIN32__)
|
||||||
const char *retloc;
|
|
||||||
if ( lang == wxLANGUAGE_DEFAULT )
|
if ( lang == wxLANGUAGE_DEFAULT )
|
||||||
{
|
{
|
||||||
::SetThreadLocale(LOCALE_USER_DEFAULT);
|
::SetThreadLocale(LOCALE_USER_DEFAULT);
|
||||||
wxMSWSetThreadUILanguage(LANG_USER_DEFAULT);
|
wxMSWSetThreadUILanguage(LANG_USER_DEFAULT);
|
||||||
|
|
||||||
// We're using the system language, so let setlocale() deal with it: it
|
// CRT locale already set above.
|
||||||
// does it better than we do and we might not even know about this
|
|
||||||
// language in the first place.
|
|
||||||
retloc = wxSetlocale(LC_ALL, "");
|
|
||||||
}
|
}
|
||||||
else if ( info->WinLang == 0 )
|
else if ( info->WinLang == 0 )
|
||||||
{
|
{
|
||||||
@@ -591,12 +597,9 @@ bool wxLocale::Init(int lang, int flags)
|
|||||||
}
|
}
|
||||||
#endif // CRT not handling Unicode-only languages
|
#endif // CRT not handling Unicode-only languages
|
||||||
#else
|
#else
|
||||||
wxUnusedVar(flags);
|
#error "Unsupported platform"
|
||||||
return false;
|
|
||||||
#define WX_NO_LOCALE_SUPPORT
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef WX_NO_LOCALE_SUPPORT
|
|
||||||
return DoCommonPostInit
|
return DoCommonPostInit
|
||||||
(
|
(
|
||||||
retloc != NULL,
|
retloc != NULL,
|
||||||
@@ -604,7 +607,10 @@ bool wxLocale::Init(int lang, int flags)
|
|||||||
shortName,
|
shortName,
|
||||||
flags & wxLOCALE_LOAD_DEFAULT
|
flags & wxLOCALE_LOAD_DEFAULT
|
||||||
);
|
);
|
||||||
#endif // !WX_NO_LOCALE_SUPPORT
|
#else // !(__UNIX__ || __WIN32__)
|
||||||
|
wxUnusedVar(flags);
|
||||||
|
return false;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
|
Reference in New Issue
Block a user