- Silence some debug messages
[reactos.git] / reactos / lib / user32 / windows / cursor.c
1 /*
2 * ReactOS kernel
3 * Copyright (C) 1998, 1999, 2000, 2001 ReactOS Team
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19 /* $Id$
20 *
21 * PROJECT: ReactOS user32.dll
22 * FILE: lib/user32/windows/cursor.c
23 * PURPOSE: Cursor
24 * PROGRAMMER: Casper S. Hornstrup (chorns@users.sourceforge.net)
25 * UPDATE HISTORY:
26 * 09-05-2001 CSH Created
27 */
28
29 /* INCLUDES ******************************************************************/
30
31 #include <user32.h>
32 #define NDEBUG
33 #include <debug.h>
34
35 #undef CopyCursor
36
37 HBITMAP
38 CopyBitmap(HBITMAP bmp);
39
40 /* INTERNAL ******************************************************************/
41
42 /* This callback routine is called directly after switching to gui mode */
43 NTSTATUS STDCALL
44 User32SetupDefaultCursors(PVOID Arguments, ULONG ArgumentLength)
45 {
46 BOOL *DefaultCursor = (BOOL*)Arguments;
47 LRESULT Result = TRUE;
48
49 if(*DefaultCursor)
50 {
51 /* set default cursor */
52 SetCursor(LoadCursorW(0, (LPCWSTR)IDC_ARROW));
53 }
54 else
55 {
56 /* FIXME load system cursor scheme */
57 SetCursor(0);
58 SetCursor(LoadCursorW(0, (LPCWSTR)IDC_ARROW));
59 }
60
61 return(ZwCallbackReturn(&Result, sizeof(LRESULT), STATUS_SUCCESS));
62 }
63
64 /* FUNCTIONS *****************************************************************/
65
66
67 /*
68 * @implemented
69 */
70 HCURSOR STDCALL
71 CopyCursor(HCURSOR pcur)
72 {
73 ICONINFO IconInfo;
74
75 if(NtUserGetCursorIconInfo((HANDLE)pcur, &IconInfo))
76 {
77 return (HCURSOR)NtUserCreateCursorIconHandle(&IconInfo, FALSE);
78 }
79 return (HCURSOR)0;
80 }
81
82 /*
83 * @implemented
84 */
85 HCURSOR STDCALL
86 CreateCursor(HINSTANCE hInst,
87 int xHotSpot,
88 int yHotSpot,
89 int nWidth,
90 int nHeight,
91 CONST VOID *pvANDPlane,
92 CONST VOID *pvXORPlane)
93 {
94 ICONINFO IconInfo;
95 BYTE BitmapInfoBuffer[sizeof(BITMAPINFOHEADER) + 2 * sizeof(RGBQUAD)];
96 BITMAPINFO *bwBIH = (BITMAPINFO *)BitmapInfoBuffer;
97 HDC hScreenDc;
98
99 hScreenDc = CreateCompatibleDC(NULL);
100 if (hScreenDc == NULL)
101 return NULL;
102
103 bwBIH->bmiHeader.biBitCount = 1;
104 bwBIH->bmiHeader.biWidth = nWidth;
105 bwBIH->bmiHeader.biHeight = -nHeight * 2;
106 bwBIH->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
107 bwBIH->bmiHeader.biPlanes = 1;
108 bwBIH->bmiHeader.biSizeImage = 0;
109 bwBIH->bmiHeader.biCompression = BI_RGB;
110 bwBIH->bmiHeader.biClrImportant = 0;
111 bwBIH->bmiHeader.biClrUsed = 0;
112 bwBIH->bmiHeader.biXPelsPerMeter = 0;
113 bwBIH->bmiHeader.biYPelsPerMeter = 0;
114
115 bwBIH->bmiColors[0].rgbBlue = 0;
116 bwBIH->bmiColors[0].rgbGreen = 0;
117 bwBIH->bmiColors[0].rgbRed = 0;
118 bwBIH->bmiColors[0].rgbReserved = 0;
119
120 bwBIH->bmiColors[1].rgbBlue = 0xff;
121 bwBIH->bmiColors[1].rgbGreen = 0xff;
122 bwBIH->bmiColors[1].rgbRed = 0xff;
123 bwBIH->bmiColors[1].rgbReserved = 0;
124
125 IconInfo.hbmMask = CreateDIBitmap(hScreenDc, &bwBIH->bmiHeader, 0,
126 NULL, bwBIH, DIB_RGB_COLORS);
127 if (IconInfo.hbmMask)
128 {
129 SetDIBits(hScreenDc, IconInfo.hbmMask, 0, nHeight,
130 pvXORPlane, bwBIH, DIB_RGB_COLORS);
131 SetDIBits(hScreenDc, IconInfo.hbmMask, nHeight, nHeight,
132 pvANDPlane, bwBIH, DIB_RGB_COLORS);
133 }
134 else
135 {
136 return NULL;
137 }
138
139 DeleteDC(hScreenDc);
140
141 IconInfo.fIcon = FALSE;
142 IconInfo.xHotspot = xHotSpot;
143 IconInfo.yHotspot = yHotSpot;
144 IconInfo.hbmColor = 0;
145
146 return (HCURSOR)NtUserCreateCursorIconHandle(&IconInfo, FALSE);
147 }
148
149
150 /*
151 * @implemented
152 */
153 BOOL STDCALL
154 DestroyCursor(HCURSOR hCursor)
155 {
156 return (BOOL)NtUserDestroyCursorIcon((HANDLE)hCursor, 0);
157 }
158
159
160 /*
161 * @implemented
162 */
163 BOOL STDCALL
164 GetClipCursor(LPRECT lpRect)
165 {
166 return NtUserGetClipCursor(lpRect);
167 }
168
169
170 /*
171 * @implemented
172 */
173 HCURSOR STDCALL
174 GetCursor(VOID)
175 {
176 CURSORINFO ci;
177 ci.cbSize = sizeof(CURSORINFO);
178 if(NtUserGetCursorInfo(&ci))
179 return ci.hCursor;
180 else
181 return (HCURSOR)0;
182 }
183
184
185 /*
186 * @implemented
187 */
188 BOOL STDCALL
189 GetCursorInfo(PCURSORINFO pci)
190 {
191 return (BOOL)NtUserGetCursorInfo(pci);
192 }
193
194
195 /*
196 * @implemented
197 */
198 BOOL STDCALL
199 GetCursorPos(LPPOINT lpPoint)
200 {
201 BOOL res;
202 /* Windows doesn't check if lpPoint == NULL, we do */
203 if(!lpPoint)
204 {
205 SetLastError(ERROR_INVALID_PARAMETER);
206 return FALSE;
207 }
208
209 res = NtUserGetCursorPos(lpPoint);
210
211 return res;
212 }
213
214
215 /*
216 * @implemented
217 */
218 HCURSOR STDCALL
219 LoadCursorA(HINSTANCE hInstance,
220 LPCSTR lpCursorName)
221 {
222 return(LoadImageA(hInstance, lpCursorName, IMAGE_CURSOR, 0, 0,
223 LR_SHARED | LR_DEFAULTSIZE));
224 }
225
226
227 /*
228 * @implemented
229 */
230 HCURSOR STDCALL
231 LoadCursorFromFileA(LPCSTR lpFileName)
232 {
233 UNICODE_STRING FileName;
234 HCURSOR Result;
235 RtlCreateUnicodeStringFromAsciiz(&FileName, (LPSTR)lpFileName);
236 Result = LoadImageW(0, FileName.Buffer, IMAGE_CURSOR, 0, 0,
237 LR_LOADFROMFILE | LR_DEFAULTSIZE);
238 RtlFreeUnicodeString(&FileName);
239 return(Result);
240 }
241
242
243 /*
244 * @implemented
245 */
246 HCURSOR STDCALL
247 LoadCursorFromFileW(LPCWSTR lpFileName)
248 {
249 return(LoadImageW(0, lpFileName, IMAGE_CURSOR, 0, 0,
250 LR_LOADFROMFILE | LR_DEFAULTSIZE));
251 }
252
253
254 /*
255 * @implemented
256 */
257 HCURSOR STDCALL
258 LoadCursorW(HINSTANCE hInstance,
259 LPCWSTR lpCursorName)
260 {
261 return(LoadImageW(hInstance, lpCursorName, IMAGE_CURSOR, 0, 0,
262 LR_SHARED | LR_DEFAULTSIZE));
263 }
264
265
266 /*
267 * @implemented
268 */
269 BOOL
270 STDCALL
271 ClipCursor(
272 CONST RECT *lpRect)
273 {
274 return NtUserClipCursor((RECT *)lpRect);
275 }
276
277
278 /*
279 * @implemented
280 */
281 HCURSOR STDCALL
282 SetCursor(HCURSOR hCursor)
283 {
284 return NtUserSetCursor(hCursor);
285 }
286
287
288 /*
289 * @implemented
290 */
291 BOOL STDCALL
292 SetCursorPos(int X,
293 int Y)
294 {
295 INPUT Input;
296
297 Input.type = INPUT_MOUSE;
298 Input.mi.dx = (LONG)X;
299 Input.mi.dy = (LONG)Y;
300 Input.mi.mouseData = 0;
301 Input.mi.dwFlags = MOUSEEVENTF_MOVE | MOUSEEVENTF_ABSOLUTE;
302 Input.mi.time = 0;
303 Input.mi.dwExtraInfo = 0;
304
305 NtUserSendInput(1, &Input, sizeof(INPUT));
306 return TRUE;
307 }
308
309
310 /*
311 * @unimplemented
312 */
313 BOOL STDCALL
314 SetSystemCursor(HCURSOR hcur,
315 DWORD id)
316 {
317 UNIMPLEMENTED;
318 return FALSE;
319 }
320
321
322 /*
323 * @unimplemented
324 */
325 int STDCALL
326 ShowCursor(BOOL bShow)
327 {
328 UNIMPLEMENTED;
329 return 0;
330 }
331
332 HCURSOR
333 CursorIconToCursor(HICON hIcon, BOOL SemiTransparent)
334 {
335 UNIMPLEMENTED;
336 return 0;
337 }