| 1 | /* $Id: caret.cpp,v 1.18 2001-06-09 14:50:16 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 | #pragma data_seg(_GLOBALDATA)
|
|---|
| 43 |
|
|---|
| 44 | static HWND hwndCaret = 0;
|
|---|
| 45 | static HBITMAP hbmCaret;
|
|---|
| 46 | static int CaretWidth, CaretHeight;
|
|---|
| 47 | static int CaretPosX, CaretPosY;
|
|---|
| 48 | static INT CaretIsVisible; //visible if > 0
|
|---|
| 49 |
|
|---|
| 50 | #pragma data_seg()
|
|---|
| 51 |
|
|---|
| 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 | wnd->SetFakeOpen32();
|
|---|
| 69 |
|
|---|
| 70 | rc = O32_CreateCaret (wnd->getOS2WindowHandle(), hBmp, width, height);
|
|---|
| 71 | if (rc)
|
|---|
| 72 | {
|
|---|
| 73 | hwndCaret = hwnd;
|
|---|
| 74 | hbmCaret = hBmp;
|
|---|
| 75 | CaretWidth = width;
|
|---|
| 76 | CaretHeight = height;
|
|---|
| 77 | CaretIsVisible = 0;
|
|---|
| 78 | }
|
|---|
| 79 |
|
|---|
| 80 | wnd->RemoveFakeOpen32();
|
|---|
| 81 | RELEASE_WNDOBJ(wnd);
|
|---|
| 82 | return (rc);
|
|---|
| 83 | }
|
|---|
| 84 | }
|
|---|
| 85 |
|
|---|
| 86 | BOOL WIN32API DestroyCaret()
|
|---|
| 87 | {
|
|---|
| 88 | BOOL rc;
|
|---|
| 89 |
|
|---|
| 90 | dprintf(("USER32: DestroyCaret"));
|
|---|
| 91 |
|
|---|
| 92 | hwndCaret = 0;
|
|---|
| 93 | hbmCaret = 0;
|
|---|
| 94 | CaretWidth = 0;
|
|---|
| 95 | CaretHeight = 0;
|
|---|
| 96 | CaretIsVisible = 0;
|
|---|
| 97 |
|
|---|
| 98 | rc = _DestroyCaret();
|
|---|
| 99 |
|
|---|
| 100 | return (rc);
|
|---|
| 101 | }
|
|---|
| 102 |
|
|---|
| 103 | BOOL WIN32API SetCaretBlinkTime (UINT mSecs)
|
|---|
| 104 | {
|
|---|
| 105 | BOOL rc;
|
|---|
| 106 |
|
|---|
| 107 | dprintf(("USER32: SetCaretBlinkTime %d ms", mSecs));
|
|---|
| 108 |
|
|---|
| 109 | rc = _SetCaretBlinkTime (mSecs);
|
|---|
| 110 |
|
|---|
| 111 | return (rc);
|
|---|
| 112 | }
|
|---|
| 113 |
|
|---|
| 114 | UINT WIN32API GetCaretBlinkTime()
|
|---|
| 115 | {
|
|---|
| 116 | UINT rc;
|
|---|
| 117 |
|
|---|
| 118 | dprintf(("USER32: GetCaretBlinkTime"));
|
|---|
| 119 |
|
|---|
| 120 | rc = _GetCaretBlinkTime();
|
|---|
| 121 | return (rc);
|
|---|
| 122 | }
|
|---|
| 123 |
|
|---|
| 124 | BOOL WIN32API SetCaretPos (int x, int y)
|
|---|
| 125 | {
|
|---|
| 126 | LONG xNew = 0, yNew = 0;
|
|---|
| 127 | BOOL result = TRUE;
|
|---|
| 128 | BOOL rc;
|
|---|
| 129 | CURSORINFO cursorInfo;
|
|---|
| 130 | POINTL caretPos = { x, y };
|
|---|
| 131 |
|
|---|
| 132 | dprintf(("USER32: SetCaretPos (%d,%d)", x, y));
|
|---|
| 133 |
|
|---|
| 134 | rc = WinQueryCursorInfo (HWND_DESKTOP, &cursorInfo);
|
|---|
| 135 | if (rc == TRUE)
|
|---|
| 136 | {
|
|---|
| 137 | HWND hwnd = cursorInfo.hwnd;
|
|---|
| 138 | Win32BaseWindow *wnd = Win32BaseWindow::GetWindowFromOS2Handle (hwnd);
|
|---|
| 139 | if (wnd)
|
|---|
| 140 | {
|
|---|
| 141 | if (wnd->isOwnDC())
|
|---|
| 142 | {
|
|---|
| 143 | HPS hps = wnd->getOwnDC();
|
|---|
| 144 | pDCData pHps = (pDCData)GpiQueryDCData(hps);
|
|---|
| 145 | if (!pHps)
|
|---|
| 146 | {
|
|---|
| 147 | RELEASE_WNDOBJ(wnd);
|
|---|
| 148 | SetLastError(ERROR_INTERNAL_ERROR);
|
|---|
| 149 | return FALSE;
|
|---|
| 150 | }
|
|---|
| 151 | GpiConvert (pHps->hps, CVTC_WORLD, CVTC_DEVICE, 1, &caretPos);
|
|---|
| 152 | xNew = caretPos.x;
|
|---|
| 153 |
|
|---|
| 154 | if (isYup (pHps))
|
|---|
| 155 | yNew = caretPos.y;
|
|---|
| 156 | else
|
|---|
| 157 | yNew = caretPos.y - cursorInfo.cy;
|
|---|
| 158 | }
|
|---|
| 159 | else
|
|---|
| 160 | {
|
|---|
| 161 | long height = wnd->getClientHeight();
|
|---|
| 162 | caretPos.y = height - caretPos.y;
|
|---|
| 163 | xNew = caretPos.x;
|
|---|
| 164 | yNew = caretPos.y - cursorInfo.cy;
|
|---|
| 165 | }
|
|---|
| 166 |
|
|---|
| 167 | hwndCaret = wnd->getWindowHandle();
|
|---|
| 168 | CaretPosX = x;
|
|---|
| 169 | CaretPosY = y;
|
|---|
| 170 | RELEASE_WNDOBJ(wnd);
|
|---|
| 171 |
|
|---|
| 172 | rc = WinCreateCursor (cursorInfo.hwnd, xNew, yNew, 0, 0, CURSOR_SETPOS, NULL);
|
|---|
| 173 | }
|
|---|
| 174 | }
|
|---|
| 175 | if (rc == FALSE)
|
|---|
| 176 | {
|
|---|
| 177 | SetLastError (ERROR_INVALID_PARAMETER);
|
|---|
| 178 | result = FALSE;
|
|---|
| 179 | }
|
|---|
| 180 |
|
|---|
| 181 | return (result);
|
|---|
| 182 | }
|
|---|
| 183 |
|
|---|
| 184 | BOOL WIN32API GetCaretPos (PPOINT pPoint)
|
|---|
| 185 | {
|
|---|
| 186 | CURSORINFO cursorInfo;
|
|---|
| 187 |
|
|---|
| 188 | dprintf(("USER32: GetCaretPos"));
|
|---|
| 189 |
|
|---|
| 190 | if (WinQueryCursorInfo (HWND_DESKTOP, &cursorInfo))
|
|---|
| 191 | {
|
|---|
| 192 | if (cursorInfo.hwnd != HWND_DESKTOP)
|
|---|
| 193 | {
|
|---|
| 194 | HPS hps = NULLHANDLE;
|
|---|
| 195 | HWND hwnd = cursorInfo.hwnd;
|
|---|
| 196 | Win32BaseWindow *wnd = Win32BaseWindow::GetWindowFromOS2Handle (hwnd);
|
|---|
| 197 |
|
|---|
| 198 | if (wnd && wnd->isOwnDC())
|
|---|
| 199 | hps = wnd->getOwnDC();
|
|---|
| 200 |
|
|---|
| 201 | if(wnd == NULL) {
|
|---|
| 202 | dprintf(("ERROR: GetCaretPos: wnd == NULL!"));
|
|---|
| 203 | return FALSE;
|
|---|
| 204 | }
|
|---|
| 205 |
|
|---|
| 206 | POINTL caretPos = {cursorInfo.x,cursorInfo.y} ;
|
|---|
| 207 | if (hps) {
|
|---|
| 208 | GpiConvert (hps, CVTC_DEVICE, CVTC_WORLD, 1, &caretPos);
|
|---|
| 209 | cursorInfo.x = caretPos.x;
|
|---|
| 210 | cursorInfo.y = caretPos.y;
|
|---|
| 211 | }
|
|---|
| 212 | else {
|
|---|
| 213 | long height = wnd->getClientHeight();
|
|---|
| 214 | caretPos.y += cursorInfo.cy;
|
|---|
| 215 | cursorInfo.y = height - caretPos.y;
|
|---|
| 216 | }
|
|---|
| 217 | RELEASE_WNDOBJ(wnd);
|
|---|
| 218 | }
|
|---|
| 219 | pPoint->x = cursorInfo.x;
|
|---|
| 220 | pPoint->y = cursorInfo.y;
|
|---|
| 221 |
|
|---|
| 222 | return TRUE;
|
|---|
| 223 | }
|
|---|
| 224 | else
|
|---|
| 225 | {
|
|---|
| 226 | return FALSE;
|
|---|
| 227 | }
|
|---|
| 228 | }
|
|---|
| 229 |
|
|---|
| 230 | BOOL WIN32API ShowCaret (HWND hwnd)
|
|---|
| 231 | {
|
|---|
| 232 | BOOL rc = FALSE;
|
|---|
| 233 |
|
|---|
| 234 | dprintf(("USER32: ShowCaret %x", hwnd));
|
|---|
| 235 |
|
|---|
| 236 | CaretIsVisible++;
|
|---|
| 237 | if (CaretIsVisible == 1)
|
|---|
| 238 | rc = _ShowCaret (Win32ToOS2Handle (hwnd));
|
|---|
| 239 | else
|
|---|
| 240 | rc = TRUE;
|
|---|
| 241 |
|
|---|
| 242 | return (rc);
|
|---|
| 243 | }
|
|---|
| 244 |
|
|---|
| 245 | BOOL WIN32API HideCaret (HWND hwnd)
|
|---|
| 246 | {
|
|---|
| 247 | BOOL rc = FALSE;
|
|---|
| 248 |
|
|---|
| 249 | dprintf(("USER32: HideCaret"));
|
|---|
| 250 |
|
|---|
| 251 | CaretIsVisible--;
|
|---|
| 252 | if (CaretIsVisible == 0)
|
|---|
| 253 | rc = _HideCaret (Win32ToOS2Handle (hwnd));
|
|---|
| 254 | else
|
|---|
| 255 | rc = TRUE;
|
|---|
| 256 |
|
|---|
| 257 | return (rc);
|
|---|
| 258 | }
|
|---|
| 259 |
|
|---|
| 260 | void recreateCaret (HWND hwndFocus)
|
|---|
| 261 | {
|
|---|
| 262 | CURSORINFO cursorInfo;
|
|---|
| 263 | INT x;
|
|---|
| 264 |
|
|---|
| 265 | if ((hwndFocus != 0) && (hwndCaret == hwndFocus) &&
|
|---|
| 266 | !WinQueryCursorInfo (HWND_DESKTOP, &cursorInfo))
|
|---|
| 267 | {
|
|---|
| 268 | dprintf(("recreateCaret for %x", hwndFocus));
|
|---|
| 269 |
|
|---|
| 270 | CreateCaret (hwndCaret, hbmCaret, CaretWidth, CaretHeight);
|
|---|
| 271 | SetCaretPos (CaretPosX, CaretPosY);
|
|---|
| 272 | if (CaretIsVisible > 0)
|
|---|
| 273 | _ShowCaret(Win32ToOS2Handle(hwndCaret));
|
|---|
| 274 | }
|
|---|
| 275 | }
|
|---|