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

Last change on this file since 10367 was 9217, checked in by sandervl, 23 years ago

fixed caret bug in edit control; removed obsolete code in createcaret

File size: 5.7 KB
Line 
1/* $Id: caret.cpp,v 1.19 2002-09-06 12:31:40 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
44static HWND hwndCaret = 0;
45static HBITMAP hbmCaret;
46static int CaretWidth, CaretHeight;
47static int CaretPosX, CaretPosY;
48static INT CaretIsVisible; //visible if > 0
49
50#pragma data_seg()
51
52
53BOOL WIN32API CreateCaret (HWND hwnd, HBITMAP hBmp, int width, int height)
54{
55 dprintf(("USER32: CreateCaret %x", hwnd));
56
57 if (hwnd == NULLHANDLE)
58 {
59 return FALSE;
60 }
61 else
62 {
63 BOOL rc;
64 Win32BaseWindow *wnd = Win32BaseWindow::GetWindowFromHandle(hwnd);
65
66 if (!wnd) return (FALSE);
67
68 rc = O32_CreateCaret (wnd->getOS2WindowHandle(), hBmp, width, height);
69 if (rc)
70 {
71 hwndCaret = hwnd;
72 hbmCaret = hBmp;
73 CaretWidth = width;
74 CaretHeight = height;
75 CaretIsVisible = 0;
76 }
77
78 RELEASE_WNDOBJ(wnd);
79 return (rc);
80 }
81}
82
83BOOL WIN32API DestroyCaret()
84{
85 BOOL rc;
86
87 dprintf(("USER32: DestroyCaret"));
88
89 hwndCaret = 0;
90 hbmCaret = 0;
91 CaretWidth = 0;
92 CaretHeight = 0;
93 CaretIsVisible = 0;
94
95 rc = _DestroyCaret();
96
97 return (rc);
98}
99
100BOOL WIN32API SetCaretBlinkTime (UINT mSecs)
101{
102 BOOL rc;
103
104 dprintf(("USER32: SetCaretBlinkTime %d ms", mSecs));
105
106 rc = _SetCaretBlinkTime (mSecs);
107
108 return (rc);
109}
110
111UINT WIN32API GetCaretBlinkTime()
112{
113 UINT rc;
114
115 dprintf(("USER32: GetCaretBlinkTime"));
116
117 rc = _GetCaretBlinkTime();
118 return (rc);
119}
120
121BOOL WIN32API SetCaretPos (int x, int y)
122{
123 LONG xNew = 0, yNew = 0;
124 BOOL result = TRUE;
125 BOOL rc;
126 CURSORINFO cursorInfo;
127 POINTL caretPos = { x, y };
128
129 dprintf(("USER32: SetCaretPos (%d,%d)", x, y));
130
131 rc = WinQueryCursorInfo (HWND_DESKTOP, &cursorInfo);
132 if (rc == TRUE)
133 {
134 HWND hwnd = cursorInfo.hwnd;
135 Win32BaseWindow *wnd = Win32BaseWindow::GetWindowFromOS2Handle (hwnd);
136 if (wnd)
137 {
138 if (wnd->isOwnDC())
139 {
140 HPS hps = wnd->getOwnDC();
141 pDCData pHps = (pDCData)GpiQueryDCData(hps);
142 if (!pHps)
143 {
144 RELEASE_WNDOBJ(wnd);
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->getClientHeight();
159 caretPos.y = height - caretPos.y;
160 xNew = caretPos.x;
161 yNew = caretPos.y - cursorInfo.cy;
162 }
163
164 hwndCaret = wnd->getWindowHandle();
165 CaretPosX = x;
166 CaretPosY = y;
167 RELEASE_WNDOBJ(wnd);
168
169 rc = WinCreateCursor (cursorInfo.hwnd, xNew, yNew, 0, 0, CURSOR_SETPOS, NULL);
170 }
171 }
172 if (rc == FALSE)
173 {
174 SetLastError (ERROR_INVALID_PARAMETER);
175 result = FALSE;
176 }
177
178 return (result);
179}
180
181BOOL WIN32API GetCaretPos (PPOINT pPoint)
182{
183 CURSORINFO cursorInfo;
184
185 dprintf(("USER32: GetCaretPos"));
186
187 if (WinQueryCursorInfo (HWND_DESKTOP, &cursorInfo))
188 {
189 if (cursorInfo.hwnd != HWND_DESKTOP)
190 {
191 HPS hps = NULLHANDLE;
192 HWND hwnd = cursorInfo.hwnd;
193 Win32BaseWindow *wnd = Win32BaseWindow::GetWindowFromOS2Handle (hwnd);
194
195 if (wnd && wnd->isOwnDC())
196 hps = wnd->getOwnDC();
197
198 if(wnd == NULL) {
199 dprintf(("ERROR: GetCaretPos: wnd == NULL!"));
200 return FALSE;
201 }
202
203 POINTL caretPos = {cursorInfo.x,cursorInfo.y} ;
204 if (hps) {
205 GpiConvert (hps, CVTC_DEVICE, CVTC_WORLD, 1, &caretPos);
206 cursorInfo.x = caretPos.x;
207 cursorInfo.y = caretPos.y;
208 }
209 else {
210 long height = wnd->getClientHeight();
211 caretPos.y += cursorInfo.cy;
212 cursorInfo.y = height - caretPos.y;
213 }
214 RELEASE_WNDOBJ(wnd);
215 }
216 pPoint->x = cursorInfo.x;
217 pPoint->y = cursorInfo.y;
218
219 return TRUE;
220 }
221 else
222 {
223 return FALSE;
224 }
225}
226
227BOOL WIN32API ShowCaret (HWND hwnd)
228{
229 BOOL rc = FALSE;
230
231 dprintf(("USER32: ShowCaret %x", hwnd));
232
233 CaretIsVisible++;
234 if (CaretIsVisible == 1)
235 rc = _ShowCaret (Win32ToOS2Handle (hwnd));
236 else
237 rc = TRUE;
238
239 return (rc);
240}
241
242BOOL WIN32API HideCaret (HWND hwnd)
243{
244 BOOL rc = FALSE;
245
246 dprintf(("USER32: HideCaret"));
247
248 CaretIsVisible--;
249 if (CaretIsVisible == 0)
250 rc = _HideCaret (Win32ToOS2Handle (hwnd));
251 else
252 rc = TRUE;
253
254 return (rc);
255}
256
257void recreateCaret (HWND hwndFocus)
258{
259 CURSORINFO cursorInfo;
260 INT x;
261
262 if ((hwndFocus != 0) && (hwndCaret == hwndFocus) &&
263 !WinQueryCursorInfo (HWND_DESKTOP, &cursorInfo))
264 {
265 dprintf(("recreateCaret for %x", hwndFocus));
266
267 CreateCaret (hwndCaret, hbmCaret, CaretWidth, CaretHeight);
268 SetCaretPos (CaretPosX, CaretPosY);
269 if (CaretIsVisible > 0)
270 _ShowCaret(Win32ToOS2Handle(hwndCaret));
271 }
272}
Note: See TracBrowser for help on using the repository browser.