]> git.saurik.com Git - wxWidgets.git/blobdiff - src/common/platinfo.cpp
fixing modal dialog quit after nested message box problem
[wxWidgets.git] / src / common / platinfo.cpp
index df765b153a79596f36726ad2d76826f0a5e87f15..a687a47862f4f96f45282ed860bf952d8ad5edc6 100644 (file)
 
 #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
 // ----------------------------------------------------------------------------
@@ -56,8 +62,14 @@ static const wxChar* const 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 const wxChar* const wxPortIdNames[] =
 };
 
 static const wxChar* const wxPortIdNames[] =
@@ -93,8 +105,8 @@ static const wxChar* const wxEndiannessNames[] =
 // local functions
 // ----------------------------------------------------------------------------
 
 // local functions
 // ----------------------------------------------------------------------------
 
-// returns log in base 2 of the value, this maps the enum values to the
-// corresponding indices
+// returns the logarithm in base 2 of 'value'; this maps the enum values to the
+// corresponding indexes of the string arrays above
 static unsigned wxGetIndexFromEnumValue(int value)
 {
     wxCHECK_MSG( value, (unsigned)-1, _T("invalid enum value") );
 static unsigned wxGetIndexFromEnumValue(int value)
 {
     wxCHECK_MSG( value, (unsigned)-1, _T("invalid enum value") );
@@ -117,26 +129,8 @@ 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_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,
 }
 
 wxPlatformInfo::wxPlatformInfo(wxPortId pid, int tkMajor, int tkMinor,
@@ -165,12 +159,67 @@ bool wxPlatformInfo::operator==(const wxPlatformInfo &t) const
            m_osVersionMajor == t.m_osVersionMajor &&
            m_osVersionMinor == t.m_osVersionMinor &&
            m_os == t.m_os &&
            m_osVersionMajor == t.m_osVersionMajor &&
            m_osVersionMinor == t.m_osVersionMinor &&
            m_os == t.m_os &&
+           m_osDesc == t.m_osDesc &&
+           m_ldi == t.m_ldi &&
+           m_desktopEnv == t.m_desktopEnv &&
            m_port == t.m_port &&
            m_usingUniversal == t.m_usingUniversal &&
            m_arch == t.m_arch &&
            m_endian == t.m_endian;
 }
 
            m_port == t.m_port &&
            m_usingUniversal == t.m_usingUniversal &&
            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_desktopEnv = traits->GetDesktopEnvironment();
+    }
+
+    m_os = wxGetOsVersion(&m_osVersionMajor, &m_osVersionMinor);
+    m_osDesc = wxGetOsDescription();
+    m_endian = wxIsPlatformLittleEndian() ? wxENDIAN_LITTLE : wxENDIAN_BIG;
+    m_arch = wxIsPlatform64Bit() ? wxARCH_64 : wxARCH_32;
+    
+#ifdef __LINUX__
+    m_ldi = wxGetLinuxDistributionInfo();
+#endif
+    // else: leave m_ldi empty
+}
+
+/* static */
+const wxPlatformInfo& wxPlatformInfo::Get()
+{
+    static bool initialized = false;
+    if ( !initialized )
+    {
+        gs_platInfo.InitForCurrentPlatform();
+        initialized = true;
+    }
+
+    return gs_platInfo;
+}
+
+/* static */
+wxString wxPlatformInfo::GetOperatingSystemDirectory()
+{
+    return wxGetOSDirectory();
+}
+
+
+
 // ----------------------------------------------------------------------------
 // wxPlatformInfo - enum -> string conversions
 // ----------------------------------------------------------------------------
 // ----------------------------------------------------------------------------
 // wxPlatformInfo - enum -> string conversions
 // ----------------------------------------------------------------------------
@@ -294,11 +343,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;