]> git.saurik.com Git - wxWidgets.git/blobdiff - src/common/platinfo.cpp
Reorganize wxCollapsiblePane event and layout code under GTK+
[wxWidgets.git] / src / common / platinfo.cpp
index 4a6c50aa1d227c2261f6d15852fc48661d7d820a..fbb27bfd942731bad3ba04ed2c42986d60ac0996 100644 (file)
     #pragma hdrstop
 #endif
 
     #pragma hdrstop
 #endif
 
+#include "wx/platinfo.h"
+
 #ifndef WX_PRECOMP
 #ifndef WX_PRECOMP
+    #include "wx/app.h"
     #include "wx/utils.h"
 #endif //WX_PRECOMP
 
     #include "wx/utils.h"
 #endif //WX_PRECOMP
 
-#include "wx/platinfo.h"
 #include "wx/apptrait.h"
 
 #include "wx/apptrait.h"
 
+// global object
+// VERY IMPORTANT: do not use the default constructor since it would
+//                 try to init the wxPlatformInfo instance using
+//                 gs_platInfo itself!
+static wxPlatformInfo gs_platInfo(wxPORT_UNKNOWN);
+
 // ----------------------------------------------------------------------------
 // constants
 // ----------------------------------------------------------------------------
 
 // ----------------------------------------------------------------------------
 // constants
 // ----------------------------------------------------------------------------
 
-static wxString wxOperatingSystemIdNames[] =
+static const wxChar* const wxOperatingSystemIdNames[] =
 {
     _T("Apple Mac OS"),
     _T("Apple Mac OS X"),
 {
     _T("Apple Mac OS"),
     _T("Apple Mac OS X"),
@@ -54,11 +62,17 @@ static wxString wxOperatingSystemIdNames[] =
     _T("AIX"),
     _T("HPUX"),
 
     _T("AIX"),
     _T("HPUX"),
 
+    _T("Other Unix"),
+    _T("Other Unix"),
+
     _T("DOS"),
     _T("DOS"),
-    _T("OS/2")
+    _T("OS/2"),
+
+    _T("PalmOS"),
+    _T("PalmOS(Over Linux)"),
 };
 
 };
 
-static wxString wxPortIdNames[] =
+static const wxChar* const wxPortIdNames[] =
 {
     _T("wxBase"),
     _T("wxMSW"),
 {
     _T("wxBase"),
     _T("wxMSW"),
@@ -70,16 +84,17 @@ static wxString wxPortIdNames[] =
     _T("wxMac"),
     _T("wxCocoa"),
     _T("wxWinCE"),
     _T("wxMac"),
     _T("wxCocoa"),
     _T("wxWinCE"),
-    _T("wxPalmOS")
+    _T("wxPalmOS"),
+    _T("wxDFB")
 };
 
 };
 
-static wxString wxArchitectureNames[] =
+static const wxChar* const wxArchitectureNames[] =
 {
     _T("32 bit"),
     _T("64 bit")
 };
 
 {
     _T("32 bit"),
     _T("64 bit")
 };
 
-static wxString wxEndiannessNames[] =
+static const wxChar* const wxEndiannessNames[] =
 {
     _T("Big endian"),
     _T("Little endian"),
 {
     _T("Big endian"),
     _T("Little endian"),
@@ -114,34 +129,20 @@ static unsigned wxGetIndexFromEnumValue(int value)
 
 wxPlatformInfo::wxPlatformInfo()
 {
 
 wxPlatformInfo::wxPlatformInfo()
 {
-    // autodetect all informations
-    const wxAppTraits * const traits = wxTheApp ? wxTheApp->GetTraits() : NULL;
-    if ( !traits )
-    {
-        wxFAIL_MSG( _T("failed to initialize wxPlatformInfo") );
-
-        m_port = wxPORT_UNKNOWN;
-        m_tkVersionMajor =
-        m_tkVersionMinor = 0;
-    }
-    else
-    {
-        m_port = traits->GetToolkitVersion(&m_tkVersionMajor, &m_tkVersionMinor);
-    }
-
-    m_os = wxGetOsVersion(&m_osVersionMajor, &m_osVersionMinor);
-    m_endian = wxIsPlatformLittleEndian() ? wxENDIAN_LITTLE : wxENDIAN_BIG;
-    m_arch = wxIsPlatform64Bit() ? wxARCH_64 : wxARCH_32;
+    // just copy platform info for currently running platform
+    *this = Get();
 }
 
 wxPlatformInfo::wxPlatformInfo(wxPortId pid, int tkMajor, int tkMinor,
                                wxOperatingSystemId id, int osMajor, int osMinor,
                                wxArchitecture arch,
 }
 
 wxPlatformInfo::wxPlatformInfo(wxPortId pid, int tkMajor, int tkMinor,
                                wxOperatingSystemId id, int osMajor, int osMinor,
                                wxArchitecture arch,
-                               wxEndianness endian)
+                               wxEndianness endian,
+                               bool usingUniversal)
 {
     m_tkVersionMajor = tkMajor;
     m_tkVersionMinor = tkMinor;
     m_port = pid;
 {
     m_tkVersionMajor = tkMajor;
     m_tkVersionMinor = tkMinor;
     m_port = pid;
+    m_usingUniversal = usingUniversal;
 
     m_os = id;
     m_osVersionMajor = osMajor;
 
     m_os = id;
     m_osVersionMajor = osMajor;
@@ -159,28 +160,69 @@ bool wxPlatformInfo::operator==(const wxPlatformInfo &t) const
            m_osVersionMinor == t.m_osVersionMinor &&
            m_os == t.m_os &&
            m_port == t.m_port &&
            m_osVersionMinor == t.m_osVersionMinor &&
            m_os == t.m_os &&
            m_port == t.m_port &&
+           m_usingUniversal == t.m_usingUniversal &&
            m_arch == t.m_arch &&
            m_endian == t.m_endian;
 }
 
            m_arch == t.m_arch &&
            m_endian == t.m_endian;
 }
 
+void wxPlatformInfo::InitForCurrentPlatform()
+{
+    // autodetect all informations
+    const wxAppTraits * const traits = wxTheApp ? wxTheApp->GetTraits() : NULL;
+    if ( !traits )
+    {
+        wxFAIL_MSG( _T("failed to initialize wxPlatformInfo") );
+
+        m_port = wxPORT_UNKNOWN;
+        m_usingUniversal = false;
+        m_tkVersionMajor =
+                m_tkVersionMinor = 0;
+    }
+    else
+    {
+        m_port = traits->GetToolkitVersion(&m_tkVersionMajor, &m_tkVersionMinor);
+        m_usingUniversal = traits->IsUsingUniversalWidgets();
+    }
+
+    m_os = wxGetOsVersion(&m_osVersionMajor, &m_osVersionMinor);
+    m_endian = wxIsPlatformLittleEndian() ? wxENDIAN_LITTLE : wxENDIAN_BIG;
+    m_arch = wxIsPlatform64Bit() ? wxARCH_64 : wxARCH_32;
+}
+
+/* static */
+const wxPlatformInfo& wxPlatformInfo::Get()
+{
+    static bool initialized = false;
+    if ( !initialized )
+    {
+        gs_platInfo.InitForCurrentPlatform();
+        initialized = true;
+    }
+
+    return gs_platInfo;
+}
+
+
+
 // ----------------------------------------------------------------------------
 // wxPlatformInfo - enum -> string conversions
 // ----------------------------------------------------------------------------
 
 wxString wxPlatformInfo::GetOperatingSystemFamilyName(wxOperatingSystemId os)
 {
 // ----------------------------------------------------------------------------
 // wxPlatformInfo - enum -> string conversions
 // ----------------------------------------------------------------------------
 
 wxString wxPlatformInfo::GetOperatingSystemFamilyName(wxOperatingSystemId os)
 {
+    const wxChar* string = _T("Unknown");
     if ( os & wxOS_MAC )
     if ( os & wxOS_MAC )
-        return _T("Macintosh");
+        string = _T("Macintosh");
     else if ( os & wxOS_WINDOWS )
     else if ( os & wxOS_WINDOWS )
-        return _T("Windows");
+        string = _T("Windows");
     else if ( os & wxOS_UNIX )
     else if ( os & wxOS_UNIX )
-        return _T("Unix");
+        string = _T("Unix");
     else if ( os == wxOS_DOS )
     else if ( os == wxOS_DOS )
-        return _T("DOS");
+        string = _T("DOS");
     else if ( os == wxOS_OS2 )
     else if ( os == wxOS_OS2 )
-        return _T("OS/2");
+        string = _T("OS/2");
 
 
-    return _T("Unknown");
+    return string;
 }
 
 wxString wxPlatformInfo::GetOperatingSystemIdName(wxOperatingSystemId os)
 }
 
 wxString wxPlatformInfo::GetOperatingSystemIdName(wxOperatingSystemId os)
@@ -193,7 +235,7 @@ wxString wxPlatformInfo::GetOperatingSystemIdName(wxOperatingSystemId os)
     return wxOperatingSystemIdNames[idx];
 }
 
     return wxOperatingSystemIdNames[idx];
 }
 
-wxString wxPlatformInfo::GetPortIdName(wxPortId port)
+wxString wxPlatformInfo::GetPortIdName(wxPortId port, bool usingUniversal)
 {
     const unsigned idx = wxGetIndexFromEnumValue(port);
 
 {
     const unsigned idx = wxGetIndexFromEnumValue(port);
 
@@ -202,13 +244,13 @@ wxString wxPlatformInfo::GetPortIdName(wxPortId port)
 
     wxString ret = wxPortIdNames[idx];
 
 
     wxString ret = wxPortIdNames[idx];
 
-    if ( IsUsingUniversalWidgets() )
+    if ( usingUniversal )
         ret += wxT("/wxUniversal");
 
     return ret;
 }
 
         ret += wxT("/wxUniversal");
 
     return ret;
 }
 
-wxString wxPlatformInfo::GetPortIdShortName(wxPortId port)
+wxString wxPlatformInfo::GetPortIdShortName(wxPortId port, bool usingUniversal)
 {
     const unsigned idx = wxGetIndexFromEnumValue(port);
 
 {
     const unsigned idx = wxGetIndexFromEnumValue(port);
 
@@ -218,7 +260,7 @@ wxString wxPlatformInfo::GetPortIdShortName(wxPortId port)
     wxString ret = wxPortIdNames[idx];
     ret = ret.Mid(2).Lower();       // remove 'wx' prefix
 
     wxString ret = wxPortIdNames[idx];
     ret = ret.Mid(2).Lower();       // remove 'wx' prefix
 
-    if ( IsUsingUniversalWidgets() )
+    if ( usingUniversal )
         ret += wxT("univ");
 
     return ret;
         ret += wxT("univ");
 
     return ret;
@@ -249,7 +291,7 @@ wxOperatingSystemId wxPlatformInfo::GetOperatingSystemId(const wxString &str)
 {
     for ( size_t i = 0; i < WXSIZEOF(wxOperatingSystemIdNames); i++ )
     {
 {
     for ( size_t i = 0; i < WXSIZEOF(wxOperatingSystemIdNames); i++ )
     {
-        if ( wxOperatingSystemIdNames[i].CmpNoCase(str) == 0 )
+        if ( wxString(wxOperatingSystemIdNames[i]).CmpNoCase(str) == 0 )
             return (wxOperatingSystemId)(1 << i);
     }
 
             return (wxOperatingSystemId)(1 << i);
     }
 
@@ -263,9 +305,9 @@ wxPortId wxPlatformInfo::GetPortId(const wxString &str)
     {
         wxPortId current = (wxPortId)(1 << i);
 
     {
         wxPortId current = (wxPortId)(1 << i);
 
-        if ( wxPortIdNames[i].CmpNoCase(str) == 0 )
-            return current;
-        if ( GetPortIdShortName(current).CmpNoCase(str) == 0 )
+        if ( wxString(wxPortIdNames[i]).CmpNoCase(str) == 0 ||
+             GetPortIdShortName(current, true).CmpNoCase(str) == 0 ||
+             GetPortIdShortName(current, false).CmpNoCase(str) == 0 )
             return current;
     }
 
             return current;
     }
 
@@ -285,11 +327,11 @@ wxArchitecture wxPlatformInfo::GetArch(const wxString &arch)
 
 wxEndianness wxPlatformInfo::GetEndianness(const wxString& end)
 {
 
 wxEndianness wxPlatformInfo::GetEndianness(const wxString& end)
 {
-    wxString endl(end.Lower());
-    if ( end.StartsWith(wxT("little")) )
+    const wxString endl(end.Lower());
+    if ( endl.StartsWith(wxT("little")) )
         return wxENDIAN_LITTLE;
 
         return wxENDIAN_LITTLE;
 
-    if ( end.StartsWith(wxT("big")) )
+    if ( endl.StartsWith(wxT("big")) )
         return wxENDIAN_BIG;
 
     return wxENDIAN_INVALID;
         return wxENDIAN_BIG;
 
     return wxENDIAN_INVALID;