]> git.saurik.com Git - wxWidgets.git/blobdiff - src/os2/utils.cpp
fixed compile error for FINAL=1
[wxWidgets.git] / src / os2 / utils.cpp
index 34ae33543ad92bdd8b1c3c27277a7f0fcf181598..15fd47cea381f2f24d5132810d69ef25e46dec64 100644 (file)
@@ -9,10 +9,6 @@
 // Licence:     wxWindows license
 /////////////////////////////////////////////////////////////////////////////
 
-#ifdef __GNUG__
-// #pragma implementation "utils.h"   // Note: this is done in utilscmn.cpp now.
-#endif
-
 // For compilers that support precompilation, includes "wx.h".
 #include "wx/wxprec.h"
 
@@ -27,9 +23,6 @@
 #include "wx/timer.h"
 #include "wx/intl.h"
 
-#define INCL_OS2
-#define INCL_PM
-
 #include <ctype.h>
 #include <direct.h>
 
 #include <errno.h>
 #include <stdarg.h>
 
+#define INCL_DOS
+#define INCL_PM
+#define INCL_GPI
+#include <os2.h>
 #include<netdb.h>
-#include<upm.h>
+#define PURE_32
+#include <upm.h>
+#include <netcons.h>
+#include <netbios.h>
 
 // In the WIN.INI file
-static const wxChar WX_SECTION[] = "wxWindows";
-static const wxChar eHOSTNAME[]  = "HostName";
-static const wxChar eUSERID[]    = "UserId";
-static const wxChar eUSERNAME[]  = "UserName";
+static const wxChar WX_SECTION[] = _T("wxWindows");
+static const wxChar eHOSTNAME[]  = _T("HostName");
+static const wxChar eUSERID[]    = _T("UserId");
+static const wxChar eUSERNAME[]  = _T("UserName");
 
 // For the following functions we SHOULD fill in support
 // for Windows-NT (which I don't know) as I assume it begin
@@ -60,7 +60,7 @@ static const wxChar eUSERNAME[]  = "UserName";
 // Get full hostname (eg. DoDo.BSn-Germany.crg.de)
 bool wxGetHostName(wxChar *buf, int maxSize)
 {
-#ifdef USE_NET_API
+#if wxUSE_NET_API
   char                               server[256];
   char                               computer[256];
   unsigned long                      ulLevel;
@@ -68,8 +68,8 @@ bool wxGetHostName(wxChar *buf, int maxSize)
   unsigned long                      ulBuffer;
   unsigned long*                     pulTotalAvail;
 
-  NetBios32GetInfo( server
-                   ,computer
+  NetBios32GetInfo( (const unsigned char*)server
+                   ,(const unsigned char*)computer
                    ,ulLevel
                    ,pbBuffer
                    ,ulBuffer
@@ -80,10 +80,12 @@ bool wxGetHostName(wxChar *buf, int maxSize)
   wxChar *sysname;
   const wxChar *default_host = _T("noname");
 
-  if ((sysname = wxGetenv(_T("SYSTEM_NAME"))) == NULL) {
-     GetProfileString(WX_SECTION, eHOSTNAME, default_host, buf, maxSize - 1);
-  } else
-    wxStrncpy(buf, sysname, maxSize - 1);
+  if ((sysname = wxGetenv(_T("SYSTEM_NAME"))) == NULL)
+  {
+      // GetProfileString(WX_SECTION, eHOSTNAME, default_host, buf, maxSize - 1);
+  }
+  else
+      wxStrncpy(buf, sysname, maxSize - 1);
   buf[maxSize] = _T('\0');
 #endif
   return *buf ? TRUE : FALSE;
@@ -92,7 +94,7 @@ bool wxGetHostName(wxChar *buf, int maxSize)
 // Get user ID e.g. jacs
 bool wxGetUserId(wxChar *buf, int maxSize)
 {
-  return(U32ELOCL(bub, maxSize));
+  return(U32ELOCL((unsigned char*)buf, (unsigned long *)&maxSize));
 }
 
 bool wxGetUserName(wxChar *buf, int maxSize)
@@ -100,16 +102,7 @@ bool wxGetUserName(wxChar *buf, int maxSize)
 #ifdef USE_NET_API
     wxGetUserId(buf, maxSize);
 #else
-    bool ok = GetProfileString(WX_SECTION, eUSERNAME, _T(""), buf, maxSize - 1) != 0;
-    if ( !ok )
-    {
-        ok = wxGetUserId(buf, maxSize);
-    }
-
-    if ( !ok )
-    {
-        wxStrncpy(buf, _T("Unknown User"), maxSize);
-    }
+    wxStrncpy(buf, _T("Unknown User"), maxSize);
 #endif
   return TRUE;
 }
@@ -125,8 +118,8 @@ int wxKill(long pid, int sig)
 bool wxShell(const wxString& command)
 {
   wxChar *shell;
-  if ((shell = wxGetenv("COMSPEC")) == NULL)
-    shell = "\\CMD.EXE";
+  if ((shell = wxGetenv(_T("COMSPEC"))) == NULL)
+    shell = _T("\\CMD.EXE");
 
   wxChar tmp[255];
   if (command != "")
@@ -138,9 +131,17 @@ bool wxShell(const wxString& command)
 }
 
 // Get free memory in bytes, or -1 if cannot determine amount (e.g. on UNIX)
-long wxGetFreeMemory()
+long wxGetFreeMemory(void *memptr)
 {
-  return (long)GetFreeSpace(0);
+    ULONG                           lSize;
+    ULONG                           lMemFlags;
+    APIRET                          rc;
+
+    lMemFlags = PAG_FREE;
+    rc = ::DosQueryMem(memptr, &lSize, &lMemFlags);
+    if (rc != 0)
+        return -1L;
+    return (long)lSize;
 }
 
 // Sleep for nSecs seconds. Attempt a Windows implementation using timers.
@@ -165,19 +166,7 @@ void wxUsleep(unsigned long milliseconds)
 
 void wxSleep(int nSecs)
 {
-  if (inTimer)
-    return;
-
-  wxTheSleepTimer = new wxSleepTimer;
-  inTimer = TRUE;
-  wxTheSleepTimer->Start(nSecs*1000);
-  while (inTimer)
-  {
-    if (wxTheApp->Pending())
-      wxTheApp->Dispatch();
-  }
-  delete wxTheSleepTimer;
-  wxTheSleepTimer = NULL;
+    ::DosSleep( 1000*nSecs );
 }
 
 // Consume all events until no more left
@@ -198,7 +187,6 @@ void wxDebugMsg(const wxChar *fmt ...)
   va_start(ap, fmt);
 
    sprintf(buffer,fmt,ap) ;
-   fflush(buffer) ;
 
   va_end(ap);
 }
@@ -211,24 +199,24 @@ void wxError(const wxString& msg, const wxString& title)
                       ,NULL
                       ,(PSZ)wxBuffer
                       ,(PSZ)WXSTRINGCAST title
+                      ,0
                       ,MB_ICONEXCLAMATION | MB_YESNO
-                     ) == IDNO)
+                     ) == MBID_YES)
     wxExit();
 }
 
 // Fatal error: pop up message box and abort
