source: trunk/src/user32/caret.cpp@ 4825

Last change on this file since 4825 was 4825, checked in by sandervl, 25 years ago

hook, mdi & focus fixes

File size: 5.6 KB
Line 
1/* $Id: caret.cpp,v 1.14 2000-12-17 15:04:09 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 <wprocess.h>
23#include <misc.h>
24#include <win32wbase.h>
25#include "oslibwin.h"
26#include <dcdata.h>
27#define INCLUDED_BY_DC
28#include "dc.h"
29#include "caret.h"
30
31#define DBG_LOCALLOG DBG_caret
32#include "dbglocal.h"
33
34#undef SEVERITY_ERROR
35#include <winerror.h>
36
37#ifndef OPEN32API
38#define OPEN32API _System
39#endif
40
41#pragma data_seg(_GLOBALDATA)
42
43static HWND hwndCaret = 0;
44static HBITMAP hbmCaret;
45static int CaretWidth, CaretHeight;
46static int CaretPosX, CaretPosY;
47static INT CaretIsVisible; //visible if > 0
48
49#pragma data_seg()
50
51
52BOOL WIN32API CreateCaret (HWND hwnd, HBITMAP hBmp, int width, int height)
53{
54 dprintf(("USER32: CreateCaret %x", hwnd));
55
56 if (hwnd == NULLHANDLE)
57 {
58 return FALSE;
59 }
60 else
61 {
62 BOOL rc;
63 Win32BaseWindow *wnd = Win32BaseWindow::GetWindowFromHandle(hwnd);
64
65 if (!wnd) return (FALSE);
66
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 CaretIsVisible = 0;
77 }
78
79 wnd->RemoveFakeOpen32();
80 return (rc);
81 }
82}
83
84BOOL 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
101BOOL 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
112UINT WIN32API GetCaretBlinkTime()
113{
114 UINT rc;
115
116 dprintf(("USER32: GetCaretBlinkTime"));
117
118 rc = _GetCaretBlinkTime();
119 return (rc);
120}
121
122BOOL WIN32API SetCaretPos (int x, int y)
123{
124 LONG xNew = 0, yNew = 0;
125 BOOL result = TRUE;
126 BOOL rc;
127 CURSORINFO cursorInfo;
128 POINTL caretPos = { x, y };
129
130 dprintf(("USER32: SetCaretPos (%d,%d)", x, y));
131
132 rc = WinQueryCursorInfo (HWND_DESKTOP, &cursorInfo);
133 if (rc == TRUE)
134 {
135 HWND hwnd = cursorInfo.hwnd;
136 Win32BaseWindow *wnd = Win32BaseWindow::GetWindowFromOS2Handle (hwnd);
137 if (wnd)
138 {
139 if (wnd->isOwnDC())
140 {
141 HPS hps = wnd->getOwnDC();
142 pDCData pHps = (pDCData)GpiQueryDCData(hps);
143 if (!pHps)
144 {
145 SetLastError(ERROR_INTERNAL_ERROR);
146 return FALSE;
147 }
148 GpiConvert (pHps->hps, CVTC_WORLD, CVTC_DEVICE, 1, &caretPos);
149 xNew = caretPos.x;
150
151 if (isYup (pHps))
152 yNew = caretPos.y;
153 else
154 yNew = caretPos.y - cursorInfo.cy;
155 }
156 else
157 {
158 long height = wnd->getWindowHeight();
159 caretPos.y = height - caretPos.y - 1;
160 xNew = caretPos.x;
161 yNew = caretPos.y - cursorInfo.cy;
162 }
163
164 hwndCaret = wnd->getWindowHandle();
165 CaretPosX = x;
166 CaretPosY = y;
167
168 rc = WinCreateCursor (cursorInfo.hwnd, xNew, yNew, 0, 0, CURSOR_SETPOS, NULL);
169 }
170 }
171 if (rc == FALSE)
172 {
173 SetLastError (ERROR_INVALID_PARAMETER);
174 result = FALSE;
175 }
176
177 return (result);
178}
179
180BOOL WIN32API GetCaretPos (PPOINT pPoint)
181{
182 CURSORINFO cursorInfo;
183
184 dprintf(("USER32: GetCaretPos"));
185
186 if (WinQueryCursorInfo (HWND_DESKTOP, &cursorInfo))
187 {
188 if (cursorInfo.hwnd != HWND_DESKTOP)
189 {
190 HPS hps = NULLHANDLE;
191 HWND hwnd = cursorInfo.hwnd;
192 Win32BaseWindow *wnd = Win32BaseWindow::GetWindowFromOS2Handle (hwnd);
193
194 if (wnd && wnd->isOwnDC())
195 hps = wnd->getOwnDC();
196 else
197 {
198 return FALSE;
199 }
200
201 POINTL caretPos = {cursorInfo.x,cursorInfo.y} ;
202 if (hps) {
203 GpiConvert (hps, CVTC_DEVICE, CVTC_WORLD, 1, &caretPos);
204 cursorInfo.x = caretPos.x;
205 cursorInfo.y = caretPos.y;
206 }
207 else {
208 long height = wnd->getWindowHeight();
209 caretPos.y += cursorInfo.cy;
210 cursorInfo.y = height - caretPos.y - 1;
211 }
212 }
213 pPoint->x = cursorInfo.x;
214 pPoint->y = cursorInfo.y;
215
216 return TRUE;
217 }
218 else
219 {
220 return FALSE;
221 }
222}
223
224BOOL WIN32API ShowCaret (HWND hwnd)
225{
226 BOOL rc = FALSE;
227
228 dprintf(("USER32: ShowCaret %x", hwnd));
229
230 CaretIsVisible++;
231 if (CaretIsVisible == 1)
232 rc = _ShowCaret (Win32BaseWindow::Win32ToOS2Handle (hwnd));
233 else
234 rc = TRUE;
235
236 return (rc);
237}
238
239BOOL WIN32API HideCaret (HWND hwnd)
240{
241 BOOL rc = FALSE;
242
243 dprintf(("USER32: HideCaret"));
244
245 CaretIsVisible--;
246 if (CaretIsVisible == 0)
247 rc = _HideCaret (Win32BaseWindow::Win32ToOS2Handle (hwnd));
248 else
249 rc = TRUE;
250
251 return (rc);
252}
253
254void recreateCaret (HWND hwndFocus)
255{
256 CURSORINFO cursorInfo;
257 INT x;
258
259 if ((hwndFocus != 0) && (hwndCaret == hwndFocus) &&
260 !WinQueryCursorInfo (HWND_DESKTOP, &cursorInfo))
261 {
262 dprintf(("recreateCaret for %x", hwndFocus));
263
264 CreateCaret (hwndCaret, hbmCaret, CaretWidth, CaretHeight);
265 SetCaretPos (CaretPosX, CaretPosY);
266 if (CaretIsVisible > 0)
267 _ShowCaret(Win32BaseWindow::Win32ToOS2Handle(hwndCaret));
268 }
269}
Note: See TracBrowser for help on using the repository browser.