This required changing CompareStrings() to be a method of wxUILocale object, rather than just as a static function, as we must only allocate the locale_t object once, and not during each to this function, as this could make it unusably slow when using it as a comparison function when sorting a large list of strings. This is also more efficient under Mac, where we can similarly allocate NSLocale only once and even marginally more efficient under MSW, where we don't have to construct the locale string during each call. And, under all platforms, it also simplifies code by separating this function implementation from the initialization of wxUILocaleImpl. Also document that case-insensitive comparison is not available under Unix and adjust the tests accordingly.
100 lines
2.7 KiB
C++
100 lines
2.7 KiB
C++
///////////////////////////////////////////////////////////////////////////////
|
|
// 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;
|
|
|
|
// Flags for wxUILocale::CompareStrings().
|
|
enum
|
|
{
|
|
wxCompare_CaseSensitive = 0,
|
|
wxCompare_CaseInsensitive = 1
|
|
};
|
|
|
|
// ----------------------------------------------------------------------------
|
|
// 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();
|
|
|
|
// 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();
|
|
|
|
// Create the object corresponding to the given locale.
|
|
explicit wxUILocale(const wxLocaleIdent& localeId);
|
|
|
|
// 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;
|
|
|
|
// Compares two strings in the order defined by this locale.
|
|
int CompareStrings(const wxString& lhs, const wxString& rhs,
|
|
int flags = wxCompare_CaseSensitive) const;
|
|
|
|
// Note that this class is not supposed to be used polymorphically, hence
|
|
// its dtor is not virtual.
|
|
~wxUILocale();
|
|
|
|
private:
|
|
// Default ctor is private and exists only for implementation reasons,
|
|
// wxUILocale objects can't be invalid.
|
|
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);
|
|
};
|
|
|
|
inline wxString wxGetUIDateFormat()
|
|
{
|
|
return wxUILocale::GetCurrent().GetInfo(wxLOCALE_SHORT_DATE_FMT);
|
|
}
|
|
|
|
#else // !wxUSE_INTL
|
|
|
|
inline wxString wxGetUIDateFormat()
|
|
{
|
|
return wxString(wxS("%x"));
|
|
}
|
|
|
|
#endif // wxUSE_INTL/!wxUSE_INTL
|
|
|
|
#endif // _WX_UILOCALE_H_
|