From ebe0847932dad995ff7f0e7cd6cf5cc6361f9fc7 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Thu, 4 Jan 2024 02:53:23 +0100 Subject: [PATCH] Add wxHAS_CONFIG_AS_{REG,FILE}CONFIG symbols Sometimes it's useful to have some code used only if wxConfig is defined as wxRegConfig or only if it is defined as wxFileConfig and testing for these symbols is more clear than testing for the platform (and more correct, considering that setting wxUSE_CONFIG_NATIVE to 0 may result in wxFileConfig being used even under Windows). --- docs/doxygen/mainpages/const_cpp.h | 4 ++++ include/wx/config.h | 2 ++ interface/wx/config.h | 4 +++- src/common/config.cpp | 13 +++++++------ 4 files changed, 16 insertions(+), 7 deletions(-) diff --git a/docs/doxygen/mainpages/const_cpp.h b/docs/doxygen/mainpages/const_cpp.h index 9c982c3323..5a1df738de 100644 --- a/docs/doxygen/mainpages/const_cpp.h +++ b/docs/doxygen/mainpages/const_cpp.h @@ -168,6 +168,10 @@ Currently the following symbols exist: implemented in a generic way, using a critical section.} @itemdef{wxHAS_BITMAPTOGGLEBUTTON, Defined in @c wx/tglbtn.h if wxBitmapToggleButton class is available in addition to wxToggleButton.} +@itemdef{wxHAS_CONFIG_AS_FILECONFIG, Defined if wxConfig is defined as + wxFileConfig. This constant is available since wxWidgets 3.3.0.} +@itemdef{wxHAS_CONFIG_AS_REGCONFIG, Defined if wxConfig is defined as + wxRegConfig. This constant is available since wxWidgets 3.3.0.} @itemdef{wxHAS_CONFIG_TEMPLATE_RW, Defined if the currently used compiler supports template Read() and Write() methods in wxConfig.} @itemdef{wxHAS_DEPRECATED_ATTR, Defined if C++14 @c [[deprecated]] attribute is diff --git a/include/wx/config.h b/include/wx/config.h index 177665116d..9a47bdedb4 100644 --- a/include/wx/config.h +++ b/include/wx/config.h @@ -23,9 +23,11 @@ #if defined(__WINDOWS__) && wxUSE_CONFIG_NATIVE #include "wx/msw/regconf.h" #define wxConfig wxRegConfig + #define wxHAS_CONFIG_AS_REGCONFIG #else // either we're under Unix or wish to always use config files #include "wx/fileconf.h" #define wxConfig wxFileConfig + #define wxHAS_CONFIG_AS_FILECONFIG #endif #endif // wxUSE_CONFIG diff --git a/interface/wx/config.h b/interface/wx/config.h index 3e86aa9434..3be4368c66 100644 --- a/interface/wx/config.h +++ b/interface/wx/config.h @@ -57,7 +57,9 @@ enum with the registry under Windows or text-based config files under Unix. To make writing the portable code even easier, wxWidgets provides a typedef wxConfig which is mapped onto the native wxConfigBase implementation on the - given platform: i.e. wxRegConfig under Windows and wxFileConfig otherwise. + given platform: i.e. wxRegConfig under Windows (in this case + `wxHAS_CONFIG_AS_REGCONFIG` preprocessor symbol is defined) and + wxFileConfig otherwise (in this case `wxHAS_CONFIG_AS_FILECONFIG` is). See @ref overview_config for a description of all features of this class. diff --git a/src/common/config.cpp b/src/common/config.cpp index fb29b8538d..7a2765636f 100644 --- a/src/common/config.cpp +++ b/src/common/config.cpp @@ -56,12 +56,13 @@ bool wxConfigBase::ms_bAutoCreate = true; wxConfigBase *wxAppTraitsBase::CreateConfig() { - return new - #if defined(__WINDOWS__) && wxUSE_CONFIG_NATIVE - wxRegConfig(wxTheApp->GetAppName(), wxTheApp->GetVendorName()); - #else // either we're under Unix or wish to use files even under Windows - wxFileConfig(wxTheApp->GetAppName()); - #endif +#if defined(wxHAS_CONFIG_AS_REGCONFIG) + return new wxRegConfig(wxTheApp->GetAppName(), wxTheApp->GetVendorName()); +#elif defined(wxHAS_CONFIG_AS_FILECONFIG) + return new wxFileConfig(wxTheApp->GetAppName()); +#else + #error No wxConfig implementation defined. +#endif } // ----------------------------------------------------------------------------