-void wxFatalError(const wxString& msg, const wxString& title)
-{
-    YUint32                         rc;
-    HWND                            hWnd;
-
-    WinMessageBox( HWND_DESKTOP
-                  ,hWnd
-                  ,rMsg.Data()
-                  ,rTitle.Data()
-                  ,0
-                  ,MB_NOICON | MB_OK
-                 );
+void wxFatalError(const wxString& rMsg, const wxString& rTitle)
+{
+    unsigned long                   rc;
+
+    rc = ::WinMessageBox( HWND_DESKTOP
+                         ,NULL
+                         ,WXSTRINGCAST rMsg
+                         ,WXSTRINGCAST rTitle
+                         ,0
+                         ,MB_NOICON | MB_OK
+                        );
     DosExit(EXIT_PROCESS, rc);
 }
 
@@ -258,57 +246,97 @@ int wxGetOsVersion(int *majorVsn, int *minorVsn)
 }
 
 // Reading and writing resources (eg WIN.INI, .Xdefaults)
+// TODO: Ability to read and write to an INI file
+
 #if wxUSE_RESOURCES
 bool wxWriteResource(const wxString& section, const wxString& entry, const wxString& value, const wxString& file)
 {
-  if (file != "")
-    return (WritePrivateProfileString((PCSZ)WXSTRINGCAST section, (PCSZ)WXSTRINGCAST entry, (PCSZ)value, (PCSZ)WXSTRINGCAST file) != 0);
-  else
-    return (WriteProfileString((PCSZ)WXSTRINGCAST section, (PCSZ)WXSTRINGCAST entry, (PCSZ)WXSTRINGCAST value) != 0);
+    HAB                             hab;
+    HINI                            hIni;
+
+    if (file != "")
+    {
+        hIni = ::PrfOpenProfile(hab, (PSZ)WXSTRINGCAST file);
+        if (hIni != 0L)
+        {
+            return (::PrfWriteProfileString( hIni
+                                            ,(PSZ)WXSTRINGCAST section
+                                            ,(PSZ)WXSTRINGCAST entry
+                                            ,(PSZ)WXSTRINGCAST value
+                                           ));
+        }
+    }
+    else
+        return (::PrfWriteProfileString( HINI_PROFILE
+                                        ,(PSZ)WXSTRINGCAST section
+                                        ,(PSZ)WXSTRINGCAST entry
+                                        ,(PSZ)WXSTRINGCAST value
+                                       ));
+    return FALSE;
 }
 
 bool wxWriteResource(const wxString& section, const wxString& entry, float value, const wxString& file)
 {
-  wxChar buf[50];
-  wxSprintf(buf, "%.4f", value);
-  return wxWriteResource(section, entry, buf, file);
+    wxChar buf[50];
+    wxSprintf(buf, "%.4f", value);
+    return wxWriteResource(section, entry, buf, file);
 }
 
 bool wxWriteResource(const wxString& section, const wxString& entry, long value, const wxString& file)
 {
-  wxChar buf[50];
-  wxSprintf(buf, "%ld", value);
-  return wxWriteResource(section, entry, buf, file);
+    wxChar buf[50];
+    wxSprintf(buf, "%ld", value);
+    return wxWriteResource(section, entry, buf, file);
 }
 
 bool wxWriteResource(const wxString& section, const wxString& entry, int value, const wxString& file)
 {
-  wxChar buf[50];
-  wxSprintf(buf, "%d", value);
-  return wxWriteResource(section, entry, buf, file);
+    wxChar buf[50];
+    wxSprintf(buf, "%d", value);
+    return wxWriteResource(section, entry, buf, file);
 }
 
 bool wxGetResource(const wxString& section, const wxString& entry, wxChar **value, const wxString& file)
 {
-  static const wxChar defunkt[] = "$$default";
-  if (file != "")
-  {
-    int n = GetPrivateProfileString((PCSZ)WXSTRINGCAST section, (PCSZ)WXSTRINGCAST entry, (PCSZ)defunkt,
-                                    (PSZ)wxBuffer, 1000, (PCSZ)WXSTRINGCAST file);
-    if (n == 0 || wxStrcmp(wxBuffer, defunkt) == 0)
-     return FALSE;
-  }
-  else
-  {
-    int n = GetProfileString((PCSZ)WXSTRINGCAST section, (PCSZ)WXSTRINGCAST entry, (LPCTSTR)defunkt,
-                                    (PSZ)wxBuffer, 1000);
-    if (n == 0 || wxStrcmp(wxBuffer, defunkt) == 0)
-      return FALSE;
-  }
-  if (*value) delete[] (*value);
-      *value = copystring(wxBuffer);
-      return TRUE;
+    HAB                             hab;
+    HINI                            hIni;
+    static const wxChar             defunkt[] = _T("$$default");
+
+    if (file != "")
+    {
+        hIni = ::PrfOpenProfile(hab, (PSZ)WXSTRINGCAST file);
+        if (hIni != 0L)
+        {
+            ULONG n = ::PrfQueryProfileString( hIni
+                                              ,(PSZ)WXSTRINGCAST section
+                                              ,(PSZ)WXSTRINGCAST entry
+                                              ,(PSZ)defunkt
+                                              ,(void*)wxBuffer
+                                              ,1000
+                                             );
+            if (n == 0L || wxStrcmp(wxBuffer, defunkt) == 0)
+                return FALSE;
+        }
+        else
+            return FALSE;
+    }
+    else
+    {
+        ULONG n = ::PrfQueryProfileString( HINI_PROFILE
+                                          ,(PSZ)WXSTRINGCAST section
+                                          ,(PSZ)WXSTRINGCAST entry
+                                          ,(PSZ)defunkt
+                                          ,(void*)wxBuffer
+                                          ,1000
+                                         );
+        if (n == 0L || wxStrcmp(wxBuffer, defunkt) == 0)
+            return FALSE;
     }
+    if (*value)
+        delete[] (*value);
+    *value = copystring(wxBuffer);
+    return TRUE;
+}
 
 bool wxGetResource(const wxString& section, const wxString& entry, float *value, const wxString& file)
 {
@@ -373,7 +401,7 @@ void wxBeginBusyCursor(wxCursor *cursor)
 void wxEndBusyCursor()
 {
     wxCHECK_RET( gs_wxBusyCursorCount > 0,
-                 "no matching wxBeginBusyCursor() for wxEndBusyCursor()");
+                 _T("no matching wxBeginBusyCursor() for wxEndBusyCursor()"));
 
     if ( --gs_wxBusyCursorCount == 0 )
     {
@@ -420,10 +448,10 @@ wxChar *wxGetUserHome (const wxString& user)
     wxChar tmp[64];
     if (wxGetUserId(tmp, sizeof(tmp)/sizeof(char))) {
       // Guests belong in the temp dir
-      if (wxStricmp(tmp, "annonymous") == 0) {
-        if ((home = wxGetenv("TMP")) != NULL ||
-            (home = wxGetenv("TMPDIR")) != NULL ||
-            (home = wxGetenv("TEMP")) != NULL)
+      if (wxStricmp(tmp, _T("annonymous")) == 0) {
+        if ((home = wxGetenv(_T("TMP"))) != NULL ||
+            (home = wxGetenv(_T("TMPDIR"))) != NULL ||
+            (home = wxGetenv(_T("TEMP"))) != NULL)
             return *home ? home : (wxChar*)_T("\\");
       }
       if (wxStricmp(tmp, WXSTRINGCAST user1) == 0)
@@ -431,7 +459,7 @@ wxChar *wxGetUserHome (const wxString& user)
     }
   }
   if (user1 == _T(""))
-    if ((home = wxGetenv("HOME")) != NULL)
+    if ((home = wxGetenv(_T("HOME"))) != NULL)
     {
       wxStrcpy(wxBuffer, home);
       Unix2DosFilename(wxBuffer);
@@ -452,12 +480,12 @@ bool wxCheckForInterrupt(wxWindow *wnd)
     HWND win= (HWND) wnd->GetHWND();
     while(::WinPeekMsg(hab,&msg,hwndFilter,0,0,PM_REMOVE))
     {
-      ::WinDispatchMsg( hab, &qmsg );
+      ::WinDispatchMsg( hab, &msg );
     }
     return TRUE;//*** temporary?
   }
   else{
-    wxFAIL_MSG("wnd==NULL !!!");
+    wxFAIL_MSG(_T("wnd==NULL !!!"));
 
     return FALSE;//*** temporary?
   }
@@ -488,26 +516,26 @@ wxChar *wxLoadUserResource(const wxString& resourceName, const wxString& resourc
 *   wxChar *theText = (wxChar *)LockResource(hData);
 *   if (!theText)
 *     return NULL;
+*
+* s = copystring(theText);
 */
-  s = copystring(theText);
-
   return s;
 }
 
 void wxGetMousePosition( int* x, int* y )
 {
-  POINT pt;
-  GetCursorPos( & pt );
-  *x = pt.x;
-  *y = pt.y;
+    POINTL pt;
+    ::WinQueryPointerPos( HWND_DESKTOP, & pt );
+    *x = pt.x;
+    *y = pt.y;
 };
 
 // Return TRUE if we have a colour display
 bool wxColourDisplay()
 {
-  bool flag;
-  // TODO:  use DosQueryDevCaps to figure it out
-  return flag;
+    bool flag;
+    // TODO:  use DosQueryDevCaps to figure it out
+    return flag;
 }
 
 // Returns depth of screen
@@ -530,7 +558,7 @@ int wxDisplayDepth()
         nDepth = nPlanes * nBitsPerPixel;
     }
     DevCloseDC(hDc);
-    return (depth);
+    return (nDepth);
 }
 
 // Get size of display
