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