From c9e2143a7a97ef82bcc20e8c6956663523a62adf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Va=CC=81clav=20Slavi=CC=81k?= Date: Fri, 16 Apr 2021 19:53:04 +0200 Subject: [PATCH 1/2] Fix wxLocale::GetInfo() for unknown Windows locales wxWidgets may be unaware of the locale being used and may be unable to get correct information from its languages database. For example, en-AT locale, supported by Windows 10 and using "," for decimal point, would be interpreted as en-US by wx, and return "." here. The other situation, when wx supports a locale that the OS doesn't, shouldn't make a difference here because in that case, CRT wouldn't support the locale either and CRT formatting functions wouldn't be set to use it. See also somewhat related 9fc78c81679274d08ae4c956e652df7a4bfec3e5. --- src/common/intl.cpp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/common/intl.cpp b/src/common/intl.cpp index 0b0d8798f4..e56425b619 100644 --- a/src/common/intl.cpp +++ b/src/common/intl.cpp @@ -1688,10 +1688,7 @@ GetInfoFromLCID(LCID lcid, /* static */ wxString wxLocale::GetInfo(wxLocaleInfo index, wxLocaleCategory cat) { - const wxLanguageInfo * const - info = wxGetLocale() ? GetLanguageInfo(wxGetLocale()->GetLanguage()) - : NULL; - if ( !info ) + if ( !wxGetLocale() ) { // wxSetLocale() hadn't been called yet of failed, hence CRT must be // using "C" locale -- but check it to detect bugs that would happen if @@ -1734,7 +1731,8 @@ wxString wxLocale::GetInfo(wxLocaleInfo index, wxLocaleCategory cat) } } - return GetInfoFromLCID(info->GetLCID(), index, cat); + // wxSetLocale() succeeded and so thread locale was set together with CRT one. + return GetInfoFromLCID(::GetThreadLocale(), index, cat); } /* static */ From b466e3c76981f721533a9bf8b00934d32b0e964e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Va=CC=81clav=20Slavi=CC=81k?= Date: Sat, 17 Apr 2021 10:42:50 +0200 Subject: [PATCH 2/2] Restore Win32 locale in wxLocale destructor --- include/wx/intl.h | 3 +++ src/common/intl.cpp | 8 ++++++++ 2 files changed, 11 insertions(+) diff --git a/include/wx/intl.h b/include/wx/intl.h index d66e3043d8..c551042754 100644 --- a/include/wx/intl.h +++ b/include/wx/intl.h @@ -363,6 +363,9 @@ private: const char *m_pszOldLocale; // previous locale from setlocale() wxLocale *m_pOldLocale; // previous wxLocale +#ifdef __WIN32__ + wxUint32 m_oldLCID; +#endif bool m_initialized; diff --git a/src/common/intl.cpp b/src/common/intl.cpp index e56425b619..6ec7ed6f28 100644 --- a/src/common/intl.cpp +++ b/src/common/intl.cpp @@ -253,6 +253,9 @@ void wxLocale::DoCommonInit() if ( m_pszOldLocale ) m_pszOldLocale = wxStrdup(m_pszOldLocale); +#ifdef __WIN32__ + m_oldLCID = ::GetThreadLocale(); +#endif m_pOldLocale = wxSetLocale(this); @@ -1098,6 +1101,11 @@ wxLocale::~wxLocale() wxSetlocale(LC_ALL, m_pszOldLocale); free(const_cast(m_pszOldLocale)); } + +#ifdef __WIN32__ + ::SetThreadLocale(m_oldLCID); + wxMSWSetThreadUILanguage(LANGIDFROMLCID(m_oldLCID)); +#endif }