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