diff --git a/include/wx/apptrait.h b/include/wx/apptrait.h index 5df1b4c8d544..1f88affa0e2e 100644 --- a/include/wx/apptrait.h +++ b/include/wx/apptrait.h @@ -171,6 +171,10 @@ class WXDLLIMPEXP_BASE wxAppTraitsBase virtual wxString GetAssertStackTrace(); #endif // wxUSE_STACKWALKER + // Text to be appended to the description returned by wxGetLibraryVersionInfo(). + // Currently used for getting compile-time versions of GTK+ and Qt. + virtual wxString GetPlatformDescription() const = 0; + private: static wxSocketManager *ms_manager; }; @@ -238,6 +242,7 @@ class WXDLLIMPEXP_BASE wxConsoleAppTraitsBase : public wxAppTraits virtual bool IsUsingUniversalWidgets() const override { return false; } virtual wxString GetDesktopEnvironment() const override { return wxEmptyString; } + virtual wxString GetPlatformDescription() const override { return wxEmptyString; } }; // ---------------------------------------------------------------------------- @@ -278,6 +283,7 @@ class WXDLLIMPEXP_CORE wxGUIAppTraitsBase : public wxAppTraits } virtual wxString GetDesktopEnvironment() const override { return wxEmptyString; } + virtual wxString GetPlatformDescription() const override { return wxEmptyString; } }; #endif // wxUSE_GUI diff --git a/include/wx/msw/apptrait.h b/include/wx/msw/apptrait.h index 3766e1be43c2..4211016d22e5 100644 --- a/include/wx/msw/apptrait.h +++ b/include/wx/msw/apptrait.h @@ -88,6 +88,7 @@ class WXDLLIMPEXP_CORE wxGUIAppTraits : public wxGUIAppTraitsBase virtual bool WriteToStderr(const wxString& WXUNUSED(text)) override { return false; } virtual WXHWND GetMainHWND() const override { return nullptr; } + virtual wxString GetPlatformDescription() const override; }; #elif defined(__WXQT__) @@ -114,6 +115,7 @@ class WXDLLIMPEXP_CORE wxGUIAppTraits : public wxGUIAppTraitsBase virtual bool CanUseStderr() override { return false; } virtual bool WriteToStderr(const wxString&) override { return false; } virtual WXHWND GetMainHWND() const override { return nullptr; } + virtual wxString GetPlatformDescription() const override; }; #endif diff --git a/include/wx/platinfo.h b/include/wx/platinfo.h index 35c5a3c0b24d..3038cb72017e 100644 --- a/include/wx/platinfo.h +++ b/include/wx/platinfo.h @@ -249,6 +249,9 @@ class WXDLLIMPEXP_BASE wxPlatformInfo int GetToolkitMicroVersion() const { return m_tkVersionMicro; } + wxString GetPlatformDescription() const + { return m_platformDescription; } + bool CheckToolkitVersion(int major, int minor, int micro = 0) const { return DoCheckVersion(GetToolkitMajorVersion(), @@ -435,6 +438,9 @@ class WXDLLIMPEXP_BASE wxPlatformInfo // native CPU architecture family name, possibly empty if unknown wxString m_nativeCpuArch; + + // e.g. compile-time version of toolkit, possibly empty + wxString m_platformDescription; }; // Return true if running under Wine and fills the provided pointer with diff --git a/include/wx/unix/apptrait.h b/include/wx/unix/apptrait.h index 78737202b7b1..f036af7c0fd5 100644 --- a/include/wx/unix/apptrait.h +++ b/include/wx/unix/apptrait.h @@ -65,6 +65,10 @@ class WXDLLIMPEXP_CORE wxGUIAppTraits : public wxGUIAppTraitsBase virtual wxString GetDesktopEnvironment() const override; #endif // __WXGTK____ +#if defined(__WXGTK__) || defined(__WXQT__) + virtual wxString GetPlatformDescription() const override; +#endif + #if defined(__WXGTK__) virtual bool ShowAssertDialog(const wxString& msg) override; #endif diff --git a/include/wx/utils.h b/include/wx/utils.h index c3bed00b7e08..b85150a1f348 100644 --- a/include/wx/utils.h +++ b/include/wx/utils.h @@ -118,7 +118,7 @@ WXDLLIMPEXP_CORE void wxBell(); WXDLLIMPEXP_CORE void wxInfoMessageBox(wxWindow* parent); #endif // wxUSE_MSGDLG -WXDLLIMPEXP_CORE wxVersionInfo wxGetLibraryVersionInfo(); +WXDLLIMPEXP_BASE wxVersionInfo wxGetLibraryVersionInfo(); // Get OS description as a user-readable string WXDLLIMPEXP_BASE wxString wxGetOsDescription(); diff --git a/interface/wx/utils.h b/interface/wx/utils.h index 14ea7a1f98fd..f6f7ed2da35c 100644 --- a/interface/wx/utils.h +++ b/interface/wx/utils.h @@ -232,7 +232,7 @@ void wxInfoMessageBox(wxWindow* parent); @header{wx/utils.h} - @library{wxcore} + @library{wxbase} */ wxVersionInfo wxGetLibraryVersionInfo(); diff --git a/src/common/platinfo.cpp b/src/common/platinfo.cpp index e659ba5e8e5a..aa36014e65c6 100644 --- a/src/common/platinfo.cpp +++ b/src/common/platinfo.cpp @@ -170,7 +170,8 @@ bool wxPlatformInfo::operator==(const wxPlatformInfo &t) const m_port == t.m_port && m_usingUniversal == t.m_usingUniversal && m_bitness == t.m_bitness && - m_endian == t.m_endian; + m_endian == t.m_endian && + m_platformDescription == t.m_platformDescription; } void wxPlatformInfo::InitForCurrentPlatform() @@ -195,6 +196,7 @@ void wxPlatformInfo::InitForCurrentPlatform() &m_tkVersionMicro); m_usingUniversal = traits->IsUsingUniversalWidgets(); m_desktopEnv = traits->GetDesktopEnvironment(); + m_platformDescription = traits->GetPlatformDescription(); } m_os = wxGetOsVersion(&m_osVersionMajor, &m_osVersionMinor, &m_osVersionMicro); diff --git a/src/common/utilscmn.cpp b/src/common/utilscmn.cpp index c7977064df5f..8bc0f563a2a7 100644 --- a/src/common/utilscmn.cpp +++ b/src/common/utilscmn.cpp @@ -1022,6 +1022,64 @@ unsigned int wxCTZ(wxUint32 x) #endif } +wxVersionInfo wxGetLibraryVersionInfo() +{ + // Only add the last build component to the version if it's non-zero, it's + // pretty useless otherwise. + wxString ver = wxString::Format + ( + wxS("%d.%d.%d"), + wxMAJOR_VERSION, + wxMINOR_VERSION, + wxRELEASE_NUMBER + ); + if ( wxSUBRELEASE_NUMBER ) + ver += wxString::Format(wxS(".%d"), wxSUBRELEASE_NUMBER); + + // don't translate these strings, they're for diagnostics purposes only + wxString msg; + msg.Printf(wxS("wxWidgets Library (%s port)\n") + wxS("Version %s (Unicode: %s, debug level: %d),\n") +#if !wxUSE_REPRODUCIBLE_BUILD + wxS("compiled at %s %s\n\n") +#endif + wxS("Runtime version of toolkit used is %d.%d.%d.\n"), + wxPlatformInfo::Get().GetPortIdName(), + ver, +#if wxUSE_UNICODE_UTF8 + "UTF-8", +#else + "wchar_t", +#endif + wxDEBUG_LEVEL, +#if !wxUSE_REPRODUCIBLE_BUILD + // As explained in the comment near these macros definitions, + // ccache has special logic for detecting the use of __DATE__ + // and __TIME__ macros, which doesn't apply to our own versions + // of them, hence this comment is needed just to mention the + // standard macro names and to ensure that ccache does _not_ + // cache the results of compiling this file. + __TDATE__, + __TTIME__, +#endif + wxPlatformInfo::Get().GetToolkitMajorVersion(), + wxPlatformInfo::Get().GetToolkitMinorVersion(), + wxPlatformInfo::Get().GetToolkitMicroVersion() + ); + + msg += wxPlatformInfo::Get().GetPlatformDescription(); + + const wxString copyrightSign = wxString::FromUTF8("\xc2\xa9"); + + return wxVersionInfo(wxS("wxWidgets"), + wxMAJOR_VERSION, + wxMINOR_VERSION, + wxRELEASE_NUMBER, + msg, + wxString::Format(wxS("Copyright %s 1992-2025 wxWidgets team"), + copyrightSign)); +} + #endif // wxUSE_BASE @@ -1374,74 +1432,6 @@ int wxMessageBox(const wxString& message, const wxString& caption, long style, return wxCANCEL; } -wxVersionInfo wxGetLibraryVersionInfo() -{ - // Only add the last build component to the version if it's non-zero, it's - // pretty useless otherwise. - wxString ver = wxString::Format - ( - wxS("%d.%d.%d"), - wxMAJOR_VERSION, - wxMINOR_VERSION, - wxRELEASE_NUMBER - ); - if ( wxSUBRELEASE_NUMBER ) - ver += wxString::Format(wxS(".%d"), wxSUBRELEASE_NUMBER); - - // don't translate these strings, they're for diagnostics purposes only - wxString msg; - msg.Printf(wxS("wxWidgets Library (%s port)\n") - wxS("Version %s (Unicode: %s, debug level: %d),\n") -#if !wxUSE_REPRODUCIBLE_BUILD - wxS("compiled at %s %s\n\n") -#endif - wxS("Runtime version of toolkit used is %d.%d.%d.\n"), - wxPlatformInfo::Get().GetPortIdName(), - ver, -#if wxUSE_UNICODE_UTF8 - "UTF-8", -#else - "wchar_t", -#endif - wxDEBUG_LEVEL, -#if !wxUSE_REPRODUCIBLE_BUILD - // As explained in the comment near these macros definitions, - // ccache has special logic for detecting the use of __DATE__ - // and __TIME__ macros, which doesn't apply to our own versions - // of them, hence this comment is needed just to mention the - // standard macro names and to ensure that ccache does _not_ - // cache the results of compiling this file. - __TDATE__, - __TTIME__, -#endif - wxPlatformInfo::Get().GetToolkitMajorVersion(), - wxPlatformInfo::Get().GetToolkitMinorVersion(), - wxPlatformInfo::Get().GetToolkitMicroVersion() - ); - -#ifdef __WXGTK__ - msg += wxString::Format("Compile-time GTK+ version is %d.%d.%d.\n", - GTK_MAJOR_VERSION, - GTK_MINOR_VERSION, - GTK_MICRO_VERSION); -#endif // __WXGTK__ - -#ifdef __WXQT__ - msg += wxString::Format("Compile-time QT version is %s.\n", - QT_VERSION_STR); -#endif // __WXQT__ - - const wxString copyrightSign = wxString::FromUTF8("\xc2\xa9"); - - return wxVersionInfo(wxS("wxWidgets"), - wxMAJOR_VERSION, - wxMINOR_VERSION, - wxRELEASE_NUMBER, - msg, - wxString::Format(wxS("Copyright %s 1992-2025 wxWidgets team"), - copyrightSign)); -} - void wxInfoMessageBox(wxWindow* parent) { wxVersionInfo info = wxGetLibraryVersionInfo(); diff --git a/src/gtk/utilsgtk.cpp b/src/gtk/utilsgtk.cpp index cd293e8516e2..e3aa7848e63b 100644 --- a/src/gtk/utilsgtk.cpp +++ b/src/gtk/utilsgtk.cpp @@ -165,6 +165,13 @@ wxPortId wxGUIAppTraits::GetToolkitVersion(int *verMaj, return wxPORT_GTK; } +wxString wxGUIAppTraits::GetPlatformDescription() const { + return wxString::Format("Compile-time GTK+ version is %d.%d.%d.\n", + GTK_MAJOR_VERSION, + GTK_MINOR_VERSION, + GTK_MICRO_VERSION); +} + #if wxUSE_TIMER wxTimerImpl *wxGUIAppTraits::CreateTimerImpl(wxTimer *timer) diff --git a/src/qt/utils.cpp b/src/qt/utils.cpp index bae93dc23323..3189233391bc 100644 --- a/src/qt/utils.cpp +++ b/src/qt/utils.cpp @@ -21,6 +21,7 @@ #include "wx/window.h" #endif // WX_PRECOMP +#include "wx/apptrait.h" #include "wx/utils.h" #include "wx/qt/private/utils.h" #include "wx/qt/private/converter.h" @@ -123,3 +124,8 @@ bool wxLaunchDefaultApplication(const wxString& path, int WXUNUSED( flags ) ) { return QDesktopServices::openUrl( QUrl::fromLocalFile( wxQtConvertString( path ) ) ); } + +wxString wxGUIAppTraits::GetPlatformDescription() const { + return wxString::Format("Compile-time QT version is %s.\n", + QT_VERSION_STR); +} diff --git a/tests/misc/misctests.cpp b/tests/misc/misctests.cpp index 8689dfcc0174..c1d9490068f1 100644 --- a/tests/misc/misctests.cpp +++ b/tests/misc/misctests.cpp @@ -19,6 +19,7 @@ #include "wx/math.h" #include "wx/mimetype.h" #include "wx/versioninfo.h" +#include "wx/utils.h" #include "wx/private/wordwrap.h" @@ -257,6 +258,14 @@ TEST_CASE("wxVersionInfo", "[version]") CHECK_FALSE( ver120.AtLeast(2, 0) ); } +TEST_CASE("wxGetLibraryVersionInfo", "[libraryversion]") +{ + // We especially want to ensure that wxGetLibraryVersionInfo() + // is available in wxBase, and successfully links, too. + wxVersionInfo libver = wxGetLibraryVersionInfo(); + CHECK( libver.GetNumericVersionString().starts_with("3.") ); +} + TEST_CASE("wxWordWrap", "[wordwrap]") { // Use artificially small max width to make the tests shorter and simpler.