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