diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt index 438f7f35d4..9ee4758738 100644 --- a/common/CMakeLists.txt +++ b/common/CMakeLists.txt @@ -44,6 +44,7 @@ add_library( singletop STATIC EXCLUDE_FROM_ALL # as APIEXPORT set( KICOMMON_SRCS exceptions.cpp + locale_io.cpp richio.cpp string_utils.cpp ) @@ -54,6 +55,7 @@ add_library( kicommon SHARED target_link_libraries( kicommon core + kimath kiplatform fmt::fmt ${wxWidgets_LIBRARIES} @@ -408,7 +410,6 @@ set( COMMON_SRCS lib_table_grid_tricks.cpp lib_tree_model.cpp lib_tree_model_adapter.cpp - locale_io.cpp lset.cpp marker_base.cpp markup_parser.cpp diff --git a/common/locale_io.cpp b/common/locale_io.cpp index 931b22e560..9b2a287cb6 100644 --- a/common/locale_io.cpp +++ b/common/locale_io.cpp @@ -47,14 +47,6 @@ // // 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 // in some cases (reading a bitmap for instance) // 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 -std::atomic LOCALE_IO::m_c_count( 0 ); +// allow for nesting of LOCALE_IO instantiations +static std::atomic 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 - if( m_c_count++ == 0 ) + if( locale_count++ == 0 ) { #if USE_WXLOCALE #define C_LANG "C" @@ -100,7 +96,7 @@ LOCALE_IO::LOCALE_IO() : m_wxLocale( nullptr ) LOCALE_IO::~LOCALE_IO() { // use thread safe, atomic operation - if( --m_c_count == 0 ) + if( --locale_count == 0 ) { // revert to the user locale #if USE_WXLOCALE diff --git a/include/locale_io.h b/include/locale_io.h index 431830076c..80d07d5ec6 100644 --- a/include/locale_io.h +++ b/include/locale_io.h @@ -24,9 +24,17 @@ #ifndef LOCALE_IO_H #define LOCALE_IO_H +#include #include #include +// 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; /** @@ -37,25 +45,20 @@ class wxLocale; * point numbers. The destructor insures that the default locale is restored whether an * exception is thrown or not. */ -class LOCALE_IO +class KICOMMON_API LOCALE_IO { public: LOCALE_IO(); ~LOCALE_IO(); private: - // allow for nesting of LOCALE_IO instantiations - static std::atomic m_c_count; - +#if USE_WXLOCALE + wxLocale* m_wxLocale; +#else // The locale in use before switching to the "C" locale // (the locale can be set by user, and is not always the system locale) std::string m_user_locale; - #ifndef __clang__ - // [[maybe_unused]] attribute is ignored by Gcc but generates a warning. - wxLocale* m_wxLocale; - #else - [[maybe_unused]] wxLocale* m_wxLocale; - #endif +#endif }; #endif