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