migrate substitution keywords to SVN
[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 #include <string.h>
33 #include <debug.h>
34 #undef CopyCursor
35
36 HBITMAP
37 CopyBitmap(HBITMAP bmp);
38
39 /* INTERNAL ******************************************************************/
40
41 /* This callback routine is called directly after switching to gui mode */
42 NTSTATUS STDCALL
43 User32SetupDefaultCursors(PVOID Arguments, ULONG ArgumentLength)
44 {
45 BOOL *DefaultCursor = (BOOL*)Arguments;
46 LRESULT Result = TRUE;
47
48 if(*DefaultCursor)
49 {
50 /* set default cursor */
51 SetCursor(LoadCursorW(0, (LPCWSTR)IDC_ARROW));
52 }
53 else
54 {
55 /* FIXME load system cursor scheme */
56 SetCursor(0);
57 SetCursor(LoadCursorW(0, (LPCWSTR)IDC_ARROW));
58 }
59
60 return(ZwCallbackReturn(&Result, sizeof(LRESULT), STATUS_SUCCESS));
61 }
62
63 /* FUNCTIONS *****************************************************************/
64
65
66 /*
67 * @implemented
68 */
69 HCURSOR STDCALL
70 CopyCursor(HCURSOR pcur)
71 {
72 ICONINFO IconInfo;
73
74 if(NtUserGetCursorIconInfo((HANDLE)pcur, &IconInfo))
75 {
76 return (HCURSOR)NtUserCreateCursorIconHandle(&IconInfo, FALSE);
77 }
78 return (HCURSOR)0;
79 }
80
81 /*
82 * @implemented
83 */
84 HCURSOR STDCALL
85 CreateCursor(HINSTANCE hInst,
86 int xHotSpot,
87 int yHotSpot,
88 int nWidth,
89 int nHeight,
90 CONST VOID *pvANDPlane,
91 CONST VOID *pvXORPlane)
92 {
93 ICONINFO IconInfo;
94 BYTE BitmapInfoBuffer[sizeof(BITMAPINFOHEADER) + 2 * sizeof(RGBQUAD)];
95 BITMAPINFO *bwBIH = (BITMAPINFO *)BitmapInfoBuffer;
96 HDC hScreenDc;
97
98 hScreenDc = CreateCompatibleDC(NULL);
99 if (hScreenDc == NULL)
100 return NULL;
101
102 bwBIH->bmiHeader.biBitCount = 1;
103 bwBIH->bmiHeader.biWidth = nWidth;
104 bwBIH->bmiHeader.biHeight = -nHeight * 2;
105 bwBIH->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
106 bwBIH->bmiHeader.biPlanes = 1;
107 bwBIH->bmiHeader.biSizeImage = 0;
108 bwBIH->bmiHeader.biCompression = BI_RGB;
109 bwBIH->bmiHeader.biClrImportant = 0;
110 bwBIH->bmiHeader.biClrUsed = 0;
111 bwBIH->bmiHeader.biXPelsPerMeter = 0;
112 bwBIH->bmiHeader.biYPelsPerMeter = 0;
113
114 bwBIH->bmiColors[0].rgbBlue = 0;
115 bwBIH->bmiColors[0].rgbGreen = 0;
116 bwBIH->bmiColors[0].rgbRed = 0;
117 bwBIH->bmiColors[0].rgbReserved = 0;
118
119 bwBIH->bmiColors[1].rgbBlue = 0xff;
120 bwBIH->bmiColors[1].rgbGreen = 0xff;
121 bwBIH->bmiColors[1].rgbRed = 0xff;
122 bwBIH->bmiColors[1].rgbReserved = 0;
123
124 IconInfo.hbmMask = CreateDIBitmap(hScreenDc, &bwBIH->bmiHeader, 0,
125 NULL, bwBIH, DIB_RGB_COLORS);
126 if (IconInfo.hbmMask)
127 {
128 SetDIBits(hScreenDc, IconInfo.hbmMask, 0, nHeight,
129 pvXORPlane, bwBIH, DIB_RGB_COLORS);
130 SetDIBits(hScreenDc, IconInfo.hbmMask, nHeight, nHeight,
131 pvANDPlane, bwBIH, DIB_RGB_COLORS);
132 }
133 else
134 {
135 return NULL;
136 }
137
138 DeleteDC(hScreenDc);
139
140 IconInfo.fIcon = FALSE;
141 IconInfo.xHotspot = xHotSpot;
142 IconInfo.yHotspot = yHotSpot;
143 IconInfo.hbmColor = 0;
144
145 return (HCURSOR)NtUserCreateCursorIconHandle(&IconInfo, FALSE);
146 }
147
148
149 /*
150 * @implemented
151 */
152 BOOL STDCALL
153 DestroyCursor(HCURSOR hCursor)
154 {
155 return (BOOL)NtUserDestroyCursorIcon((HANDLE)hCursor, 0);
156 }
157
158
159 /*
160 * @implemented
161 */
162 BOOL STDCALL
163 GetClipCursor(LPRECT lpRect)
164 {
165 return NtUserGetClipCursor(lpRect);
166 }
167
168
169 /*
170 * @implemented
171 */
172 HCURSOR STDCALL
173 GetCursor(VOID)
174 {
175 CURSORINFO ci;
176 ci.cbSize = sizeof(CURSORINFO);
177 if(NtUserGetCursorInfo(&ci))
178 return ci.hCursor;
179 else
180 return (HCURSOR)0;
181 }
182
183
184 /*
185 * @implemented
186 */
187 BOOL STDCALL
188 GetCursorInfo(PCURSORINFO pci)
189 {
190 return (BOOL)NtUserGetCursorInfo(pci);
191 }
192
193
194 /*
195 * @implemented
196 */
197 BOOL STDCALL
198 GetCursorPos(LPPOINT lpPoint)
199 {
200 BOOL res;
201 /* Windows doesn't check if lpPoint == NULL, we do */
202 if(!lpPoint)
203 {
204 SetLastError(ERROR_INVALID_PARAMETER);
205 return FALSE;
206 }
207
208 res = NtUserGetCursorPos(lpPoint);
209
210 return res;
211 }
212
213
214 /*
215 * @implemented
216 */
217 HCURSOR STDCALL
218 LoadCursorA(HINSTANCE hInstance,
219 LPCSTR lpCursorName)
220 {
221 return(LoadImageA(hInstance, lpCursorName, IMAGE_CURSOR, 0, 0,
222 LR_SHARED | LR_DEFAULTSIZE));
223 }
224
225
226 /*
227 * @implemented
228 */
229 HCURSOR STDCALL
230 LoadCursorFromFileA(LPCSTR lpFileName)
231 {
232 UNICODE_STRING FileName;
233 HCURSOR Result;
234 RtlCreateUnicodeStringFromAsciiz(&FileName, (LPSTR)lpFileName);
235 Result = LoadImageW(0, FileName.Buffer, IMAGE_CURSOR, 0, 0,
236 LR_LOADFROMFILE | LR_DEFAULTSIZE);
237 RtlFreeUnicodeString(&FileName);
238 return(Result);
239 }
240
241
242 /*
243 * @implemented
244 */
245 HCURSOR STDCALL
246 LoadCursorFromFileW(LPCWSTR lpFileName)
247 {
248 return(LoadImageW(0, lpFileName, IMAGE_CURSOR, 0, 0,
249 LR_LOADFROMFILE | LR_DEFAULTSIZE));
250 }
251
252
253 /*
254 * @implemented
255 */
256 HCURSOR STDCALL
257 LoadCursorW(HINSTANCE hInstance,
258 LPCWSTR lpCursorName)
259 {
260 return(LoadImageW(hInstance, lpCursorName, IMAGE_CURSOR, 0, 0,
261 LR_SHARED | LR_DEFAULTSIZE));
262 }
263
264
265 /*
266 * @implemented
267 */
268 BOOL
269 STDCALL
270 ClipCursor(
271 CONST RECT *lpRect)
272 {
273 return NtUserClipCursor((RECT *)lpRect);
274 }
275
276
277 /*
278 * @implemented
279 */
280 HCURSOR STDCALL
281 SetCursor(HCURSOR hCursor)
282 {
283 return NtUserSetCursor(hCursor);
284 }
285
286
287 /*
288 * @implemented
289 */
290 BOOL STDCALL
291 SetCursorPos(int X,
292 int Y)
293 {
294 INPUT Input;
295
296 Input.type = INPUT_MOUSE;
297 Input.mi.dx = (LONG)X;
298 Input.mi.dy = (LONG)Y;
299 Input.mi.mouseData = 0;
300 Input.mi.dwFlags = MOUSEEVENTF_MOVE | MOUSEEVENTF_ABSOLUTE;
301 Input.mi.time = 0;
302 Input.mi.dwExtraInfo = 0;
303
304 NtUserSendInput(1, &Input, sizeof(INPUT));
305 return TRUE;
306 }
307
308
309 /*
310 * @unimplemented
311 */
312 BOOL STDCALL
313 SetSystemCursor(HCURSOR hcur,
314 DWORD id)
315 {
316 UNIMPLEMENTED;
317 return FALSE;
318 }
319
320
321 /*
322 * @unimplemented
323 */
324 int STDCALL
325 ShowCursor(BOOL bShow)
326 {
327 UNIMPLEMENTED;
328 return 0;
329 }
330
331 HCURSOR
332 CursorIconToCursor(HICON hIcon, BOOL SemiTransparent)
333 {
334 UNIMPLEMENTED;
335 return 0;
336 }