From ebad9cc02f5f5f2b0f096c620499e9dc451ca7b4 Mon Sep 17 00:00:00 2001 From: Mart Raudsepp Date: Sun, 18 Jul 2021 13:40:23 +0300 Subject: [PATCH 1/5] Use the override keyword directly instead of wxOVERRIDE The override keyword is available since C++11 and the project already required C++17, so there's no reason to go through wxOVERRIDE to support non-C++11 compilers. wxOVERRIDE is new since wx3.1.0 Signed-off-by: Mart Raudsepp --- src/prefs/DirectoriesPrefs.cpp | 8 +++---- src/widgets/FileConfig.h | 44 +++++++++++++++++----------------- 2 files changed, 26 insertions(+), 26 deletions(-) diff --git a/src/prefs/DirectoriesPrefs.cpp b/src/prefs/DirectoriesPrefs.cpp index 0d5064e67..988dcdb3c 100644 --- a/src/prefs/DirectoriesPrefs.cpp +++ b/src/prefs/DirectoriesPrefs.cpp @@ -52,12 +52,12 @@ public: mMessage = message; } - virtual wxObject* Clone() const wxOVERRIDE + virtual wxObject* Clone() const override { return safenew FilesystemValidator(mMessage); } - virtual bool Validate(wxWindow* WXUNUSED(parent)) wxOVERRIDE + virtual bool Validate(wxWindow* WXUNUSED(parent)) override { wxTextCtrl* tc = wxDynamicCast(GetWindow(), wxTextCtrl); if (!tc) { @@ -71,12 +71,12 @@ public: return true; } - virtual bool TransferToWindow() wxOVERRIDE + virtual bool TransferToWindow() override { return true; } - virtual bool TransferFromWindow() wxOVERRIDE + virtual bool TransferFromWindow() override { return true; } diff --git a/src/widgets/FileConfig.h b/src/widgets/FileConfig.h index adc58371a..f6f619ce3 100644 --- a/src/widgets/FileConfig.h +++ b/src/widgets/FileConfig.h @@ -30,22 +30,22 @@ public: void Init(); virtual ~FileConfig(); - virtual void SetPath(const wxString& strPath) wxOVERRIDE; - virtual const wxString& GetPath() const wxOVERRIDE; - virtual bool GetFirstGroup(wxString& str, long& lIndex) const wxOVERRIDE; - virtual bool GetNextGroup(wxString& str, long& lIndex) const wxOVERRIDE; - virtual bool GetFirstEntry(wxString& str, long& lIndex) const wxOVERRIDE; - virtual bool GetNextEntry(wxString& str, long& lIndex) const wxOVERRIDE; - virtual size_t GetNumberOfEntries(bool bRecursive = false) const wxOVERRIDE; - virtual size_t GetNumberOfGroups(bool bRecursive = false) const wxOVERRIDE; - virtual bool HasGroup(const wxString& strName) const wxOVERRIDE; - virtual bool HasEntry(const wxString& strName) const wxOVERRIDE; - virtual bool Flush(bool bCurrentOnly = false) wxOVERRIDE; - virtual bool RenameEntry(const wxString& oldName, const wxString& newName) wxOVERRIDE; - virtual bool RenameGroup(const wxString& oldName, const wxString& newName) wxOVERRIDE; - virtual bool DeleteEntry(const wxString& key, bool bDeleteGroupIfEmpty = true) wxOVERRIDE; - virtual bool DeleteGroup(const wxString& key) wxOVERRIDE; - virtual bool DeleteAll() wxOVERRIDE; + virtual void SetPath(const wxString& strPath) override; + virtual const wxString& GetPath() const override; + virtual bool GetFirstGroup(wxString& str, long& lIndex) const override; + virtual bool GetNextGroup(wxString& str, long& lIndex) const override; + virtual bool GetFirstEntry(wxString& str, long& lIndex) const override; + virtual bool GetNextEntry(wxString& str, long& lIndex) const override; + virtual size_t GetNumberOfEntries(bool bRecursive = false) const override; + virtual size_t GetNumberOfGroups(bool bRecursive = false) const override; + virtual bool HasGroup(const wxString& strName) const override; + virtual bool HasEntry(const wxString& strName) const override; + virtual bool Flush(bool bCurrentOnly = false) override; + virtual bool RenameEntry(const wxString& oldName, const wxString& newName) override; + virtual bool RenameGroup(const wxString& oldName, const wxString& newName) override; + virtual bool DeleteEntry(const wxString& key, bool bDeleteGroupIfEmpty = true) override; + virtual bool DeleteGroup(const wxString& key) override; + virtual bool DeleteAll() override; // Set and Get values of the version major/minor/micro keys in tenacity.cfg when Tenacity first opens void SetVersionKeysInit( int major, int minor, int micro) @@ -62,16 +62,16 @@ public: } protected: - virtual bool DoReadString(const wxString& key, wxString *pStr) const wxOVERRIDE; - virtual bool DoReadLong(const wxString& key, long *pl) const wxOVERRIDE; + virtual bool DoReadString(const wxString& key, wxString *pStr) const override; + virtual bool DoReadLong(const wxString& key, long *pl) const override; #if wxUSE_BASE64 - virtual bool DoReadBinary(const wxString& key, wxMemoryBuffer* buf) const wxOVERRIDE; + virtual bool DoReadBinary(const wxString& key, wxMemoryBuffer* buf) const override; #endif // wxUSE_BASE64 - virtual bool DoWriteString(const wxString& key, const wxString& szValue) wxOVERRIDE; - virtual bool DoWriteLong(const wxString& key, long lValue) wxOVERRIDE; + virtual bool DoWriteString(const wxString& key, const wxString& szValue) override; + virtual bool DoWriteLong(const wxString& key, long lValue) override; #if wxUSE_BASE64 - virtual bool DoWriteBinary(const wxString& key, const wxMemoryBuffer& buf) wxOVERRIDE; + virtual bool DoWriteBinary(const wxString& key, const wxMemoryBuffer& buf) override; #endif // wxUSE_BASE64 protected: From 786f21b85c9ee63af5067abd96a07609d0aaf2a2 Mon Sep 17 00:00:00 2001 From: Mart Raudsepp Date: Sun, 18 Jul 2021 13:44:41 +0300 Subject: [PATCH 2/5] Meter: Make compatible with wx3.0 with a local wxColour::GetLuminance Signed-off-by: Mart Raudsepp --- src/widgets/Meter.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/widgets/Meter.cpp b/src/widgets/Meter.cpp index 20321c1c8..575dd6bdb 100644 --- a/src/widgets/Meter.cpp +++ b/src/widgets/Meter.cpp @@ -471,6 +471,16 @@ void MeterPanel::OnErase(wxEraseEvent & WXUNUSED(event)) // Ignore it to prevent flashing } +static double GetColourLuminance(wxColour color) +{ +#if wxCHECK_VERSION(3, 1, 0) + return color.GetLuminance(); +#else + // Standard RGB to YIQ conversion for the luma (Y) part, used also by wx3.1 + return (0.299*color.Red() + 0.587*color.Green() + 0.114*color.Blue()) / 255.0; +#endif +} + void MeterPanel::OnPaint(wxPaintEvent & WXUNUSED(event)) { #if defined(__WXMAC__) @@ -533,13 +543,13 @@ void MeterPanel::OnPaint(wxPaintEvent & WXUNUSED(event)) // Bug #2473 - (Sort of) Hack to make text on meters more // visible with darker backgrounds. It would be better to have // different colors entirely and as part of the theme. - if (GetBackgroundColour().GetLuminance() < 0.25) + if (GetColourLuminance(GetBackgroundColour()) < 0.25) { green = wxColor(117-100, 215-100, 112-100); yellow = wxColor(255-100, 255-100, 0); red = wxColor(255-100, 0, 0); } - else if (GetBackgroundColour().GetLuminance() < 0.50) + else if (GetColourLuminance(GetBackgroundColour()) < 0.50) { green = wxColor(117-50, 215-50, 112-50); yellow = wxColor(255-50, 255-50, 0); From f6b0cd343ceba491cfc5feac029e3f610ee132ec Mon Sep 17 00:00:00 2001 From: Mart Raudsepp Date: Sun, 18 Jul 2021 13:59:17 +0300 Subject: [PATCH 3/5] CodeConversions: Make compatible with wx3.0 Signed-off-by: Mart Raudsepp --- libraries/lib-string-utils/CodeConversions.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/libraries/lib-string-utils/CodeConversions.cpp b/libraries/lib-string-utils/CodeConversions.cpp index 54fc4d748..fc989b950 100644 --- a/libraries/lib-string-utils/CodeConversions.cpp +++ b/libraries/lib-string-utils/CodeConversions.cpp @@ -28,7 +28,14 @@ std::string ToUTF8 (const wchar_t* wstr) std::string ToUTF8 (const wxString& wstr) { +#if wxCHECK_VERSION(3, 1, 1) return wstr.ToStdString (wxGet_wxConvUTF8 ()); +#elif !wxUSE_UNICODE + return std::string (wstr.c_str (), wstr.length ()); +#else + wxScopedCharBuffer buf (wstr.mb_str (wxGet_wxConvUTF8 ())); + return std::string (buf.data (), buf.length ()); +#endif } std::wstring ToWString (const std::string& str) @@ -48,7 +55,11 @@ std::wstring ToWString (const wxString& str) wxString ToWXString (const std::string& str) { +#if wxCHECK_VERSION(3, 1, 1) return wxString::FromUTF8 (str); +#else + return wxString::FromUTF8 (str.c_str()); +#endif } wxString ToWXString (const std::wstring& str) From c8db3ab3ac3fbf3bf379c83e37f617edab90bcc8 Mon Sep 17 00:00:00 2001 From: Mart Raudsepp Date: Sun, 18 Jul 2021 14:05:30 +0300 Subject: [PATCH 4/5] lib-strings: Make hashing compatible with wx3.0 3.0 doesn't have direct wxString hash support yet, so lift an earlier version of this from the history, which was used in TranslatableString.h before and use it again. wxWidgets version is slightly different though. Signed-off-by: Mart Raudsepp --- libraries/lib-strings/Identifier.h | 14 ++++++++++++++ libraries/lib-strings/TranslatableString.h | 1 + 2 files changed, 15 insertions(+) diff --git a/libraries/lib-strings/Identifier.h b/libraries/lib-strings/Identifier.h index 30f2de251..7a08e145d 100644 --- a/libraries/lib-strings/Identifier.h +++ b/libraries/lib-strings/Identifier.h @@ -90,6 +90,20 @@ inline bool operator <= ( const Identifier &x, const Identifier &y ) inline bool operator >= ( const Identifier &x, const Identifier &y ) { return !(x < y); } +#if !wxCHECK_VERSION(3, 1, 0) +namespace std +{ + template<> struct hash< wxString > { + size_t operator () (const wxString &str) const // noexcept + { + auto stdstr = str.ToStdWstring(); // no allocations, a cheap fetch + using Hasher = hash< decltype(stdstr) >; + return Hasher{}( stdstr ); + } + }; +} +#endif + namespace std { template<> struct hash< Identifier > { diff --git a/libraries/lib-strings/TranslatableString.h b/libraries/lib-strings/TranslatableString.h index fe755088d..00034d107 100644 --- a/libraries/lib-strings/TranslatableString.h +++ b/libraries/lib-strings/TranslatableString.h @@ -18,6 +18,7 @@ class Identifier; #include +#include "Identifier.h" //! Holds a msgid for the translation catalog; may also bind format arguments /*! From 7d57a665c3375e045d46e5b5758405d0fce9587f Mon Sep 17 00:00:00 2001 From: Mart Raudsepp Date: Sun, 18 Jul 2021 14:07:36 +0300 Subject: [PATCH 5/5] FileConfig: Compat with wx3.0 (reintroduces tiny bug if 3.0 used) This makes it have the potential of bogus temporary files again. This issue feels small enough vs not being able to run against wx3.0. Signed-off-by: Mart Raudsepp --- src/widgets/FileConfig.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/widgets/FileConfig.cpp b/src/widgets/FileConfig.cpp index 19b8f1da2..21a9d4f58 100644 --- a/src/widgets/FileConfig.cpp +++ b/src/widgets/FileConfig.cpp @@ -63,7 +63,10 @@ void FileConfig::Init() // because we don't use the wxFileConfig::Flush() method and so the wxFileConfig dirty // flag never gets reset. During deletion, the dirty flag is checked and a Flush() // performed. This can (and probably will) create bogus temporary files. + // TODO: Fix the problem for wx3.0 +#if wxCHECK_VERSION(3, 1, 3) mConfig->DisableAutoSave(); +#endif bool canRead = false; bool canWrite = false;