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