]> git.saurik.com Git - wxWidgets.git/blobdiff - src/os2/utils.cpp
move code ignoring VK_SPACE and VK_RETURN WM_CHAR messages to MSWDefWindowProc()...
[wxWidgets.git] / src / os2 / utils.cpp
index 68b0e3e6af550d59263e307461eeae6b106e56b1..f29aafc86b204b42f4e658b23a64a4744bc9b190 100644 (file)
@@ -19,7 +19,6 @@
 #endif  //WX_PRECOMP
 
 #include "wx/os2/private.h"
-#include "wx/timer.h"
 #include "wx/intl.h"
 #include "wx/apptrait.h"
 
@@ -46,7 +45,7 @@
 #include <netbios.h>
 #endif
 
-static const wxChar WX_SECTION[] = _T("wxWindows");
+static const wxChar WX_SECTION[] = _T("wxWidgets");
 static const wxChar eHOSTNAME[]  = _T("HostName");
 static const wxChar eUSERID[]    = _T("UserId");
 static const wxChar eUSERNAME[]  = _T("UserName");
@@ -84,19 +83,19 @@ bool wxGetHostName(
 
     if ((zSysname = wxGetenv(_T("SYSTEM_NAME"))) == NULL)
     {
-        ULONG n = ::PrfQueryProfileString( HINI_PROFILE
-                                          ,(PSZ)WX_SECTION
-                                          ,(PSZ)eHOSTNAME
-                                          ,(PSZ)zDefaultHost
-                                          ,(void*)zBuf
-                                          ,(ULONG)nMaxSize - 1
-                                         );
+        ::PrfQueryProfileString( HINI_PROFILE
+                                ,(PSZ)WX_SECTION
+                                ,(PSZ)eHOSTNAME
+                                ,(PSZ)zDefaultHost
+                                ,(void*)zBuf
+                                ,(ULONG)nMaxSize - 1
+                               );
     }
     else
         wxStrncpy(zBuf, zSysname, nMaxSize - 1);
     zBuf[nMaxSize] = _T('\0');
 #endif
-    return *zBuf ? TRUE : FALSE;
+    return *zBuf ? true : false;
 }
 
 // Get user ID e.g. jacs
