]> git.saurik.com Git - wxWidgets.git/blobdiff - src/os2/utils.cpp
More scrolling stuff.
[wxWidgets.git] / src / os2 / utils.cpp
index 34cb8a977f85db24a84c0ffadf90f58ac64ee2de..94a7823eebfe91e39dcf9cea616fe7f555d96963 100644 (file)
@@ -26,8 +26,6 @@
 #include <ctype.h>
 #ifdef __EMX__
 #include <dirent.h>
-#else
-#include <direct.h>
 #endif
 
 #include "wx/log.h"
 #include <errno.h>
 #include <stdarg.h>
 
-#define INCL_DOS
-#define INCL_PM
-#define INCL_GPI
-#include <os2.h>
 #define PURE_32
+
 #ifndef __EMX__
 #include <upm.h>
 #include <netcons.h>
@@ -217,6 +212,49 @@ long wxGetFreeMemory()
     return (long)lSize;
 }
 
+// ----------------------------------------------------------------------------
+// env vars
+// ----------------------------------------------------------------------------
+
+bool wxGetEnv(const wxString& var, wxString *value)
+{
+    // wxGetenv is defined as getenv()
+    wxChar *p = wxGetenv(var);
+    if ( !p )
+        return FALSE;
+
+    if ( value )
+    {
+        *value = p;
+    }
+
+    return TRUE;
+}
+
+bool wxSetEnv(const wxString& variable, const wxChar *value)
+{
+#if defined(HAVE_SETENV)
+    return setenv(variable.mb_str(), value ? wxString(value).mb_str().data()
+                                           : NULL, 1 /* overwrite */) == 0;
+#elif defined(HAVE_PUTENV)
+    wxString s = variable;
+    if ( value )
+        s << _T('=') << value;
+
+    // transform to ANSI
+    const char *p = s.mb_str();
+
+    // the string will be free()d by libc
+    char *buf = (char *)malloc(strlen(p) + 1);
+    strcpy(buf, p);
+
+    return putenv(buf) == 0;
+#else // no way to set an env var
+    return FALSE;
+#endif
+}
+
+
 // Sleep for nSecs seconds. Attempt a Windows implementation using timers.
 static bool inTimer = FALSE;
 
@@ -236,7 +274,7 @@ void wxUsleep(
   unsigned long                     ulMilliseconds
 )
 {
-    ::DosSleep(ulMilliseconds);
+    ::DosSleep(ulMilliseconds/1000l);
 }
 
 void wxSleep(
@@ -760,6 +798,43 @@ void wxDisplaySize(
     *pHeight = (int)lHeight;
 }
 
+void wxDisplaySizeMM(
+  int*                              pWidth
+, int*                              pHeight
+)
+{
+    HPS                             hpsScreen;
+    HDC                             hdcScreen;
+
+    hpsScreen = ::WinGetScreenPS(HWND_DESKTOP);
+    hdcScreen = ::GpiQueryDevice(hpsScreen);
+
+    if (pWidth)
+        ::DevQueryCaps( hdcScreen
+                       ,CAPS_HORIZONTAL_RESOLUTION
+                       ,1L
+                       ,(PLONG)pWidth
+                      );
+    if (pHeight)
+        ::DevQueryCaps( hdcScreen
+                       ,CAPS_VERTICAL_RESOLUTION
+                       ,1L
+                       ,(PLONG)pHeight
+                      );
+}
+
+void wxClientDisplayRect(int *x, int *y, int *width, int *height)
+{
+    // This is supposed to return desktop dimensions minus any window
+    // manager panels, menus, taskbars, etc.  If there is a way to do that
+    // for this platform please fix this function, otherwise it defaults
+    // to the entire desktop.
+    if (x) *x = 0;
+    if (y) *y = 0;
+    wxDisplaySize(width, height);
+}
+
+
 bool wxDirExists(
   const wxString&                   rDir
 )
@@ -817,3 +892,62 @@ WXWORD WXDLLEXPORT wxGetWindowId(
     return ::WinQueryWindowUShort((HWND)hWnd, QWS_ID);
 }
 
+wxString WXDLLEXPORT wxPMErrorToStr(
+  ERRORID                           vError
+)
+{
+    wxString                        sError;
+
+    //
+    // Remove the high order byte -- it is useless
+    //
+    vError &= 0x0000ffff;
+    switch(vError)
+    {
+        case PMERR_INVALID_HWND:
+            sError = wxT("Invalid window handle specified");
+            break;
+
+        case PMERR_INVALID_FLAG:
+            sError = wxT("Invalid flag bit set");
+            break;
+
+        case PMERR_NO_MSG_QUEUE:
+            sError = wxT("No message queue available");
+            break;
+
+        case PMERR_INVALID_PARM:
+            sError = wxT("Parameter contained invalid data");
+            break;
+
+        case PMERR_INVALID_PARAMETERS:
+            sError = wxT("Parameter value is out of range");
+            break;
+
+        case PMERR_PARAMETER_OUT_OF_RANGE:
+            sError = wxT("Parameter value is out of range");
+            break;
+
+        case PMERR_INVALID_INTEGER_ATOM:
+            sError = wxT("Not a valid atom");
+            break;
+
+        case PMERR_INVALID_HATOMTBL:
+            sError = wxT("Atom table handle is invalid");
+            break;
+
+        case PMERR_INVALID_ATOM_NAME:
+            sError = wxT("Not a valid atom name");
+            break;
+
+        case PMERR_ATOM_NAME_NOT_FOUND:
+            sError = wxT("Valid name format, but cannot find name in atom table");
+            break;
+
+        default:
+            sError = wxT("Unknown error");
+    }
+    return(sError);
+} // end of wxPMErrorToStr
+
+