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