| 1 | /* $Id: caret.cpp,v 1.20 2004-01-11 12:03:13 sandervl Exp $ */ | 
|---|
| 2 |  | 
|---|
| 3 | /* | 
|---|
| 4 | * Caret functions for USER32 | 
|---|
| 5 | * | 
|---|
| 6 | * | 
|---|
| 7 | * TODO: Getting height of window instead of checking whether it needs | 
|---|
| 8 | *       to be window or client appears to be wrong.... | 
|---|
| 9 | * | 
|---|
| 10 | * Project Odin Software License can be found in LICENSE.TXT | 
|---|
| 11 | * | 
|---|
| 12 | */ | 
|---|
| 13 |  | 
|---|
| 14 | #define INCL_WIN | 
|---|
| 15 | #define INCL_GPI | 
|---|
| 16 | #include <os2wrap.h> | 
|---|
| 17 | #include <os2sel.h> | 
|---|
| 18 | #include <stdlib.h> | 
|---|
| 19 | #include <win32type.h> | 
|---|
| 20 | #include <win32api.h> | 
|---|
| 21 | #include <winconst.h> | 
|---|
| 22 | #include <winuser32.h> | 
|---|
| 23 | #include <wprocess.h> | 
|---|
| 24 | #include <misc.h> | 
|---|
| 25 | #include "win32wbase.h" | 
|---|
| 26 | #include "oslibwin.h" | 
|---|
| 27 | #include <dcdata.h> | 
|---|
| 28 | #define INCLUDED_BY_DC | 
|---|
| 29 | #include "dc.h" | 
|---|
| 30 | #include "caret.h" | 
|---|
| 31 |  | 
|---|
| 32 | #define DBG_LOCALLOG    DBG_caret | 
|---|
| 33 | #include "dbglocal.h" | 
|---|
| 34 |  | 
|---|
| 35 | #undef SEVERITY_ERROR | 
|---|
| 36 | #include <winerror.h> | 
|---|
| 37 |  | 
|---|
| 38 | #ifndef OPEN32API | 
|---|
| 39 | #define OPEN32API _System | 
|---|
| 40 | #endif | 
|---|
| 41 |  | 
|---|
| 42 | // | 
|---|
| 43 | // Global DLL Data (keep it in sync with globaldata.asm!) | 
|---|
| 44 | // | 
|---|
| 45 | extern HWND hwndCaret; // = 0 | 
|---|
| 46 | extern HBITMAP hbmCaret; // = 0 | 
|---|
| 47 | extern int CaretWidth, CaretHeight; // = 0 | 
|---|
| 48 | extern int CaretPosX, CaretPosY; // = 0 | 
|---|
| 49 | extern INT CaretIsVisible; // =0, visible if > 0 | 
|---|
| 50 |  | 
|---|
| 51 | extern "C" { | 
|---|
| 52 |  | 
|---|
| 53 | BOOL WIN32API CreateCaret (HWND hwnd, HBITMAP hBmp, int width, int height) | 
|---|
| 54 | { | 
|---|
| 55 | dprintf(("USER32:  CreateCaret %x", hwnd)); | 
|---|
| 56 |  | 
|---|
| 57 | if (hwnd == NULLHANDLE) | 
|---|
| 58 | { | 
|---|
| 59 | return FALSE; | 
|---|
| 60 | } | 
|---|
| 61 | else | 
|---|
| 62 | { | 
|---|
| 63 | BOOL rc; | 
|---|
| 64 | Win32BaseWindow *wnd = Win32BaseWindow::GetWindowFromHandle(hwnd); | 
|---|
| 65 |  | 
|---|
| 66 | if (!wnd) return (FALSE); | 
|---|
| 67 |  | 
|---|
| 68 | rc = O32_CreateCaret (wnd->getOS2WindowHandle(), hBmp, width, height); | 
|---|
| 69 | if (rc) | 
|---|
| 70 | { | 
|---|
| 71 | hwndCaret      = hwnd; | 
|---|
| 72 | hbmCaret       = hBmp; | 
|---|
| 73 | CaretWidth     = width; | 
|---|
| 74 | CaretHeight    = height; | 
|---|
| 75 | CaretIsVisible = 0; | 
|---|
| 76 | } | 
|---|
| 77 |  | 
|---|
| 78 | RELEASE_WNDOBJ(wnd); | 
|---|
| 79 | return (rc); | 
|---|
| 80 | } | 
|---|
| 81 | } | 
|---|
| 82 |  | 
|---|
| 83 | BOOL WIN32API DestroyCaret() | 
|---|
| 84 | { | 
|---|
| 85 | BOOL rc; | 
|---|
| 86 |  | 
|---|
| 87 | dprintf(("USER32:  DestroyCaret")); | 
|---|
| 88 |  | 
|---|
| 89 | hwndCaret      = 0; | 
|---|
| 90 | hbmCaret       = 0; | 
|---|
| 91 | CaretWidth     = 0; | 
|---|
| 92 | CaretHeight    = 0; | 
|---|
| 93 | CaretIsVisible = 0; | 
|---|
| 94 |  | 
|---|
| 95 | rc = _DestroyCaret(); | 
|---|
| 96 |  | 
|---|
| 97 | return (rc); | 
|---|
| 98 | } | 
|---|
| 99 |  | 
|---|
| 100 | BOOL WIN32API SetCaretBlinkTime (UINT mSecs) | 
|---|
| 101 | { | 
|---|
| 102 | BOOL rc; | 
|---|
| 103 |  | 
|---|
| 104 | dprintf(("USER32: SetCaretBlinkTime %d ms", mSecs)); | 
|---|
| 105 |  | 
|---|
| 106 | rc = _SetCaretBlinkTime (mSecs); | 
|---|
| 107 |  | 
|---|
| 108 | return (rc); | 
|---|
| 109 | } | 
|---|
| 110 |  | 
|---|
| 111 | UINT WIN32API GetCaretBlinkTime() | 
|---|
| 112 | { | 
|---|
| 113 | UINT rc; | 
|---|
| 114 |  | 
|---|
| 115 | dprintf(("USER32:  GetCaretBlinkTime")); | 
|---|
| 116 |  | 
|---|
| 117 | rc = _GetCaretBlinkTime(); | 
|---|
| 118 | return (rc); | 
|---|
| 119 | } | 
|---|
| 120 |  | 
|---|
| 121 | /* | 
|---|
| 122 | * The SetCaretPos function moves the caret to the specified coordinates. If | 
|---|
| 123 | * the window that owns the caret was created with the CS_OWNDC class style, | 
|---|
| 124 | * then the specified coordinates are subject to the mapping mode of the device | 
|---|
| 125 | * context associated with that window. | 
|---|
| 126 | * | 
|---|
| 127 | */ | 
|---|
| 128 | BOOL WIN32API SetCaretPos (int x, int y) | 
|---|
| 129 | { | 
|---|
| 130 | LONG       xNew = 0, yNew = 0; | 
|---|
| 131 | BOOL       result = TRUE; | 
|---|
| 132 | BOOL       rc; | 
|---|
| 133 | CURSORINFO cursorInfo; | 
|---|
| 134 | POINTL     caretPos = { x, y }; | 
|---|
| 135 |  | 
|---|
| 136 | dprintf(("USER32: SetCaretPos (%d,%d)", x, y)); | 
|---|
| 137 |  | 
|---|
| 138 | rc = WinQueryCursorInfo (HWND_DESKTOP, &cursorInfo); | 
|---|
| 139 | if (rc == TRUE) | 
|---|
| 140 | { | 
|---|
| 141 | HWND hwnd = cursorInfo.hwnd; | 
|---|
| 142 | Win32BaseWindow *wnd = Win32BaseWindow::GetWindowFromOS2Handle (hwnd); | 
|---|
| 143 | if (wnd) | 
|---|
| 144 | { | 
|---|
| 145 | if (wnd->isOwnDC()) | 
|---|
| 146 | { | 
|---|
| 147 | HPS     hps  = wnd->getOwnDC(); | 
|---|
| 148 | pDCData pHps = (pDCData)GpiQueryDCData(hps); | 
|---|
| 149 | if (!pHps) | 
|---|
| 150 | { | 
|---|
| 151 | RELEASE_WNDOBJ(wnd); | 
|---|
| 152 | SetLastError(ERROR_INTERNAL_ERROR); | 
|---|
| 153 | return FALSE; | 
|---|
| 154 | } | 
|---|
| 155 | GpiConvert (pHps->hps, CVTC_WORLD, CVTC_DEVICE, 1, &caretPos); | 
|---|
| 156 | xNew = caretPos.x; | 
|---|
| 157 |  | 
|---|
| 158 | if (isYup (pHps)) | 
|---|
| 159 | yNew = caretPos.y; | 
|---|
| 160 | else | 
|---|
| 161 | yNew = caretPos.y - cursorInfo.cy; | 
|---|
| 162 | } | 
|---|
| 163 | else | 
|---|
| 164 | { | 
|---|
| 165 | long height = wnd->getClientHeight(); | 
|---|
| 166 | caretPos.y = height - caretPos.y; | 
|---|
| 167 | xNew = caretPos.x; | 
|---|
| 168 | yNew = caretPos.y - cursorInfo.cy; | 
|---|
| 169 | } | 
|---|
| 170 |  | 
|---|
| 171 | hwndCaret = wnd->getWindowHandle(); | 
|---|
| 172 | CaretPosX = x; | 
|---|
| 173 | CaretPosY = y; | 
|---|
| 174 | RELEASE_WNDOBJ(wnd); | 
|---|
| 175 |  | 
|---|
| 176 | rc = WinCreateCursor (cursorInfo.hwnd, xNew, yNew, 0, 0, CURSOR_SETPOS, NULL); | 
|---|
| 177 | } | 
|---|
| 178 | } | 
|---|
| 179 | if (rc == FALSE) | 
|---|
| 180 | { | 
|---|
| 181 | SetLastError (ERROR_INVALID_PARAMETER); | 
|---|
| 182 | result = FALSE; | 
|---|
| 183 | } | 
|---|
| 184 |  | 
|---|
| 185 | return (result); | 
|---|
| 186 | } | 
|---|
| 187 |  | 
|---|
| 188 | BOOL WIN32API GetCaretPos (PPOINT pPoint) | 
|---|
| 189 | { | 
|---|
| 190 | CURSORINFO cursorInfo; | 
|---|
| 191 |  | 
|---|
| 192 | dprintf(("USER32: GetCaretPos")); | 
|---|
| 193 |  | 
|---|
| 194 | if (WinQueryCursorInfo (HWND_DESKTOP, &cursorInfo)) | 
|---|
| 195 | { | 
|---|
| 196 | if (cursorInfo.hwnd != HWND_DESKTOP) | 
|---|
| 197 | { | 
|---|
| 198 | HPS hps   = NULLHANDLE; | 
|---|
| 199 | HWND hwnd = cursorInfo.hwnd; | 
|---|
| 200 | Win32BaseWindow *wnd = Win32BaseWindow::GetWindowFromOS2Handle (hwnd); | 
|---|
| 201 |  | 
|---|
| 202 | if (wnd && wnd->isOwnDC()) | 
|---|
| 203 | hps = wnd->getOwnDC(); | 
|---|
| 204 |  | 
|---|
| 205 | if(wnd == NULL) { | 
|---|
| 206 | dprintf(("ERROR: GetCaretPos: wnd == NULL!")); | 
|---|
| 207 | return FALSE; | 
|---|
| 208 | } | 
|---|
| 209 |  | 
|---|
| 210 | POINTL caretPos = {cursorInfo.x,cursorInfo.y} ; | 
|---|
| 211 | if (hps) { | 
|---|
| 212 | GpiConvert (hps, CVTC_DEVICE, CVTC_WORLD, 1, &caretPos); | 
|---|
| 213 | cursorInfo.x = caretPos.x; | 
|---|
| 214 | cursorInfo.y = caretPos.y; | 
|---|
| 215 | } | 
|---|
| 216 | else { | 
|---|
| 217 | long height   = wnd->getClientHeight(); | 
|---|
| 218 | caretPos.y   += cursorInfo.cy; | 
|---|
| 219 | cursorInfo.y  = height - caretPos.y; | 
|---|
| 220 | } | 
|---|
| 221 | RELEASE_WNDOBJ(wnd); | 
|---|
| 222 | } | 
|---|
| 223 | pPoint->x = cursorInfo.x; | 
|---|
| 224 | pPoint->y = cursorInfo.y; | 
|---|
| 225 |  | 
|---|
| 226 | return TRUE; | 
|---|
| 227 | } | 
|---|
| 228 | else | 
|---|
| 229 | { | 
|---|
| 230 | return FALSE; | 
|---|
| 231 | } | 
|---|
| 232 | } | 
|---|
| 233 |  | 
|---|
| 234 | BOOL WIN32API ShowCaret (HWND hwnd) | 
|---|
| 235 | { | 
|---|
| 236 | BOOL   rc = FALSE; | 
|---|
| 237 |  | 
|---|
| 238 | dprintf(("USER32:  ShowCaret %x", hwnd)); | 
|---|
| 239 |  | 
|---|
| 240 | CaretIsVisible++; | 
|---|
| 241 | if (CaretIsVisible == 1) | 
|---|
| 242 | rc = _ShowCaret (Win32ToOS2Handle (hwnd)); | 
|---|
| 243 | else | 
|---|
| 244 | rc = TRUE; | 
|---|
| 245 |  | 
|---|
| 246 | return (rc); | 
|---|
| 247 | } | 
|---|
| 248 |  | 
|---|
| 249 | BOOL WIN32API HideCaret (HWND hwnd) | 
|---|
| 250 | { | 
|---|
| 251 | BOOL rc = FALSE; | 
|---|
| 252 |  | 
|---|
| 253 | dprintf(("USER32:  HideCaret")); | 
|---|
| 254 |  | 
|---|
| 255 | CaretIsVisible--; | 
|---|
| 256 | if (CaretIsVisible == 0) | 
|---|
| 257 | rc = _HideCaret (Win32ToOS2Handle (hwnd)); | 
|---|
| 258 | else | 
|---|
| 259 | rc = TRUE; | 
|---|
| 260 |  | 
|---|
| 261 | return (rc); | 
|---|
| 262 | } | 
|---|
| 263 |  | 
|---|
| 264 | } // extern "C" | 
|---|
| 265 |  | 
|---|
| 266 | void recreateCaret (HWND hwndFocus) | 
|---|
| 267 | { | 
|---|
| 268 | CURSORINFO cursorInfo; | 
|---|
| 269 | INT x; | 
|---|
| 270 |  | 
|---|
| 271 | if ((hwndFocus != 0) && (hwndCaret == hwndFocus) && | 
|---|
| 272 | !WinQueryCursorInfo (HWND_DESKTOP, &cursorInfo)) | 
|---|
| 273 | { | 
|---|
| 274 | dprintf(("recreateCaret for %x", hwndFocus)); | 
|---|
| 275 |  | 
|---|
| 276 | CreateCaret (hwndCaret, hbmCaret, CaretWidth, CaretHeight); | 
|---|
| 277 | SetCaretPos (CaretPosX, CaretPosY); | 
|---|
| 278 | if (CaretIsVisible > 0) | 
|---|
| 279 | _ShowCaret(Win32ToOS2Handle(hwndCaret)); | 
|---|
| 280 | } | 
|---|
| 281 | } | 
|---|