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
This commit is contained in:
Václav Slavík
2003-08-02 15:14:17 +00:00
parent 25c0717a43
commit a8eaaeb237
18 changed files with 171 additions and 95 deletions

View File

@@ -75,6 +75,7 @@ private:
}; };
#endif // wxUSE_GUI #endif // wxUSE_GUI
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// wxAppConsole: wxApp for non-GUI applications // wxAppConsole: wxApp for non-GUI applications
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------

View File

@@ -12,15 +12,37 @@
#ifndef _WX_APPTRAIT_H_ #ifndef _WX_APPTRAIT_H_
#define _WX_APPTRAIT_H_ #define _WX_APPTRAIT_H_
class WXDLLEXPORT wxObject; #include "wx/string.h"
class WXDLLIMPEXP_BASE wxObject;
class WXDLLEXPORT wxAppTraits; class WXDLLEXPORT wxAppTraits;
#if wxUSE_FONTMAP #if wxUSE_FONTMAP
class WXDLLEXPORT wxFontMapper; class WXDLLEXPORT wxFontMapper;
#endif // wxUSE_FONTMAP #endif // wxUSE_FONTMAP
class WXDLLEXPORT wxLog; class WXDLLIMPEXP_BASE wxLog;
class WXDLLEXPORT wxMessageOutput; class WXDLLIMPEXP_BASE wxMessageOutput;
class WXDLLEXPORT wxRendererNative; 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 // wxAppTraits: this class defines various configurable aspects of wxApp
@@ -85,13 +107,14 @@ public:
virtual void RemoveFromPendingDelete(wxObject *object) = 0; virtual void RemoveFromPendingDelete(wxObject *object) = 0;
// other miscellaneous helpers // 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
// wxGetOsVersion() behaves differently in GUI and non-GUI builds under
// Unix: in the former case it returns the information about the toolkit // 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 // and in the latter -- about the OS, so we need to virtualize it
virtual int GetOSVersion(int *verMaj, int *verMin) = 0; // - wxDynamicLibrary::CanonicalizePluginName() must embed toolkit
// signature in DLL name
virtual wxToolkitInfo *GetToolkitInfo() = 0;
}; };
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------

View File

@@ -22,7 +22,7 @@ public:
// other miscellaneous helpers // other miscellaneous helpers
// --------------------------- // ---------------------------
virtual int GetOSVersion(int *verMaj, int *verMin); virtual wxToolkitInfo *GetToolkitInfo();
}; };
#if wxUSE_GUI #if wxUSE_GUI
@@ -33,7 +33,7 @@ public:
// other miscellaneous helpers // other miscellaneous helpers
// --------------------------- // ---------------------------
virtual int GetOSVersion(int *verMaj, int *verMin); virtual wxToolkitInfo *GetToolkitInfo();
}; };
#endif // wxUSE_GUI #endif // wxUSE_GUI

View File

@@ -44,9 +44,10 @@ public:
// other miscellaneous helpers // other miscellaneous helpers
// --------------------------- // ---------------------------
// under MSW this function does the same thing for console and GUI // under MSW this function returns same version for both console and GUI
// applications so we can implement it directly in the base class // applications so we can implement it directly in the base class and only
virtual int GetOSVersion(int *verMaj, int *verMin); // override it wxGUIAppTraits to fill in toolkit information
virtual wxToolkitInfo *GetToolkitInfo();
}; };
#endif // _WX_MSW_APPTBASE_H_ #endif // _WX_MSW_APPTBASE_H_

View File

@@ -36,6 +36,7 @@ public:
virtual void AfterChildWaitLoop(void *data); virtual void AfterChildWaitLoop(void *data);
virtual bool DoMessageFromThreadWait(); virtual bool DoMessageFromThreadWait();
virtual wxToolkitInfo *GetToolkitInfo();
}; };
#endif // wxUSE_GUI #endif // wxUSE_GUI

View File

