Index: trunk/src/user32/caret.cpp
===================================================================
--- trunk/src/user32/caret.cpp	(revision 1071)
+++ trunk/src/user32/caret.cpp	(revision 1071)
@@ -0,0 +1,247 @@
+/* $Id: caret.cpp,v 1.1 1999-09-27 18:20:00 dengert Exp $ */
+
+/*
+ * Caret functions for USER32
+ *
+ * Project Odin Software License can be found in LICENSE.TXT
+ *
+ */
+
+#define INCL_WIN
+#include <os2.h>
+#include <os2sel.h>
+#include <stdlib.h>
+#include "win32type.h"
+#include <winconst.h>
+#include <wprocess.h>
+#include <misc.h>
+#include <win32wbase.h>
+#include "oslibwin.h"
+#include "dcdata.h"
+
+#undef SEVERITY_ERROR
+#include <winerror.h>
+
+#ifndef OPEN32API
+#define OPEN32API _System
+#endif
+
+static HWND hwndCaret;
+static HBITMAP hbmCaret;
+static int CaretWidth, CaretHeight;
+static int CaretPosX, CaretPosY;
+static BOOL CaretIsVisible;
+
+BOOL WIN32API CreateCaret (HWND hwnd, HBITMAP hBmp, int width, int height)
+{
+   if (hwnd == NULLHANDLE)
+   {
+      return FALSE;
+   }
+   else
+   {
+       BOOL rc;
+       Win32BaseWindow *wnd = Win32BaseWindow::GetWindowFromHandle(hwnd);
+
+       if (!wnd) return (FALSE);
+
+       USHORT sel = RestoreOS2FS();
+       wnd->SetFakeOpen32();
+
+       rc = _O32_CreateCaret (hwnd, hBmp, width, height);
+       if (rc)
+       {
+           hwndCaret   = hwnd;
+           hbmCaret    = hBmp;
+           CaretWidth  = width;
+           CaretHeight = height;
+       }
+
+       wnd->RemoveFakeOpen32();
+       SetFS(sel);
+       return (rc);
+   }
+}
+
+BOOL WIN32API DestroyCaret()
+{
+   BOOL rc;
+   USHORT sel = RestoreOS2FS();
+
+   hwndCaret      = 0;
+   hbmCaret       = 0;
+   CaretWidth     = 0;
+   CaretHeight    = 0;
+   CaretIsVisible = FALSE;
+
+   rc = _DestroyCaret();
+
+   SetFS(sel);
+   return (rc);
+}
+
+
+UINT WIN32API GetCaretBlinkTime()
+{
+   UINT rc;
+   USHORT sel = RestoreOS2FS();
+
+   rc = _GetCaretBlinkTime();
+
+   SetFS(sel);
+   return (rc);
+}
+
+BOOL WIN32API GetCaretPos (PPOINT pPoint)
+{
+   USHORT sel = RestoreOS2FS();
+   CURSORINFO cursorInfo;
+
+   if (WinQueryCursorInfo (HWND_DESKTOP, &cursorInfo))
+   {
+      if (cursorInfo.hwnd != HWND_DESKTOP)
+      {
+         HPS hps = NULLHANDLE;
+         HWND hwnd = cursorInfo.hwnd;
+         Win32BaseWindow *wnd = Win32BaseWindow::GetWindowFromOS2Handle (hwnd);
+
+         if (wnd && wnd->isOwnDC())
+            hps = wnd->getOwnDC();
+
+         POINTL caretPos = {cursorInfo.x,cursorInfo.y} ;
+         if (hps) {
+            GpiConvert (hps, CVTC_DEVICE, CVTC_WORLD, 1, &caretPos);
+            cursorInfo.x = caretPos.x;
+            cursorInfo.y = caretPos.y;
+         } else {
+            caretPos.y += cursorInfo.cy;
+            convertDevicePoint( cursorInfo.hwnd, &caretPos, 1);
+            cursorInfo.y = caretPos.y;
+         }
+      }
+      pPoint->x = cursorInfo.x;
+      pPoint->y = cursorInfo.y;
+
+      SetFS(sel);
+      return TRUE;
+   }
+   else
+   {
+      SetFS(sel);
+      return FALSE;
+   }
+}
+
+BOOL WIN32API HideCaret (HWND hwnd)
+{
+   USHORT sel = RestoreOS2FS();
+   BOOL rc = FALSE;
+   Win32BaseWindow *wnd = Win32BaseWindow::GetWindowFromHandle (hwnd);
+
+   CaretIsVisible = FALSE;
+
+   if (wnd)
+       rc = _HideCaret (wnd->getOS2WindowHandle());
+
+   SetFS(sel);
+   return (rc);
+}
+
+BOOL WIN32API SetCaretBlinkTime (UINT mSecs)
+{
+   USHORT sel = RestoreOS2FS();
+   BOOL rc;
+
+   rc = _SetCaretBlinkTime (mSecs);
+
+   SetFS(sel);
+   return (rc);
+}
+
+BOOL WIN32API SetCaretPos (int x, int y)
+{
+   USHORT     sel = RestoreOS2FS();
+   LONG       xNew = 0, yNew = 0;
+   BOOL       result = TRUE;
+   BOOL       rc;
+   CURSORINFO cursorInfo;
+   POINTL     caretPos = { x, y };
+
+   rc = WinQueryCursorInfo (HWND_DESKTOP, &cursorInfo);
+   if (rc == TRUE)
+   {
+      HWND hwnd = cursorInfo.hwnd;
+      Win32BaseWindow *wnd = Win32BaseWindow::GetWindowFromOS2Handle (hwnd);
+      if (wnd && wnd->isOwnDC())
+      {
+         HPS     hps  = wnd->getOwnDC();
+         pDCData pHps = (pDCData)GpiQueryDCData(hps);
+         if (!pHps)
+         {
+            _O32_SetLastError (ERROR_INTERNAL_ERROR);
+            SetFS(sel);
+            return FALSE;
+         }
+#if 0
+         convertWinWorldPointToPMDevicePoint (pHps, &caretPos, 1);
+
+         xNew = caretPos.x;
+
+         if (doesYAxisGrowNorth(pHps) == TRUE)
+         {
+            yNew = caretPos.y;
+         }
+         else
+         {
+            yNew = caretPos.y - cursorInfo.cy;
+         }
+#endif
+      }
+      else
+      {
+//         convertWinDevicePointToPMDevicePoint (cursorInfo.hwnd, &caretPos, 1);
+         xNew = caretPos.x;
+         yNew = caretPos.y - cursorInfo.cy;
+      }
+
+      hwndCaret = wnd->getWindowHandle();
+      CaretPosX = x;
+      CaretPosY = y;
+
+      rc = WinCreateCursor (cursorInfo.hwnd, xNew, yNew, 0, 0, CURSOR_SETPOS, NULL);
+   }
+   if (rc == FALSE)
+   {
+      _O32_SetLastError (ERROR_INVALID_PARAMETER);
+      result = FALSE;
+   }
+
+   SetFS(sel);
+   return (result);
+}
+
+BOOL WIN32API ShowCaret (HWND hwnd)
+{
+   USHORT sel = RestoreOS2FS();
+   BOOL   rc = FALSE;
+
+   CaretIsVisible = TRUE;
+   rc = _ShowCaret (Win32ToOS2Handle (hwnd));
+
+   SetFS(sel);
+   return (result);
+}
+
+void recreateCaret (HWND hwndFocus)
+{
+   CURSORINFO cursorInfo;
+
+   if ((hwndCaret == hwndFocus)
+       && !WinQueryCursorInfo (HWND_DESKTOP, &cursorInfo))
+   {
+      CreateCaret (hwndCaret, hbmCaret, CaretWidth, CaretHeight);
+      SetCaretPos (CaretPosX, CaretPosY);
+      if (CaretIsVisible)
+         ShowCaret (hwndCaret);
+   }
+}
