Move platform-specific parts of wxLocale::Init() to wxUILocale

This is tidier than using #ifdefs in the same common file and also
ensures that initializing wxLocale affects wxUILocale too, which will be
important for compatibility when the code elsewhere is modified to use
wxUILocale::GetInfo() instead of wxLocale::GetInfo() in the upcoming
commits.

This commit is best viewed with --color-moved git option.
This commit is contained in:
Vadim Zeitlin
2021-08-14 17:42:29 +01:00
parent d3a1abaab2
commit 37a23e1ab1
9 changed files with 270 additions and 193 deletions

View File

@@ -0,0 +1,28 @@
///////////////////////////////////////////////////////////////////////////////
// Name: wx/msw/private/uilocale.h
// Purpose: MSW-specific locale-related helpers
// Author: Vadim Zeitlin
// Created: 2021-08-14
// Copyright: (c) 2021 Vadim Zeitlin <vadim@wxwidgets.org>
// Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////////
#ifndef _WX_MSW_PRIVATE_UILOCALE_H_
#define _WX_MSW_PRIVATE_UILOCALE_H_
#include "wx/msw/private.h" // Include <windows.h> to get LCID.
#ifndef LOCALE_SNAME
#define LOCALE_SNAME 0x5c
#endif
#ifndef LOCALE_CUSTOM_UI_DEFAULT
#define LOCALE_CUSTOM_UI_DEFAULT 0x1400
#endif
// Use the specific LCID for the current thread.
void wxUseLCID(LCID lcid);
// This function is defined in src/common/intl.cpp
wxString wxGetInfoFromLCID(LCID lcid, wxLocaleInfo index, wxLocaleCategory cat);
#endif // _WX_MSW_PRIVATE_UILOCALE_H_

View File

@@ -33,6 +33,15 @@ public:
// It may return NULL in case of failure.
static wxUILocaleImpl* CreateUserDefault();
// This function exists only for wxLocale compatibility and sets the locale
// corresponding to the given language.
//
// The language passed to this function is a valid language, i.e. neither
// wxLANGUAGE_UNKNOWN nor wxLANGUAGE_DEFAULT.
//
// It may return NULL in case of failure.
static wxUILocaleImpl* CreateForLanguage(const wxLanguageInfo& info);
// Functions corresponding to wxUILocale ones.
virtual wxString GetName() const = 0;
virtual wxString GetInfo(wxLocaleInfo index, wxLocaleCategory cat) const = 0;

View File

@@ -29,6 +29,12 @@ public:
// Configure the UI to use the default user locale.
static bool UseDefault();
// Use the locale corresponding to the given language.
//
// This is a compatibility function used by wxWidgets itself, don't use it
// in the new code.
static bool UseLanguage(const wxLanguageInfo& info);
// Get the object corresponding to the currently used locale.
static const wxUILocale& GetCurrent();

View File

@@ -0,0 +1,33 @@
///////////////////////////////////////////////////////////////////////////////
// Name: wx/unix/private/uilocale.h
// Purpose: Various locale-related helpers used under Unix systems only
// Author: Vadim Zeitlin
// Created: 2021-08-14 (extracted from src/common/intl.cpp)
// Copyright: (c) 2021 Vadim Zeitlin <vadim@wxwidgets.org>
// Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////////
#ifndef _WX_UNIX_PRIVATE_UILOCALE_H_
#define _WX_UNIX_PRIVATE_UILOCALE_H_
#include "wx/string.h"
// get just the language part ("en" in "en_GB")
inline wxString ExtractLang(const wxString& langFull)
{
return langFull.BeforeFirst('_');
}
// get everything else (including the leading '_')
inline wxString ExtractNotLang(const wxString& langFull)
{
size_t pos = langFull.find('_');
if ( pos != wxString::npos )
return langFull.substr(pos);
else
return wxString();
}
const char *wxSetlocaleTryAll(int c, const wxString& lc);
#endif // _WX_UNIX_PRIVATE_UILOCALE_H_