@@ -109,9 +108,9 @@ bool wxGetUserId(
     long                            lrc;
     // UPM procs return 0 on success
     lrc = U32ELOCU((unsigned char*)zBuf, (unsigned long *)&nType);
-    if (lrc == 0) return TRUE;
+    if (lrc == 0) return true;
 #endif
-    return FALSE;
+    return false;
 }
 
 bool wxGetUserName(
@@ -126,13 +125,14 @@ bool wxGetUserName(
 #else
     wxStrncpy(zBuf, _T("Unknown User"), nMaxSize);
 #endif
-    return TRUE;
+    return true;
 }
 
 int wxKill(
   long                              lPid
 , wxSignal                          eSig
 , wxKillError*                      peError
+, int                               flags
 )
 {
     return((int)::DosKillProcess(0, (PID)lPid));
@@ -147,7 +147,6 @@ bool wxShell(
 {
     wxChar*                         zShell = _T("CMD.EXE");
     wxString                        sInputs;
-    wxChar                          zTmp[255];
     STARTDATA                       SData = {0};
     PSZ                             PgmTitle = "Command Shell";
     APIRET                          rc;
@@ -202,22 +201,40 @@ bool wxShell(
 bool wxShutdown(wxShutdownFlags wFlags)
 {
     // TODO
-    return FALSE;
+    return false;
+}
+
+wxPowerType wxGetPowerType()
+{
+    // TODO
+    return wxPOWER_UNKNOWN;
+}
+
+wxBatteryState wxGetBatteryState()
+{
+    // TODO
+    return wxBATTERY_UNKNOWN_STATE;
 }
 
 // Get free memory in bytes, or -1 if cannot determine amount (e.g. on UNIX)
-long wxGetFreeMemory()
+wxMemorySize wxGetFreeMemory()
 {
     void*                           pMemptr = NULL;
-    ULONG                           lSize;
+    LONG                            lSize;
     ULONG                           lMemFlags;
     APIRET                          rc;
 
     lMemFlags = PAG_FREE;
-    rc = ::DosQueryMem(pMemptr, &lSize, &lMemFlags);
+    rc = ::DosQueryMem(pMemptr, (PULONG)&lSize, &lMemFlags);
     if (rc != 0)
-        return -1L;
-    return (long)lSize;
+        lSize = -1L;
+    return (wxMemorySize)lSize;
+}
+
+// Get Process ID
+unsigned long wxGetProcessId()
+{
+    return (unsigned long)getpid();
 }
 
 // ----------------------------------------------------------------------------
@@ -229,14 +246,14 @@ bool wxGetEnv(const wxString& var, wxString *value)
     // wxGetenv is defined as getenv()
     wxChar *p = wxGetenv(var);
     if ( !p )
-        return FALSE;
+        return false;
 
     if ( value )
     {
         *value = p;
     }
 
-    return TRUE;
+    return true;
 }
 
 bool wxSetEnv(const wxString& variable, const wxChar *value)
@@ -258,17 +275,24 @@ bool wxSetEnv(const wxString& variable, const wxChar *value)
 
     return putenv(buf) == 0;
 #else // no way to set an env var
-    return FALSE;
+    return false;
 #endif
 }
 
-void wxUsleep(
+void wxMilliSleep(
   unsigned long                     ulMilliseconds
 )
 {
     ::DosSleep(ulMilliseconds);
 }
 
+void wxMicroSleep(
+  unsigned long                     ulMicroseconds
+)
+{
+    ::DosSleep(ulMicroseconds/1000);
+}
+
 void wxSleep(
   int                               nSecs
 )
@@ -305,7 +329,7 @@ void wxError(
 , const wxString&                   rTitle
 )
 {
-    wxBuffer = new wxChar[256];
+    wxChar *wxBuffer = new wxChar[256];
     wxSprintf(wxBuffer, "%s\nContinue?", WXSTRINGCAST rMsg);
     if (::WinMessageBox( HWND_DESKTOP
                         ,NULL
@@ -343,15 +367,23 @@ void wxBell()
 {
     DosBeep(1000,1000); // 1kHz during 1 sec.
 }
-#if 0
-int wxGUIAppTraits::GetOSVersion(
-  int*                              pMajorVsn
-, int*                              pMinorVsn
-)
+
+
+void wxAppTraits::InitializeGui(unsigned long &ulHab)
 {
-    ULONG                           ulSysInfo[QSV_MAX] = {0};
-    APIRET                          ulrc;
+}
 
+void wxAppTraits::TerminateGui(unsigned long ulHab)
+{
+}
+
+wxToolkitInfo & wxConsoleAppTraits::GetToolkitInfo()
+{
+    static wxToolkitInfo  vInfo;
+    ULONG                 ulSysInfo[QSV_MAX] = {0};
+    APIRET                ulrc;
+
+    vInfo.name = _T("wxBase");
     ulrc = ::DosQuerySysInfo( 1L
                              ,QSV_MAX
                              ,(PVOID)ulSysInfo
@@ -359,14 +391,13 @@ int wxGUIAppTraits::GetOSVersion(
                             );
     if (ulrc == 0L)
     {
-        *pMajorVsn = ulSysInfo[QSV_VERSION_MAJOR];
-        *pMajorVsn = *pMajorVsn/10;
-        *pMinorVsn = ulSysInfo[QSV_VERSION_MINOR];
-        return wxWINDOWS_OS2;
+        vInfo.versionMajor = ulSysInfo[QSV_VERSION_MAJOR] / 10;
+        vInfo.versionMinor = ulSysInfo[QSV_VERSION_MINOR];
     }
-    return wxWINDOWS; // error if we get here, return generic value
+    vInfo.os = wxOS2_PM;
+    return vInfo;
 }
-#endif
+
 // ---------------------------------------------------------------------------
 const wxChar* wxGetHomeDir(
   wxString*                         pStr
@@ -375,18 +406,24 @@ const wxChar* wxGetHomeDir(
     wxString&                       rStrDir = *pStr;
 
     // OS/2 has no idea about home,
-    // so use the working directory instead?
+    // so use the working directory instead.
+    // However, we might have a valid HOME directory,
+    // as is used on many machines that have unix utilities
+    // on them, so we should use that, if available.
 
     // 256 was taken from os2def.h
 #ifndef MAX_PATH
 #  define MAX_PATH  256
 #endif
 
-    char                            zDirName[256];
-    ULONG                           ulDirLen;
+    const wxChar *szHome = wxGetenv("HOME");
+    if ( szHome == NULL ) {
+      // we're homeless, use current directory.
+      rStrDir = wxT(".");
+    }
+    else
+       rStrDir = szHome;
 
-    ::DosQueryCurrentDir(0, zDirName, &ulDirLen);
-    rStrDir = zDirName;
     return rStrDir.c_str();
 }
 
@@ -398,9 +435,9 @@ wxChar* wxGetUserHome (
     wxChar*                         zHome;
     wxString                        sUser1(rUser);
 
-    wxBuffer = new wxChar[256];
+    char *wxBuffer = new wxChar[256];
 #ifndef __EMX__
-    if (sUser1 != _T(""))
+    if (!sUser1.empty())
     {
         wxChar                      zTmp[64];
 
@@ -422,7 +459,7 @@ wxChar* wxGetUserHome (
         }
     }
 #endif
-    if (sUser1 == _T(""))
+    if (sUser1.empty())
     {
         if ((zHome = wxGetenv(_T("HOME"))) != NULL)
         {
@@ -437,13 +474,6 @@ wxChar* wxGetUserHome (
     return NULL; // No home known!
 }
 
-bool wxDirExists(
-  const wxString&                   rDir
-)
-{
-    return (::DosSetCurrentDir(WXSTRINGCAST rDir));
-}
-
 wxString WXDLLEXPORT wxPMErrorToStr(
   ERRORID                           vError
 )
@@ -501,3 +531,12 @@ wxString WXDLLEXPORT wxPMErrorToStr(
     }
     return(sError);
 } // end of wxPMErrorToStr
+
+// replacement for implementation in unix/utilsunx.cpp,
+// to be used by all X11 based ports.
+struct wxEndProcessData;
+
+void wxHandleProcessTermination(wxEndProcessData *proc_data)
+{
+    // For now, just do nothing. To be filled in as needed.
+}