@@ -24,7 +24,7 @@ public:
virtual void DetachWriteFDOfEndProcessPipe(wxExecuteData& execData); virtual void DetachWriteFDOfEndProcessPipe(wxExecuteData& execData);
virtual int WaitForChild(wxExecuteData& execData); virtual int WaitForChild(wxExecuteData& execData);
virtual int GetOSVersion(int *verMaj, int *verMin); virtual wxToolkitInfo *GetToolkitInfo();
}; };
#if wxUSE_GUI #if wxUSE_GUI
@@ -37,7 +37,7 @@ public:
virtual void DetachWriteFDOfEndProcessPipe(wxExecuteData& execData); virtual void DetachWriteFDOfEndProcessPipe(wxExecuteData& execData);
virtual int WaitForChild(wxExecuteData& execData); virtual int WaitForChild(wxExecuteData& execData);
virtual int GetOSVersion(int *verMaj, int *verMin); virtual wxToolkitInfo *GetToolkitInfo();
}; };
#endif // wxUSE_GUI #endif // wxUSE_GUI

View File

@@ -39,6 +39,8 @@
#include "wx/log.h" #include "wx/log.h"
#include "wx/utils.h" #include "wx/utils.h"
#include "wx/filename.h" // for SplitPath() #include "wx/filename.h" // for SplitPath()
#include "wx/app.h"
#include "wx/apptrait.h"
#if defined(__WXMAC__) #if defined(__WXMAC__)
#include "wx/mac/private.h" #include "wx/mac/private.h"
@@ -409,31 +411,11 @@ wxString wxDynamicLibrary::CanonicalizePluginName(const wxString& name,
wxString suffix; wxString suffix;
if ( cat == wxDL_PLUGIN_GUI ) if ( cat == wxDL_PLUGIN_GUI )
{ {
suffix = wxString::FromAscii( wxAppTraits *traits = wxAppConsole::GetInstance() ?
#if defined(__WXMSW__) wxAppConsole::GetInstance()->GetTraits() : NULL;
"msw" wxASSERT_MSG( traits,
#elif defined(__WXGTK__) _("can't query for GUI plugins name in console applications") );
"gtk" suffix = traits->GetToolkitInfo()->shortName;
#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
} }
#if wxUSE_UNICODE #if wxUSE_UNICODE
suffix << _T('u'); suffix << _T('u');

View File

@@ -293,7 +293,12 @@ int wxGetOsVersion(int *verMaj, int *verMin)
if ( ! traits ) if ( ! traits )
traits = &traitsConsole; traits = &traitsConsole;
return traits->GetOSVersion(verMaj, verMin); wxToolkitInfo *info = traits->GetToolkitInfo();
if ( verMaj )
*verMaj = info->versionMajor;
if ( verMin )
*verMin = info->versionMinor;
return info->os;
} }
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------

View File

@@ -122,14 +122,23 @@ int wxDisplayDepth()
return gdk_window_get_visual( wxGetRootWindow()->window )->depth; return gdk_window_get_visual( wxGetRootWindow()->window )->depth;
} }
int wxGUIAppTraits::GetOSVersion(int *majorVsn, int *minorVsn) wxToolkitInfo *wxGUIAppTraits::GetToolkitInfo()
{ {
if (majorVsn) static wxToolkitInfo info;
*majorVsn = GTK_MAJOR_VERSION; #ifdef __WXGTK20__
if (minorVsn) info.shortName = _T("gtk2");
*minorVsn = GTK_MINOR_VERSION; #else
info.shortName = _T("gtk");
return wxGTK; #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) wxWindow* wxFindWindowAtPoint(const wxPoint& pt)

View File

@@ -122,14 +122,23 @@ int wxDisplayDepth()
return gdk_window_get_visual( wxGetRootWindow()->window )->depth; return gdk_window_get_visual( wxGetRootWindow()->window )->depth;
} }
int wxGUIAppTraits::GetOSVersion(int *majorVsn, int *minorVsn) wxToolkitInfo *wxGUIAppTraits::GetToolkitInfo()
{ {
if (majorVsn) static wxToolkitInfo info;
*majorVsn = GTK_MAJOR_VERSION; #ifdef __WXGTK20__
if (minorVsn) info.shortName = _T("gtk2");
*minorVsn = GTK_MINOR_VERSION; #else
info.shortName = _T("gtk");
return wxGTK; #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) wxWindow* wxFindWindowAtPoint(const wxPoint& pt)

View File

@@ -218,18 +218,29 @@ static int DoGetOSVersion(int *majorVsn, int *minorVsn)
#endif #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 #endif // wxUSE_BASE
#if wxUSE_GUI #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) // Reading and writing resources (eg WIN.INI, .Xdefaults)

View File

@@ -218,18 +218,29 @@ static int DoGetOSVersion(int *majorVsn, int *minorVsn)
#endif #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 #endif // wxUSE_BASE
#if wxUSE_GUI #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) // Reading and writing resources (eg WIN.INI, .Xdefaults)

View File

@@ -133,19 +133,24 @@ void wxBell()
XBell (wxGlobalDisplay(), 0); 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 // FIXME TODO
// This code is WRONG!! Does NOT return the // This code is WRONG!! Does NOT return the
// Motif version of the libs but the X protocol // Motif version of the libs but the X protocol
// version! // version!
Display *display = wxGlobalDisplay(); Display *display = wxGlobalDisplay();
if (majorVsn) info.versionMajor = ProtocolVersion (display);
*majorVsn = ProtocolVersion (display); info.versionMinor = ProtocolRevision (display);
if (minorVsn) info.os = wxMOTIF_X;
*minorVsn = ProtocolRevision (display); return &info;
return wxMOTIF_X;
} }
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------

