Add wxUILocale with minimal functionality

Use it in the sample to show what (little) it can do right now.
This commit is contained in:
Vadim Zeitlin
2021-08-13 23:29:42 +02:00
parent b12961f992
commit b9cbe6770f
22 changed files with 1178 additions and 72 deletions

View File

@@ -90,6 +90,8 @@ enum wxLocaleInitFlags
#endif
};
// NOTE: This class is deprecated, use wxUILocale and wxTranslations instead.
class WXDLLIMPEXP_BASE wxLocale
{
public:

View File

@@ -0,0 +1,43 @@
///////////////////////////////////////////////////////////////////////////////
// Name: wx/private/uilocale.h
// Purpose: wxUILocaleImpl class declaration
// Author: Vadim Zeitlin
// Created: 2021-08-01
// Copyright: (c) 2021 Vadim Zeitlin <vadim@wxwidgets.org>
// Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////////
#ifndef _WX_PRIVATE_UILOCALE_H_
#define _WX_PRIVATE_UILOCALE_H_
#include "wx/localedefs.h"
#include "wx/string.h"
// ----------------------------------------------------------------------------
// wxUILocaleImpl provides the implementation of public wxUILocale functions
// ----------------------------------------------------------------------------
class wxUILocaleImpl
{
public:
// This function is implemented in platform-specific code and returns the
// object used by default, i.e. if wxUILocale::UseDefault() is not called.
// This object corresponds to the traditional "C" locale.
//
// It should never return NULL.
static wxUILocaleImpl* CreateStdC();
// Similarly, this one returns the object corresponding to the default user
// locale settings which is used if wxUILocale::UseDefault() was called.
//
// It may return NULL in case of failure.
static wxUILocaleImpl* CreateUserDefault();
// Functions corresponding to wxUILocale ones.
virtual wxString GetName() const = 0;
virtual wxString GetInfo(wxLocaleInfo index, wxLocaleCategory cat) const = 0;
virtual ~wxUILocaleImpl() { }
};
#endif // _WX_PRIVATE_UILOCALE_H_

66
include/wx/uilocale.h Normal file
View File

@@ -0,0 +1,66 @@
///////////////////////////////////////////////////////////////////////////////
// Name: wx/uilocale.h
// Purpose: wxUILocale class declaration.
// Author: Vadim Zeitlin
// Created: 2021-07-31
// Copyright: (c) 2021 Vadim Zeitlin <vadim@wxwidgets.org>
// Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////////
#ifndef _WX_UILOCALE_H_
#define _WX_UILOCALE_H_
#include "wx/defs.h"
#if wxUSE_INTL
#include "wx/localedefs.h"
#include "wx/string.h"
class wxUILocaleImpl;
// ----------------------------------------------------------------------------
// wxUILocale allows to use the default UI locale and get information about it
// ----------------------------------------------------------------------------
class WXDLLIMPEXP_BASE wxUILocale
{
public:
// Configure the UI to use the default user locale.
static bool UseDefault();
// Get the object corresponding to the currently used locale.
static const wxUILocale& GetCurrent();
// Get the platform-dependent name of the current locale.
wxString GetName() const;
// Query the locale for the specified information.
wxString GetInfo(wxLocaleInfo index,
wxLocaleCategory cat = wxLOCALE_CAT_DEFAULT) const;
// Note that this class is not supposed to be used polymorphically, hence
// its dtor is not virtual.
~wxUILocale();
private:
// Ctor is private, use static accessor to get objects of this class.
wxUILocale() : m_impl(NULL) { }
// Used by UseDefault().
//
// Note that this object takes ownership of the provided pointer and will
// delete it in dtor.
void SetImpl(wxUILocaleImpl* impl);
static wxUILocale ms_current;
wxUILocaleImpl* m_impl;
wxDECLARE_NO_COPY_CLASS(wxUILocale);
};
#endif // wxUSE_INTL
#endif // _WX_UILOCALE_H_