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