@@ -545,8 +573,8 @@ void wxDisplaySize(int *width, int *height)
                     ,lArray
                    ))
     {
-        *pWidth  = (int)lArray[CAPS_WIDTH];
-        *pHeight = (int)lArray[CAPS_HEIGHT];
+        *width  = (int)lArray[CAPS_WIDTH];
+        *height = (int)lArray[CAPS_HEIGHT];
     }
     DevCloseDC(hDc);
 }
@@ -565,7 +593,7 @@ wxString WXDLLEXPORT wxGetWindowText(WXHWND hWnd)
 {
     wxString str;
     long len = ::WinQueryWindowTextLength((HWND)hWnd) + 1;
-    ::WinQueryWindowText((HWND)hWnd, str.GetWriteBuf((int)len), len);
+    ::WinQueryWindowText((HWND)hWnd, len, str.GetWriteBuf((int)len));
     str.UngetWriteBuf();
 
     return str;
@@ -579,7 +607,7 @@ wxString WXDLLEXPORT wxGetWindowClass(WXHWND hWnd)
 
     for ( ;; )
     {
-        int count = ::WinQueryClassName((HWND)hWnd, str.GetWriteBuf(len), len);
+        int count = ::WinQueryClassName((HWND)hWnd, len, str.GetWriteBuf(len));
 
         str.UngetWriteBuf();
         if ( count == len )