From: Václav Slavík Date: Sat, 2 Aug 2003 15:14:17 +0000 (+0000) Subject: replaced wxAppTraits::GetOSVersion with GetToolkitInfo with richer information that... X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/a8eaaeb23796c69ea0f67cbd48fc5f667d9823d0 replaced wxAppTraits::GetOSVersion with GetToolkitInfo with richer information that is needed by wxDynamicLibrary git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@22491 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/include/wx/app.h b/include/wx/app.h index a06b1f7485..c95c47751c 100644 --- a/include/wx/app.h +++ b/include/wx/app.h @@ -75,6 +75,7 @@ private: }; #endif // wxUSE_GUI + // ---------------------------------------------------------------------------- // wxAppConsole: wxApp for non-GUI applications // ---------------------------------------------------------------------------- diff --git a/include/wx/apptrait.h b/include/wx/apptrait.h index 0a169af8f0..7d81b46bee 100644 --- a/include/wx/apptrait.h +++ b/include/wx/apptrait.h @@ -12,15 +12,37 @@ #ifndef _WX_APPTRAIT_H_ #define _WX_APPTRAIT_H_ -class WXDLLEXPORT wxObject; +#include "wx/string.h" + +class WXDLLIMPEXP_BASE wxObject; class WXDLLEXPORT wxAppTraits; #if wxUSE_FONTMAP class WXDLLEXPORT wxFontMapper; #endif // wxUSE_FONTMAP -class WXDLLEXPORT wxLog; -class WXDLLEXPORT wxMessageOutput; +class WXDLLIMPEXP_BASE wxLog; +class WXDLLIMPEXP_BASE wxMessageOutput; class WXDLLEXPORT wxRendererNative; -class WXDLLEXPORT wxString; +class WXDLLIMPEXP_BASE wxString; +struct WXDLLIMPEXP_BASE wxToolkitInfo; + +// ---------------------------------------------------------------------------- +// toolkit information +// ---------------------------------------------------------------------------- + +// Information about the toolkit that the app is running under (e.g. wxMSW): +struct WXDLLIMPEXP_BASE wxToolkitInfo +{ + // Short name of the toolkit (e.g. "msw" or "mswuniv"); empty for console: + wxString shortName; + // Descriptive name of the toolkit, human readable (e.g. "wxMSW" or + // "wxMSW/Universal"); "wxBase" for console apps: + wxString name; + // Version of the underlying toolkit or of the OS for console apps: + int versionMajor, versionMinor; + // OS mnenomics, e.g. wxGTK or wxMSW: + int os; +}; + // ---------------------------------------------------------------------------- // wxAppTraits: this class defines various configurable aspects of wxApp @@ -85,13 +107,14 @@ public: virtual void RemoveFromPendingDelete(wxObject *object) = 0; - // other miscellaneous helpers - // --------------------------- - - // wxGetOsVersion() behaves differently in GUI and non-GUI builds under - // Unix: in the former case it returns the information about the toolkit - // and in the latter -- about the OS, so we need to virtualize it - virtual int GetOSVersion(int *verMaj, int *verMin) = 0; + // return information about what toolkit is running; we need for two things + // that are both contained in wxBase: + // - wxGetOsVersion() behaves differently in GUI and non-GUI builds under + // Unix: in the former case it returns the information about the toolkit + // and in the latter -- about the OS, so we need to virtualize it + // - wxDynamicLibrary::CanonicalizePluginName() must embed toolkit + // signature in DLL name + virtual wxToolkitInfo *GetToolkitInfo() = 0; }; // ---------------------------------------------------------------------------- diff --git a/include/wx/mac/apptrait.h b/include/wx/mac/apptrait.h index e6d6bdfed9..7cae381e37 100644 --- a/include/wx/mac/apptrait.h +++ b/include/wx/mac/apptrait.h @@ -22,7 +22,7 @@ public: // other miscellaneous helpers // --------------------------- - virtual int GetOSVersion(int *verMaj, int *verMin); + virtual wxToolkitInfo *GetToolkitInfo(); }; #if wxUSE_GUI @@ -33,7 +33,7 @@ public: // other miscellaneous helpers // --------------------------- - virtual int GetOSVersion(int *verMaj, int *verMin); + virtual wxToolkitInfo *GetToolkitInfo(); }; #endif // wxUSE_GUI diff --git a/include/wx/msw/apptbase.h b/include/wx/msw/apptbase.h index ce0dc36d10..ef8db45012 100644 --- a/include/wx/msw/apptbase.h +++ b/include/wx/msw/apptbase.h @@ -44,9 +44,10 @@ public: // other miscellaneous helpers // --------------------------- - // under MSW this function does the same thing for console and GUI - // applications so we can implement it directly in the base class - virtual int GetOSVersion(int *verMaj, int *verMin); + // under MSW this function returns same version for both console and GUI + // applications so we can implement it directly in the base class and only + // override it wxGUIAppTraits to fill in toolkit information + virtual wxToolkitInfo *GetToolkitInfo(); }; #endif // _WX_MSW_APPTBASE_H_ diff --git a/include/wx/msw/apptrait.h b/include/wx/msw/apptrait.h index a85f992051..41789eda05 100644 --- a/include/wx/msw/apptrait.h +++ b/include/wx/msw/apptrait.h @@ -36,6 +36,7 @@ public: virtual void AfterChildWaitLoop(void *data); virtual bool DoMessageFromThreadWait(); + virtual wxToolkitInfo *GetToolkitInfo(); }; #endif // wxUSE_GUI diff --git a/include/wx/unix/apptrait.h b/include/wx/unix/apptrait.h index 13b25fcbc6..598b4b4d80 100644 --- a/include/wx/unix/apptrait.h +++ b/include/wx/unix/apptrait.h @@ -24,7 +24,7 @@ public: virtual void DetachWriteFDOfEndProcessPipe(wxExecuteData& execData); virtual int WaitForChild(wxExecuteData& execData); - virtual int GetOSVersion(int *verMaj, int *verMin); + virtual wxToolkitInfo *GetToolkitInfo(); }; #if wxUSE_GUI @@ -37,7 +37,7 @@ public: virtual void DetachWriteFDOfEndProcessPipe(wxExecuteData& execData); virtual int WaitForChild(wxExecuteData& execData); - virtual int GetOSVersion(int *verMaj, int *verMin); + virtual wxToolkitInfo *GetToolkitInfo(); }; #endif // wxUSE_GUI diff --git a/src/common/dynlib.cpp b/src/common/dynlib.cpp index f537a51adf..1ba9660c9f 100644 --- a/src/common/dynlib.cpp +++ b/src/common/dynlib.cpp @@ -39,6 +39,8 @@ #include "wx/log.h" #include "wx/utils.h" #include "wx/filename.h" // for SplitPath() +#include "wx/app.h" +#include "wx/apptrait.h" #if defined(__WXMAC__) #include "wx/mac/private.h" @@ -409,31 +411,11 @@ wxString wxDynamicLibrary::CanonicalizePluginName(const wxString& name, wxString suffix; if ( cat == wxDL_PLUGIN_GUI ) { - suffix = wxString::FromAscii( -#if defined(__WXMSW__) - "msw" -#elif defined(__WXGTK__) - "gtk" -#elif defined(__WXMGL__) - "mgl" -#elif defined(__WXMOTIF__) - "motif" -#elif defined(__WXOS2__) - "pm" -#elif defined(__WXX11__) - "x11" -#elif defined(__WXMAC__) - "mac" -#elif defined(__WXCOCOA__) - "cocoa" -#else // FIXME - wrong! - "" -#endif - ); - -#ifdef __WXUNIVERSAL__ - suffix << _T("univ"); -#endif + wxAppTraits *traits = wxAppConsole::GetInstance() ? + wxAppConsole::GetInstance()->GetTraits() : NULL; + wxASSERT_MSG( traits, + _("can't query for GUI plugins name in console applications") ); + suffix = traits->GetToolkitInfo()->shortName; } #if wxUSE_UNICODE suffix << _T('u'); diff --git a/src/common/utilscmn.cpp b/src/common/utilscmn.cpp index 3e96078407..f6195cfeb2 100644 --- a/src/common/utilscmn.cpp +++ b/src/common/utilscmn.cpp @@ -293,7 +293,12 @@ int wxGetOsVersion(int *verMaj, int *verMin) if ( ! traits ) traits = &traitsConsole; - return traits->GetOSVersion(verMaj, verMin); + wxToolkitInfo *info = traits->GetToolkitInfo(); + if ( verMaj ) + *verMaj = info->versionMajor; + if ( verMin ) + *verMin = info->versionMinor; + return info->os; } // ---------------------------------------------------------------------------- diff --git a/src/gtk/utilsgtk.cpp b/src/gtk/utilsgtk.cpp index 75972bb8b6..1e0d4dccc1 100644 --- a/src/gtk/utilsgtk.cpp +++ b/src/gtk/utilsgtk.cpp @@ -122,14 +122,23 @@ int wxDisplayDepth() return gdk_window_get_visual( wxGetRootWindow()->window )->depth; } -int wxGUIAppTraits::GetOSVersion(int *majorVsn, int *minorVsn) +wxToolkitInfo *wxGUIAppTraits::GetToolkitInfo() { - if (majorVsn) - *majorVsn = GTK_MAJOR_VERSION; - if (minorVsn) - *minorVsn = GTK_MINOR_VERSION; - - return wxGTK; + static wxToolkitInfo info; +#ifdef __WXGTK20__ + info.shortName = _T("gtk2"); +#else + info.shortName = _T("gtk"); +#endif + info.name = _T("wxGTK"); +#ifdef __WXUNIVERSAL__ + info.shortName << _T("univ"); + info.name << _T("/wxUniversal"); +#endif + info.versionMajor = GTK_MAJOR_VERSION; + info.versionMinor = GTK_MINOR_VERSION; + info.os = wxGTK; + return &info; } wxWindow* wxFindWindowAtPoint(const wxPoint& pt) diff --git a/src/gtk1/utilsgtk.cpp b/src/gtk1/utilsgtk.cpp index 75972bb8b6..1e0d4dccc1 100644 --- a/src/gtk1/utilsgtk.cpp +++ b/src/gtk1/utilsgtk.cpp @@ -122,14 +122,23 @@ int wxDisplayDepth() return gdk_window_get_visual( wxGetRootWindow()->window )->depth; } -int wxGUIAppTraits::GetOSVersion(int *majorVsn, int *minorVsn) +wxToolkitInfo *wxGUIAppTraits::GetToolkitInfo() { - if (majorVsn) - *majorVsn = GTK_MAJOR_VERSION; - if (minorVsn) - *minorVsn = GTK_MINOR_VERSION; - - return wxGTK; + static wxToolkitInfo info; +#ifdef __WXGTK20__ + info.shortName = _T("gtk2"); +#else + info.shortName = _T("gtk"); +#endif + info.name = _T("wxGTK"); +#ifdef __WXUNIVERSAL__ + info.shortName << _T("univ"); + info.name << _T("/wxUniversal"); +#endif + info.versionMajor = GTK_MAJOR_VERSION; + info.versionMinor = GTK_MINOR_VERSION; + info.os = wxGTK; + return &info; } wxWindow* wxFindWindowAtPoint(const wxPoint& pt) diff --git a/src/mac/carbon/utils.cpp b/src/mac/carbon/utils.cpp index ae2d5b4140..6e1bd0d1b4 100644 --- a/src/mac/carbon/utils.cpp +++ b/src/mac/carbon/utils.cpp @@ -218,18 +218,29 @@ static int DoGetOSVersion(int *majorVsn, int *minorVsn) #endif } -int wxConsoleAppTraits::GetOSVersion(int *majorVsn, int *minorVsn) +wxToolkitInfo *wxConsoleAppTraits::GetToolkitInfo() { - return DoGetOSVersion(majorVsn, minorVsn); + static wxToolkitInfo info; + info.os = DoGetOSVersion(&info.majorVersion, &info.minorVersion); + info.name = _T("wxBase"); + return &info; } #endif // wxUSE_BASE #if wxUSE_GUI -int wxGUIAppTraits::GetOSVersion(int *majorVsn, int *minorVsn) +wxToolkitInfo *wxGUIAppTraits::GetToolkitInfo() { - return DoGetOSVersion(majorVsn, minorVsn); + static wxToolkitInfo info; + info.os = DoGetOSVersion(&info.majorVersion, &info.minorVersion); + info.shortName = _T("mac"); + info.name = _T("wxMac"); +#ifdef __WXUNIVERSAL__ + info.shortName << _T("univ"); + info.name << _T("/wxUniversal"); +#endif + return &info; } // Reading and writing resources (eg WIN.INI, .Xdefaults) diff --git a/src/mac/utils.cpp b/src/mac/utils.cpp index ae2d5b4140..6e1bd0d1b4 100644 --- a/src/mac/utils.cpp +++ b/src/mac/utils.cpp @@ -218,18 +218,29 @@ static int DoGetOSVersion(int *majorVsn, int *minorVsn) #endif } -int wxConsoleAppTraits::GetOSVersion(int *majorVsn, int *minorVsn) +wxToolkitInfo *wxConsoleAppTraits::GetToolkitInfo() { - return DoGetOSVersion(majorVsn, minorVsn); + static wxToolkitInfo info; + info.os = DoGetOSVersion(&info.majorVersion, &info.minorVersion); + info.name = _T("wxBase"); + return &info; } #endif // wxUSE_BASE #if wxUSE_GUI -int wxGUIAppTraits::GetOSVersion(int *majorVsn, int *minorVsn) +wxToolkitInfo *wxGUIAppTraits::GetToolkitInfo() { - return DoGetOSVersion(majorVsn, minorVsn); + static wxToolkitInfo info; + info.os = DoGetOSVersion(&info.majorVersion, &info.minorVersion); + info.shortName = _T("mac"); + info.name = _T("wxMac"); +#ifdef __WXUNIVERSAL__ + info.shortName << _T("univ"); + info.name << _T("/wxUniversal"); +#endif + return &info; } // Reading and writing resources (eg WIN.INI, .Xdefaults) diff --git a/src/motif/utils.cpp b/src/motif/utils.cpp index 01c0719c0c..ab645457b2 100644 --- a/src/motif/utils.cpp +++ b/src/motif/utils.cpp @@ -133,19 +133,24 @@ void wxBell() XBell (wxGlobalDisplay(), 0); } -int wxGUIAppTraits::GetOSVersion(int *majorVsn, int *minorVsn) +wxToolkitInfo *wxGUIAppTraits::GetToolkitInfo() { + wxToolkitInfo info; + info.shortName = _T("motif"); + info.name = _T("wxMotif"); +#ifdef __WXUNIVERSAL__ + info.shortName << _T("univ"); + info.name << _T("/wxUniversal"); +#endif // FIXME TODO // This code is WRONG!! Does NOT return the // Motif version of the libs but the X protocol // version! Display *display = wxGlobalDisplay(); - if (majorVsn) - *majorVsn = ProtocolVersion (display); - if (minorVsn) - *minorVsn = ProtocolRevision (display); - - return wxMOTIF_X; + info.versionMajor = ProtocolVersion (display); + info.versionMinor = ProtocolRevision (display); + info.os = wxMOTIF_X; + return &info; } // ---------------------------------------------------------------------------- diff --git a/src/msw/app.cpp b/src/msw/app.cpp index 2b12d8ebb0..8d2c220f95 100644 --- a/src/msw/app.cpp +++ b/src/msw/app.cpp @@ -229,6 +229,22 @@ bool wxGUIAppTraits::DoMessageFromThreadWait() return !wxTheApp || wxTheApp->DoMessage(); } +wxToolkitInfo *wxGUIAppTraits::GetToolkitInfo() +{ + static wxToolkitInfo info; + wxToolkitInfo *baseInfo = wxAppTraits::GetToolkitInfo(); + info.versionMajor = baseInfo->versionMajor; + info.versionMinor = baseInfo->versionMinor; + info.os = baseInfo->os; + info.shortName = _T("msw"); + info.name = _T("wxMSW"); +#ifdef __WXUNIVERSAL__ + info.shortName << _T("univ"); + info.name << _T("/wxUniversal"); +#endif + return &info; +} + // =========================================================================== // wxApp implementation // =========================================================================== diff --git a/src/msw/utils.cpp b/src/msw/utils.cpp index e53cdcbfcb..3a3f03a76c 100644 --- a/src/msw/utils.cpp +++ b/src/msw/utils.cpp @@ -1012,7 +1012,7 @@ wxString wxGetOsDescription() #endif // Win32/16 } -int wxAppTraits::GetOSVersion(int *verMaj, int *verMin) +wxToolkitInfo *wxAppTraits::GetToolkitInfo() { // cache the version info, it's not going to change // @@ -1056,12 +1056,12 @@ int wxAppTraits::GetOSVersion(int *verMaj, int *verMin) } } - if ( verMaj ) - *verMaj = s_major; - if ( verMin ) - *verMin = s_minor; - - return s_ver; + static wxToolkitInfo info; + info.versionMajor = s_major; + info.versionMinor = s_minor; + info.os = s_ver; + info.name = _T("wxBase"); + return &info; } // ---------------------------------------------------------------------------- diff --git a/src/unix/baseunix.cpp b/src/unix/baseunix.cpp index b265339a06..630ad555a0 100644 --- a/src/unix/baseunix.cpp +++ b/src/unix/baseunix.cpp @@ -88,8 +88,9 @@ wxConsoleAppTraits::WaitForChild(wxExecuteData& execData) // this is in mac/utils.cpp under Mac #ifndef __WXMAC__ -int wxConsoleAppTraits::GetOSVersion(int *verMaj, int *verMin) +wxToolkitInfo *wxConsoleAppTraits::GetToolkitInfo() { + static wxToolkitInfo info; int major, minor; char name[256]; @@ -100,12 +101,12 @@ int wxConsoleAppTraits::GetOSVersion(int *verMaj, int *verMin) minor = -1; } - if ( verMaj ) - *verMaj = major; - if ( verMin ) - *verMin = minor; + info.versionMajor = major; + info.versionMinor = minor; + info.name = _T("wxBase"); + info.os = wxUNIX; - return wxUNIX; + return &info; } #endif // __WXMAC__ diff --git a/src/unix/gsocket.c b/src/unix/gsocket.c index 3c5fa00ed0..09924de226 100644 --- a/src/unix/gsocket.c +++ b/src/unix/gsocket.c @@ -111,7 +111,8 @@ struct sockaddr_un #endif /* __GSOCKET_STANDALONE__ */ /* redefine some GUI-only functions to do nothing in console mode */ -#if defined(wxUSE_GUI) && !wxUSE_GUI +#if 1 //defined(wxUSE_GUI) && !wxUSE_GUI + // FIXME -- temporary measure # define _GSocket_GUI_Init(socket) (1) # define _GSocket_GUI_Destroy(socket) # define _GSocket_Enable_Events(socket) diff --git a/src/x11/utils.cpp b/src/x11/utils.cpp index 0dedaec505..0bdd4ed3dc 100644 --- a/src/x11/utils.cpp +++ b/src/x11/utils.cpp @@ -98,15 +98,15 @@ void wxBell() XBell ((Display*) wxGetDisplay(), 0); } -int wxGUIAppTraits::GetOSVersion(int *majorVsn, int *minorVsn) +wxToolkitInfo *wxGUIAppTraits::GetToolkitInfo() { - if (majorVsn) - *majorVsn = 0; - - if (minorVsn) - *minorVsn = 0; - - return wxX11; + static wxToolkitInfo info; + info.shortName = _T("x11univ"); + info.name = _T("wxX11"); + info.versionMajor = 0; + info.versionMinor = 0; + info.os = wxX11; + return &info; } // ----------------------------------------------------------------------------