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