Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

caret.cpp

Go to the documentation of this file.
00001 /* $Id: caret.cpp,v 1.18 2001/06/09 14:50:16 sandervl Exp $ */
00002 
00003 /*
00004  * Caret functions for USER32
00005  *
00006  *
00007  * TODO: Getting height of window instead of checking whether it needs 
00008  *       to be window or client appears to be wrong....
00009  *
00010  * Project Odin Software License can be found in LICENSE.TXT
00011  *
00012  */
00013 
00014 #define INCL_WIN
00015 #define INCL_GPI
00016 #include <os2wrap.h>
00017 #include <os2sel.h>
00018 #include <stdlib.h>
00019 #include <win32type.h>
00020 #include <win32api.h>
00021 #include <winconst.h>
00022 #include <winuser32.h>
00023 #include <wprocess.h>
00024 #include <misc.h>
00025 #include <win32wbase.h>
00026 #include "oslibwin.h"
00027 #include <dcdata.h>
00028 #define INCLUDED_BY_DC
00029 #include "dc.h"
00030 #include "caret.h"
00031 
00032 #define DBG_LOCALLOG    DBG_caret
00033 #include "dbglocal.h"
00034 
00035 #undef SEVERITY_ERROR
00036 #include <winerror.h>
00037 
00038 #ifndef OPEN32API
00039 #define OPEN32API _System
00040 #endif
00041 
00042 #pragma data_seg(_GLOBALDATA)
00043 
00044 static HWND hwndCaret = 0;
00045 static HBITMAP hbmCaret;
00046 static int CaretWidth, CaretHeight;
00047 static int CaretPosX, CaretPosY;
00048 static INT CaretIsVisible; //visible if > 0
00049 
00050 #pragma data_seg()
00051 
00052 
00053 BOOL WIN32API CreateCaret (HWND hwnd, HBITMAP hBmp, int width, int height)
00054 {
00055    dprintf(("USER32:  CreateCaret %x", hwnd));
00056 
00057    if (hwnd == NULLHANDLE)
00058    {
00059       return FALSE;
00060    }
00061    else
00062    {
00063        BOOL rc;
00064        Win32BaseWindow *wnd = Win32BaseWindow::GetWindowFromHandle(hwnd);
00065 
00066        if (!wnd) return (FALSE);
00067 
00068        wnd->SetFakeOpen32();
00069 
00070        rc = O32_CreateCaret (wnd->getOS2WindowHandle(), hBmp, width, height);
00071        if (rc)
00072        {
00073            hwndCaret      = hwnd;
00074            hbmCaret       = hBmp;
00075            CaretWidth     = width;
00076            CaretHeight    = height;
00077            CaretIsVisible = 0;
00078        }
00079 
00080        wnd->RemoveFakeOpen32();
00081        RELEASE_WNDOBJ(wnd);
00082        return (rc);
00083    }
00084 }
00085 
00086 BOOL WIN32API DestroyCaret()
00087 {
00088    BOOL rc;
00089 
00090    dprintf(("USER32:  DestroyCaret"));
00091 
00092    hwndCaret      = 0;
00093    hbmCaret       = 0;
00094    CaretWidth     = 0;
00095    CaretHeight    = 0;
00096    CaretIsVisible = 0;
00097 
00098    rc = _DestroyCaret();
00099 
00100    return (rc);
00101 }
00102 
00103 BOOL WIN32API SetCaretBlinkTime (UINT mSecs)
00104 {
00105    BOOL rc;
00106 
00107    dprintf(("USER32: SetCaretBlinkTime %d ms", mSecs));
00108 
00109    rc = _SetCaretBlinkTime (mSecs);
00110 
00111    return (rc);
00112 }
00113 
00114 UINT WIN32API GetCaretBlinkTime()
00115 {
00116    UINT rc;
00117 
00118    dprintf(("USER32:  GetCaretBlinkTime"));
00119 
00120    rc = _GetCaretBlinkTime();
00121    return (rc);
00122 }
00123 
00124 BOOL WIN32API SetCaretPos (int x, int y)
00125 {
00126    LONG       xNew = 0, yNew = 0;
00127    BOOL       result = TRUE;
00128    BOOL       rc;
00129    CURSORINFO cursorInfo;
00130    POINTL     caretPos = { x, y };
00131 
00132    dprintf(("USER32: SetCaretPos (%d,%d)", x, y));
00133 
00134    rc = WinQueryCursorInfo (HWND_DESKTOP, &cursorInfo);
00135    if (rc == TRUE)
00136    {
00137       HWND hwnd = cursorInfo.hwnd;
00138       Win32BaseWindow *wnd = Win32BaseWindow::GetWindowFromOS2Handle (hwnd);
00139       if (wnd)
00140       {
00141         if (wnd->isOwnDC())
00142         {
00143            HPS     hps  = wnd->getOwnDC();
00144            pDCData pHps = (pDCData)GpiQueryDCData(hps);
00145            if (!pHps)
00146            {
00147               RELEASE_WNDOBJ(wnd);
00148               SetLastError(ERROR_INTERNAL_ERROR);
00149               return FALSE;
00150            }
00151            GpiConvert (pHps->hps, CVTC_WORLD, CVTC_DEVICE, 1, &caretPos);
00152            xNew = caretPos.x;
00153 
00154            if (isYup (pHps))
00155               yNew = caretPos.y;
00156            else
00157               yNew = caretPos.y - cursorInfo.cy;
00158         }
00159         else
00160         {
00161            long height = wnd->getClientHeight();
00162            caretPos.y = height - caretPos.y;
00163            xNew = caretPos.x;
00164            yNew = caretPos.y - cursorInfo.cy;
00165         }
00166 
00167         hwndCaret = wnd->getWindowHandle();
00168         CaretPosX = x;
00169         CaretPosY = y;
00170         RELEASE_WNDOBJ(wnd);
00171 
00172         rc = WinCreateCursor (cursorInfo.hwnd, xNew, yNew, 0, 0, CURSOR_SETPOS, NULL);
00173       }
00174    }
00175    if (rc == FALSE)
00176    {
00177       SetLastError (ERROR_INVALID_PARAMETER);
00178       result = FALSE;
00179    }
00180 
00181    return (result);
00182 }
00183 
00184 BOOL WIN32API GetCaretPos (PPOINT pPoint)
00185 {
00186    CURSORINFO cursorInfo;
00187 
00188    dprintf(("USER32: GetCaretPos"));
00189 
00190    if (WinQueryCursorInfo (HWND_DESKTOP, &cursorInfo))
00191    {
00192       if (cursorInfo.hwnd != HWND_DESKTOP)
00193       {
00194          HPS hps   = NULLHANDLE;
00195          HWND hwnd = cursorInfo.hwnd;
00196          Win32BaseWindow *wnd = Win32BaseWindow::GetWindowFromOS2Handle (hwnd);
00197 
00198          if (wnd && wnd->isOwnDC())
00199             hps = wnd->getOwnDC();
00200 
00201          if(wnd == NULL) {
00202             dprintf(("ERROR: GetCaretPos: wnd == NULL!"));
00203             return FALSE;
00204          }
00205 
00206          POINTL caretPos = {cursorInfo.x,cursorInfo.y} ;
00207          if (hps) {
00208             GpiConvert (hps, CVTC_DEVICE, CVTC_WORLD, 1, &caretPos);
00209             cursorInfo.x = caretPos.x;
00210             cursorInfo.y = caretPos.y;
00211          } 
00212          else {
00213             long height   = wnd->getClientHeight();
00214             caretPos.y   += cursorInfo.cy;
00215             cursorInfo.y  = height - caretPos.y;
00216          }
00217          RELEASE_WNDOBJ(wnd);
00218       }
00219       pPoint->x = cursorInfo.x;
00220       pPoint->y = cursorInfo.y;
00221 
00222       return TRUE;
00223    }
00224    else
00225    {
00226       return FALSE;
00227    }
00228 }
00229 
00230 BOOL WIN32API ShowCaret (HWND hwnd)
00231 {
00232    BOOL   rc = FALSE;
00233 
00234    dprintf(("USER32:  ShowCaret %x", hwnd));
00235 
00236    CaretIsVisible++;
00237    if (CaretIsVisible == 1)
00238      rc = _ShowCaret (Win32ToOS2Handle (hwnd));
00239    else
00240      rc = TRUE;
00241 
00242    return (rc);
00243 }
00244 
00245 BOOL WIN32API HideCaret (HWND hwnd)
00246 {
00247    BOOL rc = FALSE;
00248 
00249    dprintf(("USER32:  HideCaret"));
00250 
00251    CaretIsVisible--;
00252    if (CaretIsVisible == 0)
00253      rc = _HideCaret (Win32ToOS2Handle (hwnd));
00254    else
00255      rc = TRUE;
00256 
00257    return (rc);
00258 }
00259 
00260 void recreateCaret (HWND hwndFocus)
00261 {
00262    CURSORINFO cursorInfo;
00263    INT x;
00264 
00265    if ((hwndFocus != 0) && (hwndCaret == hwndFocus) &&
00266        !WinQueryCursorInfo (HWND_DESKTOP, &cursorInfo))
00267    {
00268       dprintf(("recreateCaret for %x", hwndFocus));
00269 
00270       CreateCaret (hwndCaret, hbmCaret, CaretWidth, CaretHeight);
00271       SetCaretPos (CaretPosX, CaretPosY);
00272       if (CaretIsVisible > 0)
00273         _ShowCaret(Win32ToOS2Handle(hwndCaret));
00274    }
00275 }

Generated on Wed Jan 23 23:17:25 2002 for ODIN-user32 by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001