Move locale_io to kicommon
This commit is contained in:
parent
4ac5404822
commit
f0987821b5
|
@ -44,6 +44,7 @@ add_library( singletop STATIC EXCLUDE_FROM_ALL
|
||||||
# as APIEXPORT
|
# as APIEXPORT
|
||||||
set( KICOMMON_SRCS
|
set( KICOMMON_SRCS
|
||||||
exceptions.cpp
|
exceptions.cpp
|
||||||
|
locale_io.cpp
|
||||||
richio.cpp
|
richio.cpp
|
||||||
string_utils.cpp
|
string_utils.cpp
|
||||||
)
|
)
|
||||||
|
@ -54,6 +55,7 @@ add_library( kicommon SHARED
|
||||||
|
|
||||||
target_link_libraries( kicommon
|
target_link_libraries( kicommon
|
||||||
core
|
core
|
||||||
|
kimath
|
||||||
kiplatform
|
kiplatform
|
||||||
fmt::fmt
|
fmt::fmt
|
||||||
${wxWidgets_LIBRARIES}
|
${wxWidgets_LIBRARIES}
|
||||||
|
@ -408,7 +410,6 @@ set( COMMON_SRCS
|
||||||
lib_table_grid_tricks.cpp
|
lib_table_grid_tricks.cpp
|
||||||
lib_tree_model.cpp
|
lib_tree_model.cpp
|
||||||
lib_tree_model_adapter.cpp
|
lib_tree_model_adapter.cpp
|
||||||
locale_io.cpp
|
|
||||||
lset.cpp
|
lset.cpp
|
||||||
marker_base.cpp
|
marker_base.cpp
|
||||||
markup_parser.cpp
|
markup_parser.cpp
|
||||||
|
|
|
@ -47,14 +47,6 @@
|
||||||
//
|
//
|
||||||
// So use wxLocale on Windows and setlocale on unix
|
// So use wxLocale on Windows and setlocale on unix
|
||||||
|
|
||||||
|
|
||||||
// set USE_WXLOCALE 0 to use setlocale, 1 to use wxLocale:
|
|
||||||
#if defined( _WIN32 )
|
|
||||||
#define USE_WXLOCALE 1
|
|
||||||
#else
|
|
||||||
#define USE_WXLOCALE 0
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// On Windows, when using setlocale, a wx alert is generated
|
// On Windows, when using setlocale, a wx alert is generated
|
||||||
// in some cases (reading a bitmap for instance)
|
// in some cases (reading a bitmap for instance)
|
||||||
// So we disable alerts during the time a file is read or written
|
// So we disable alerts during the time a file is read or written
|
||||||
|
@ -73,12 +65,16 @@ void KiAssertFilter( const wxString &file, int line,
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
std::atomic<unsigned int> LOCALE_IO::m_c_count( 0 );
|
// allow for nesting of LOCALE_IO instantiations
|
||||||
|
static std::atomic<unsigned int> locale_count( 0 );
|
||||||
|
|
||||||
LOCALE_IO::LOCALE_IO() : m_wxLocale( nullptr )
|
LOCALE_IO::LOCALE_IO()
|
||||||
|
#if USE_WXLOCALE
|
||||||
|
: m_wxLocale( nullptr )
|
||||||
|
#endif
|
||||||
{
|
{
|
||||||
// use thread safe, atomic operation
|
// use thread safe, atomic operation
|
||||||
if( m_c_count++ == 0 )
|
if( locale_count++ == 0 )
|
||||||
{
|
{
|
||||||
#if USE_WXLOCALE
|
#if USE_WXLOCALE
|
||||||
#define C_LANG "C"
|
#define C_LANG "C"
|
||||||
|
@ -100,7 +96,7 @@ LOCALE_IO::LOCALE_IO() : m_wxLocale( nullptr )
|
||||||
LOCALE_IO::~LOCALE_IO()
|
LOCALE_IO::~LOCALE_IO()
|
||||||
{
|
{
|
||||||
// use thread safe, atomic operation
|
// use thread safe, atomic operation
|
||||||
if( --m_c_count == 0 )
|
if( --locale_count == 0 )
|
||||||
{
|
{
|
||||||
// revert to the user locale
|
// revert to the user locale
|
||||||
#if USE_WXLOCALE
|
#if USE_WXLOCALE
|
||||||
|
|
|
@ -24,9 +24,17 @@
|
||||||
#ifndef LOCALE_IO_H
|
#ifndef LOCALE_IO_H
|
||||||
#define LOCALE_IO_H
|
#define LOCALE_IO_H
|
||||||
|
|
||||||
|
#include <kicommon.h>
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
// set USE_WXLOCALE 0 to use setlocale, 1 to use wxLocale:
|
||||||
|
#if defined( _WIN32 )
|
||||||
|
#define USE_WXLOCALE 1
|
||||||
|
#else
|
||||||
|
#define USE_WXLOCALE 0
|
||||||
|
#endif
|
||||||
|
|
||||||
class wxLocale;
|
class wxLocale;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -37,25 +45,20 @@ class wxLocale;
|
||||||
* point numbers. The destructor insures that the default locale is restored whether an
|
* point numbers. The destructor insures that the default locale is restored whether an
|
||||||
* exception is thrown or not.
|
* exception is thrown or not.
|
||||||
*/
|
*/
|
||||||
class LOCALE_IO
|
class KICOMMON_API LOCALE_IO
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
LOCALE_IO();
|
LOCALE_IO();
|
||||||
~LOCALE_IO();
|
~LOCALE_IO();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// allow for nesting of LOCALE_IO instantiations
|
#if USE_WXLOCALE
|
||||||
static std::atomic<unsigned int> m_c_count;
|
wxLocale* m_wxLocale;
|
||||||
|
#else
|
||||||
// The locale in use before switching to the "C" locale
|
// The locale in use before switching to the "C" locale
|
||||||
// (the locale can be set by user, and is not always the system locale)
|
// (the locale can be set by user, and is not always the system locale)
|
||||||
std::string m_user_locale;
|
std::string m_user_locale;
|
||||||
#ifndef __clang__
|
#endif
|
||||||
// [[maybe_unused]] attribute is ignored by Gcc but generates a warning.
|
|
||||||
wxLocale* m_wxLocale;
|
|
||||||
#else
|
|
||||||
[[maybe_unused]] wxLocale* m_wxLocale;
|
|
||||||
#endif
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue