]> git.saurik.com Git - wxWidgets.git/blobdiff - src/common/platinfo.cpp
generate #line references to source .xrc files in wxrc --gettext (patch #1803492...
[wxWidgets.git] / src / common / platinfo.cpp
index e9d2553236876a1bfb478f65024ae1799c0f52f1..163a4c1f63d6aa3b3289eaffc70068ecc051d02f 100644 (file)
 
 #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
 // ----------------------------------------------------------------------------
@@ -56,6 +62,9 @@ static const wxChar* const wxOperatingSystemIdNames[] =
     _T("AIX"),
     _T("HPUX"),
 
+    _T("Other Unix"),
+    _T("Other Unix"),
+
     _T("DOS"),
     _T("OS/2")
 };
@@ -72,7 +81,8 @@ static const wxChar* const wxPortIdNames[] =
     _T("wxMac"),
     _T("wxCocoa"),
     _T("wxWinCE"),
-    _T("wxPalmOS")
+    _T("wxPalmOS"),
+    _T("wxDFB")
 };
 
 static const wxChar* const wxArchitectureNames[] =
@@ -116,26 +126,8 @@ static unsigned wxGetIndexFromEnumValue(int value)
 
 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_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;
+    // just copy platform info for currently running platform
+    *this = Get();
 }
 
 wxPlatformInfo::wxPlatformInfo(wxPortId pid, int tkMajor, int tkMinor,
@@ -170,6 +162,45 @@ bool wxPlatformInfo::operator==(const wxPlatformInfo &t) const
            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
 // ----------------------------------------------------------------------------
@@ -293,11 +324,11 @@ wxArchitecture wxPlatformInfo::GetArch(const wxString &arch)
 
 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;
 
-    if ( end.StartsWith(wxT("big")) )
+    if ( endl.StartsWith(wxT("big")) )
         return wxENDIAN_BIG;
 
     return wxENDIAN_INVALID;