3 * Copyright (C) 1998, 1999, 2000, 2001 ReactOS Team
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.
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.
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.
21 * PROJECT: ReactOS user32.dll
22 * FILE: lib/user32/windows/cursor.c
24 * PROGRAMMER: Casper S. Hornstrup (chorns@users.sourceforge.net)
26 * 09-05-2001 CSH Created
29 /* INCLUDES ******************************************************************/
33 #include <wine/debug.h>
35 WINE_DEFAULT_DEBUG_CHANNEL(user32
);
40 CopyBitmap(HBITMAP bmp
);
42 /* INTERNAL ******************************************************************/
44 /* This callback routine is called directly after switching to gui mode */
47 User32SetupDefaultCursors(PVOID Arguments
,
50 BOOL
*DefaultCursor
= (BOOL
*)Arguments
;
51 LRESULT Result
= TRUE
;
55 /* set default cursor */
56 SetCursor(LoadCursorW(0, (LPCWSTR
)IDC_ARROW
));
60 /* FIXME load system cursor scheme */
62 SetCursor(LoadCursorW(0, (LPCWSTR
)IDC_ARROW
));
65 return(ZwCallbackReturn(&Result
, sizeof(LRESULT
), STATUS_SUCCESS
));
68 /* FUNCTIONS *****************************************************************/
76 CopyCursor(HCURSOR pcur
)
80 if(GetIconInfo((HANDLE
)pcur
, &IconInfo
))
82 return (HCURSOR
)NtUserCreateCursorIconHandle(&IconInfo
, FALSE
);
92 CreateCursor(HINSTANCE hInst
,
97 CONST VOID
*pvANDPlane
,
98 CONST VOID
*pvXORPlane
)
101 BYTE BitmapInfoBuffer
[sizeof(BITMAPINFOHEADER
) + 2 * sizeof(RGBQUAD
)];
102 BITMAPINFO
*bwBIH
= (BITMAPINFO
*)BitmapInfoBuffer
;
105 hScreenDc
= CreateCompatibleDC(NULL
);
106 if (hScreenDc
== NULL
)
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;
121 bwBIH
->bmiColors
[0].rgbBlue
= 0;
122 bwBIH
->bmiColors
[0].rgbGreen
= 0;
123 bwBIH
->bmiColors
[0].rgbRed
= 0;
124 bwBIH
->bmiColors
[0].rgbReserved
= 0;
126 bwBIH
->bmiColors
[1].rgbBlue
= 0xff;
127 bwBIH
->bmiColors
[1].rgbGreen
= 0xff;
128 bwBIH
->bmiColors
[1].rgbRed
= 0xff;
129 bwBIH
->bmiColors
[1].rgbReserved
= 0;
131 IconInfo
.hbmMask
= CreateDIBitmap(hScreenDc
, &bwBIH
->bmiHeader
, 0,
132 NULL
, bwBIH
, DIB_RGB_COLORS
);
133 if (IconInfo
.hbmMask
)
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
);
147 IconInfo
.fIcon
= FALSE
;
148 IconInfo
.xHotspot
= xHotSpot
;
149 IconInfo
.yHotspot
= yHotSpot
;
150 IconInfo
.hbmColor
= 0;
152 return (HCURSOR
)NtUserCreateCursorIconHandle(&IconInfo
, FALSE
);
161 DestroyCursor(HCURSOR hCursor
)
163 return (BOOL
)NtUserDestroyCursor((HANDLE
)hCursor
, 0);
172 GetClipCursor(LPRECT lpRect
)
174 return NtUserGetClipCursor(lpRect
);
186 ci
.cbSize
= sizeof(CURSORINFO
);
187 if(NtUserGetCursorInfo(&ci
))
199 GetCursorInfo(PCURSORINFO pci
)
201 return (BOOL
)NtUserGetCursorInfo(pci
);
210 GetCursorPos(LPPOINT lpPoint
)
213 /* Windows doesn't check if lpPoint == NULL, we do */
216 SetLastError(ERROR_INVALID_PARAMETER
);
220 res
= NtUserGetCursorPos(lpPoint
);
231 LoadCursorA(HINSTANCE hInstance
,
234 return(LoadImageA(hInstance
,
239 LR_SHARED
| LR_DEFAULTSIZE
));
248 LoadCursorFromFileA(LPCSTR lpFileName
)
250 UNICODE_STRING FileName
;
252 RtlCreateUnicodeStringFromAsciiz(&FileName
, (LPSTR
)lpFileName
);
253 Result
= LoadImageW(0,
258 LR_LOADFROMFILE
| LR_DEFAULTSIZE
);
259 RtlFreeUnicodeString(&FileName
);
269 LoadCursorFromFileW(LPCWSTR lpFileName
)
276 LR_LOADFROMFILE
| LR_DEFAULTSIZE
));
285 LoadCursorW(HINSTANCE hInstance
,
286 LPCWSTR lpCursorName
)
288 return(LoadImageW(hInstance
,
293 LR_SHARED
| LR_DEFAULTSIZE
));
302 ClipCursor(CONST RECT
*lpRect
)
304 return NtUserClipCursor((RECT
*)lpRect
);
313 SetCursor(HCURSOR hCursor
)
315 return NtUserSetCursor(hCursor
);
329 Input
.type
= INPUT_MOUSE
;
330 Input
.mi
.dx
= (LONG
)X
;
331 Input
.mi
.dy
= (LONG
)Y
;
332 Input
.mi
.mouseData
= 0;
333 Input
.mi
.dwFlags
= MOUSEEVENTF_MOVE
| MOUSEEVENTF_ABSOLUTE
;
335 Input
.mi
.dwExtraInfo
= 0;
337 NtUserSendInput(1, &Input
, sizeof(INPUT
));
347 SetSystemCursor(HCURSOR hcur
,
360 ShowCursor(BOOL bShow
)
362 return NtUserShowCursor(bShow
);
366 CursorIconToCursor(HICON hIcon
,
367 BOOL SemiTransparent
)