View File

@@ -229,6 +229,22 @@ bool wxGUIAppTraits::DoMessageFromThreadWait()
return !wxTheApp || wxTheApp->DoMessage(); 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 // wxApp implementation
// =========================================================================== // ===========================================================================

View File

@@ -1012,7 +1012,7 @@ wxString wxGetOsDescription()
#endif // Win32/16 #endif // Win32/16
} }
int wxAppTraits::GetOSVersion(int *verMaj, int *verMin) wxToolkitInfo *wxAppTraits::GetToolkitInfo()
{ {
// cache the version info, it's not going to change // cache the version info, it's not going to change
// //
@@ -1056,12 +1056,12 @@ int wxAppTraits::GetOSVersion(int *verMaj, int *verMin)
} }
} }
if ( verMaj ) static wxToolkitInfo info;
*verMaj = s_major; info.versionMajor = s_major;
if ( verMin ) info.versionMinor = s_minor;
*verMin = s_minor; info.os = s_ver;
info.name = _T("wxBase");
return s_ver; return &info;
} }
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------

View File

@@ -88,8 +88,9 @@ wxConsoleAppTraits::WaitForChild(wxExecuteData& execData)
// this is in mac/utils.cpp under Mac // this is in mac/utils.cpp under Mac
#ifndef __WXMAC__ #ifndef __WXMAC__
int wxConsoleAppTraits::GetOSVersion(int *verMaj, int *verMin) wxToolkitInfo *wxConsoleAppTraits::GetToolkitInfo()
{ {
static wxToolkitInfo info;
int major, minor; int major, minor;
char name[256]; char name[256];
@@ -100,12 +101,12 @@ int wxConsoleAppTraits::GetOSVersion(int *verMaj, int *verMin)
minor = -1; minor = -1;
} }
if ( verMaj ) info.versionMajor = major;
*verMaj = major; info.versionMinor = minor;
if ( verMin ) info.name = _T("wxBase");
*verMin = minor; info.os = wxUNIX;
return wxUNIX; return &info;
} }
#endif // __WXMAC__ #endif // __WXMAC__

View File

@@ -111,7 +111,8 @@ struct sockaddr_un
#endif /* __GSOCKET_STANDALONE__ */ #endif /* __GSOCKET_STANDALONE__ */
/* redefine some GUI-only functions to do nothing in console mode */ /* 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_Init(socket) (1)
# define _GSocket_GUI_Destroy(socket) # define _GSocket_GUI_Destroy(socket)
# define _GSocket_Enable_Events(socket) # define _GSocket_Enable_Events(socket)

View File

@@ -98,15 +98,15 @@ void wxBell()
XBell ((Display*) wxGetDisplay(), 0); XBell ((Display*) wxGetDisplay(), 0);
} }
int wxGUIAppTraits::GetOSVersion(int *majorVsn, int *minorVsn) wxToolkitInfo *wxGUIAppTraits::GetToolkitInfo()
{ {
if (majorVsn) static wxToolkitInfo info;
*majorVsn = 0; info.shortName = _T("x11univ");
info.name = _T("wxX11");
if (minorVsn) info.versionMajor = 0;
*minorVsn = 0; info.versionMinor = 0;
info.os = wxX11;
return wxX11; return &info;
} }
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------