2 * ReactOS W32 Subsystem
3 * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 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 along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 * We handle two types of cursors/icons:
23 * Loaded without LR_SHARED flag
24 * Private to a process
25 * Can be deleted by calling NtDestroyCursorIcon()
26 * CurIcon->hModule, CurIcon->hRsrc and CurIcon->hGroupRsrc set to NULL
28 * Loaded with LR_SHARED flag
29 * Possibly shared by multiple processes
30 * Immune to NtDestroyCursorIcon()
31 * CurIcon->hModule, CurIcon->hRsrc and CurIcon->hGroupRsrc are valid
32 * There's a M:N relationship between processes and (shared) cursor/icons.
33 * A process can have multiple cursor/icons and a cursor/icon can be used
34 * by multiple processes. To keep track of this we keep a list of all
35 * cursor/icons (CurIconList) and per cursor/icon we keep a list of
36 * CURICON_PROCESS structs starting at CurIcon->ProcessList.
44 static PAGED_LOOKASIDE_LIST gProcessLookasideList
;
45 static LIST_ENTRY gCurIconList
;
47 SYSTEM_CURSORINFO gSysCursorInfo
;
52 ExInitializePagedLookasideList(&gProcessLookasideList
,
56 sizeof(CURICON_PROCESS
),
59 InitializeListHead(&gCurIconList
);
61 gSysCursorInfo
.Enabled
= FALSE
;
62 gSysCursorInfo
.ButtonsDown
= 0;
63 gSysCursorInfo
.CursorClipInfo
.IsClipped
= FALSE
;
64 gSysCursorInfo
.LastBtnDown
= 0;
65 gSysCursorInfo
.CurrentCursorObject
= NULL
;
66 gSysCursorInfo
.ShowingCursor
= 0;
67 gSysCursorInfo
.ClickLockActive
= FALSE
;
68 gSysCursorInfo
.ClickLockTime
= 0;
76 return &gSysCursorInfo
;
79 /* This function creates a reference for the object! */
80 PCURICON_OBJECT FASTCALL
UserGetCurIconObject(HCURSOR hCurIcon
)
82 PCURICON_OBJECT CurIcon
;
86 SetLastWin32Error(ERROR_INVALID_CURSOR_HANDLE
);
90 CurIcon
= (PCURICON_OBJECT
)UserReferenceObjectByHandle(hCurIcon
, otCursorIcon
);
93 /* we never set ERROR_INVALID_ICON_HANDLE. lets hope noone ever checks for it */
94 SetLastWin32Error(ERROR_INVALID_CURSOR_HANDLE
);
98 ASSERT(CurIcon
->head
.cLockObj
>= 1);
105 PCURICON_OBJECT NewCursor
,
108 PSYSTEM_CURSORINFO CurInfo
;
109 PCURICON_OBJECT OldCursor
;
110 HCURSOR hOldCursor
= (HCURSOR
)0;
114 CurInfo
= IntGetSysCursorInfo();
116 OldCursor
= CurInfo
->CurrentCursorObject
;
119 hOldCursor
= (HCURSOR
)OldCursor
->Self
;
122 /* Is the new cursor the same as the old cursor? */
123 if (OldCursor
== NewCursor
)
125 /* Nothing to to do in this case */
129 /* Get the screen DC */
130 if(!(hdcScreen
= IntGetScreenDC()))
135 /* Do we have a new cursor? */
138 UserReferenceObject(NewCursor
);
140 CurInfo
->ShowingCursor
= 1;
141 CurInfo
->CurrentCursorObject
= NewCursor
;
143 /* Call GDI to set the new screen cursor */
144 bResult
= GreSetPointerShape(hdcScreen
,
145 NewCursor
->IconInfo
.hbmMask
,
146 NewCursor
->IconInfo
.hbmColor
,
147 NewCursor
->IconInfo
.xHotspot
,
148 NewCursor
->IconInfo
.yHotspot
,
156 /* Check if were diplaying a cursor */
157 if (OldCursor
&& CurInfo
->ShowingCursor
)
159 /* Remove the cursor */
160 GreMovePointer(hdcScreen
, -1, -1);
161 DPRINT("Removing pointer!\n");
164 CurInfo
->CurrentCursorObject
= NULL
;
165 CurInfo
->ShowingCursor
= 0;
168 /* OldCursor is not in use anymore */
171 UserDereferenceObject(OldCursor
);
174 /* Return handle of the old cursor */
178 BOOL
UserSetCursorPos( INT x
, INT y
, BOOL SendMouseMoveMsg
)
180 PWINDOW_OBJECT DesktopWindow
;
181 PSYSTEM_CURSORINFO CurInfo
;
185 if(!(hDC
= IntGetScreenDC()))
190 CurInfo
= IntGetSysCursorInfo();
192 DesktopWindow
= UserGetDesktopWindow();
196 if(x
>= DesktopWindow
->Wnd
->rcClient
.right
)
197 x
= DesktopWindow
->Wnd
->rcClient
.right
- 1;
198 if(y
>= DesktopWindow
->Wnd
->rcClient
.bottom
)
199 y
= DesktopWindow
->Wnd
->rcClient
.bottom
- 1;
207 //Clip cursor position
208 if(CurInfo
->CursorClipInfo
.IsClipped
)
210 if(x
>= (LONG
)CurInfo
->CursorClipInfo
.Right
)
211 x
= (LONG
)CurInfo
->CursorClipInfo
.Right
- 1;
212 if(x
< (LONG
)CurInfo
->CursorClipInfo
.Left
)
213 x
= (LONG
)CurInfo
->CursorClipInfo
.Left
;
214 if(y
>= (LONG
)CurInfo
->CursorClipInfo
.Bottom
)
215 y
= (LONG
)CurInfo
->CursorClipInfo
.Bottom
- 1;
216 if(y
< (LONG
)CurInfo
->CursorClipInfo
.Top
)
217 y
= (LONG
)CurInfo
->CursorClipInfo
.Top
;
220 //Store the new cursor position
221 gpsi
->ptCursor
.x
= x
;
222 gpsi
->ptCursor
.y
= y
;
224 //Move the mouse pointer
225 GreMovePointer(hDC
, x
, y
);
227 if (!SendMouseMoveMsg
)
230 //Generate a mouse move message
231 Msg
.message
= WM_MOUSEMOVE
;
232 Msg
.wParam
= CurInfo
->ButtonsDown
;
233 Msg
.lParam
= MAKELPARAM(x
, y
);
234 Msg
.pt
= gpsi
->ptCursor
;
235 MsqInsertSystemMessage(&Msg
);
240 /* Called from NtUserCallOneParam with Routine ONEPARAM_ROUTINE_SHOWCURSOR
241 * User32 macro NtUserShowCursor */
242 int UserShowCursor(BOOL bShow
)
244 PSYSTEM_CURSORINFO CurInfo
= IntGetSysCursorInfo();
247 if (!(hdcScreen
= IntGetScreenDC()))
249 return 0; /* No mouse */
254 /* Check if were diplaying a cursor */
255 if (CurInfo
->ShowingCursor
== 1)
257 /* Remove the pointer */
258 GreMovePointer(hdcScreen
, -1, -1);
259 DPRINT("Removing pointer!\n");
261 CurInfo
->ShowingCursor
--;
265 if (CurInfo
->ShowingCursor
== 0)
268 GreMovePointer(hdcScreen
, gpsi
->ptCursor
.x
, gpsi
->ptCursor
.y
);
270 CurInfo
->ShowingCursor
++;
273 return CurInfo
->ShowingCursor
;
277 * We have to register that this object is in use by the current
278 * process. The only way to do that seems to be to walk the list
279 * of cursor/icon objects starting at W32Process->CursorIconListHead.
280 * If the object is already present in the list, we don't have to do
281 * anything, if it's not present we add it and inc the ProcessCount
282 * in the object. Having to walk the list kind of sucks, but that's
285 static BOOLEAN FASTCALL
286 ReferenceCurIconByProcess(PCURICON_OBJECT CurIcon
)
288 PPROCESSINFO Win32Process
;
289 PCURICON_PROCESS Current
;
291 Win32Process
= PsGetCurrentProcessWin32Process();
293 LIST_FOR_EACH(Current
, &CurIcon
->ProcessList
, CURICON_PROCESS
, ListEntry
)
295 if (Current
->Process
== Win32Process
)
297 /* Already registered for this process */
302 /* Not registered yet */
303 Current
= ExAllocateFromPagedLookasideList(&gProcessLookasideList
);
308 InsertHeadList(&CurIcon
->ProcessList
, &Current
->ListEntry
);
309 Current
->Process
= Win32Process
;
314 PCURICON_OBJECT FASTCALL
315 IntFindExistingCurIconObject(HMODULE hModule
,
316 HRSRC hRsrc
, LONG cx
, LONG cy
)
318 PCURICON_OBJECT CurIcon
;
320 LIST_FOR_EACH(CurIcon
, &gCurIconList
, CURICON_OBJECT
, ListEntry
)
323 // if(NT_SUCCESS(UserReferenceObjectByPointer(Object, otCursorIcon))) //<- huh????
324 // UserReferenceObject( CurIcon);
326 if ((CurIcon
->hModule
== hModule
) && (CurIcon
->hRsrc
== hRsrc
))
328 if (cx
&& ((cx
!= CurIcon
->Size
.cx
) || (cy
!= CurIcon
->Size
.cy
)))
330 // UserDereferenceObject(CurIcon);
333 if (! ReferenceCurIconByProcess(CurIcon
))
341 // UserDereferenceObject(CurIcon);
349 IntCreateCurIconHandle()
351 PCURICON_OBJECT CurIcon
;
354 CurIcon
= UserCreateObject(gHandleTable
, NULL
, &hCurIcon
, otCursorIcon
, sizeof(CURICON_OBJECT
));
358 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
362 CurIcon
->Self
= hCurIcon
;
363 InitializeListHead(&CurIcon
->ProcessList
);
365 if (! ReferenceCurIconByProcess(CurIcon
))
367 DPRINT1("Failed to add process\n");
368 UserDeleteObject(hCurIcon
, otCursorIcon
);
369 UserDereferenceObject(CurIcon
);
373 InsertHeadList(&gCurIconList
, &CurIcon
->ListEntry
);
379 IntDestroyCurIconObject(PCURICON_OBJECT CurIcon
, BOOL ProcessCleanup
)
381 PSYSTEM_CURSORINFO CurInfo
;
382 HBITMAP bmpMask
, bmpColor
;
384 PCURICON_PROCESS Current
= NULL
;
385 PPROCESSINFO W32Process
= PsGetCurrentProcessWin32Process();
387 /* Private objects can only be destroyed by their own process */
388 if (NULL
== CurIcon
->hModule
)
390 ASSERT(CurIcon
->ProcessList
.Flink
->Flink
== &CurIcon
->ProcessList
);
391 Current
= CONTAINING_RECORD(CurIcon
->ProcessList
.Flink
, CURICON_PROCESS
, ListEntry
);
392 if (Current
->Process
!= W32Process
)
394 DPRINT1("Trying to destroy private icon/cursor of another process\n");
398 else if (! ProcessCleanup
)
400 DPRINT("Trying to destroy shared icon/cursor\n");
404 /* Now find this process in the list of processes referencing this object and
405 remove it from that list */
406 LIST_FOR_EACH(Current
, &CurIcon
->ProcessList
, CURICON_PROCESS
, ListEntry
)
408 if (Current
->Process
== W32Process
)
410 RemoveEntryList(&Current
->ListEntry
);
415 ExFreeToPagedLookasideList(&gProcessLookasideList
, Current
);
417 /* If there are still processes referencing this object we can't destroy it yet */
418 if (! IsListEmpty(&CurIcon
->ProcessList
))
424 if (! ProcessCleanup
)
426 RemoveEntryList(&CurIcon
->ListEntry
);
429 CurInfo
= IntGetSysCursorInfo();
431 if (CurInfo
->CurrentCursorObject
== CurIcon
)
433 /* Hide the cursor if we're destroying the current cursor */
434 UserSetCursor(NULL
, TRUE
);
437 bmpMask
= CurIcon
->IconInfo
.hbmMask
;
438 bmpColor
= CurIcon
->IconInfo
.hbmColor
;
443 GDIOBJ_SetOwnership(bmpMask
, PsGetCurrentProcess());
444 GreDeleteObject(bmpMask
);
445 CurIcon
->IconInfo
.hbmMask
= NULL
;
449 GDIOBJ_SetOwnership(bmpColor
, PsGetCurrentProcess());
450 GreDeleteObject(bmpColor
);
451 CurIcon
->IconInfo
.hbmColor
= NULL
;
454 /* We were given a pointer, no need to keep the reference anylonger! */
455 UserDereferenceObject(CurIcon
);
456 Ret
= UserDeleteObject(CurIcon
->Self
, otCursorIcon
);
462 IntCleanupCurIcons(struct _EPROCESS
*Process
, PPROCESSINFO Win32Process
)
464 PCURICON_OBJECT CurIcon
, tmp
;
465 PCURICON_PROCESS ProcessData
;
467 LIST_FOR_EACH_SAFE(CurIcon
, tmp
, &gCurIconList
, CURICON_OBJECT
, ListEntry
)
469 UserReferenceObject(CurIcon
);
470 // if(NT_SUCCESS(UserReferenceObjectByPointer(Object, otCursorIcon)))
472 LIST_FOR_EACH(ProcessData
, &CurIcon
->ProcessList
, CURICON_PROCESS
, ListEntry
)
474 if (Win32Process
== ProcessData
->Process
)
476 RemoveEntryList(&CurIcon
->ListEntry
);
477 IntDestroyCurIconObject(CurIcon
, TRUE
);
483 // UserDereferenceObject(Object);
488 UserDereferenceObject(CurIcon
);
499 NtUserCreateCursorIconHandle(PICONINFO IconInfo OPTIONAL
, BOOL Indirect
)
501 PCURICON_OBJECT CurIcon
;
505 DECLARE_RETURN(HANDLE
);
507 DPRINT("Enter NtUserCreateCursorIconHandle\n");
508 UserEnterExclusive();
510 if (!(CurIcon
= IntCreateCurIconHandle()))
512 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
520 Status
= MmCopyFromCaller(&CurIcon
->IconInfo
, IconInfo
, sizeof(ICONINFO
));
521 if (NT_SUCCESS(Status
))
523 /* Copy bitmaps and size info */
527 CurIcon
->IconInfo
.hbmMask
= BITMAP_CopyBitmap(CurIcon
->IconInfo
.hbmMask
);
528 CurIcon
->IconInfo
.hbmColor
= BITMAP_CopyBitmap(CurIcon
->IconInfo
.hbmColor
);
530 if (CurIcon
->IconInfo
.hbmColor
&&
531 (psurfBmp
= SURFACE_LockSurface(CurIcon
->IconInfo
.hbmColor
)))
533 CurIcon
->Size
.cx
= psurfBmp
->SurfObj
.sizlBitmap
.cx
;
534 CurIcon
->Size
.cy
= psurfBmp
->SurfObj
.sizlBitmap
.cy
;
535 SURFACE_UnlockSurface(psurfBmp
);
536 GDIOBJ_SetOwnership(CurIcon
->IconInfo
.hbmColor
, NULL
);
538 if (CurIcon
->IconInfo
.hbmMask
&&
539 (psurfBmp
= SURFACE_LockSurface(CurIcon
->IconInfo
.hbmMask
)))
541 if (CurIcon
->IconInfo
.hbmColor
== NULL
)
543 CurIcon
->Size
.cx
= psurfBmp
->SurfObj
.sizlBitmap
.cx
;
544 CurIcon
->Size
.cy
= psurfBmp
->SurfObj
.sizlBitmap
.cy
>> 1;
546 SURFACE_UnlockSurface(psurfBmp
);
547 GDIOBJ_SetOwnership(CurIcon
->IconInfo
.hbmMask
, NULL
);
550 /* Calculate icon hotspot */
551 if (CurIcon
->IconInfo
.fIcon
== TRUE
)
553 CurIcon
->IconInfo
.xHotspot
= CurIcon
->Size
.cx
>> 1;
554 CurIcon
->IconInfo
.yHotspot
= CurIcon
->Size
.cy
>> 1;
559 SetLastNtError(Status
);
560 /* FIXME - Don't exit here */
564 UserDereferenceObject(CurIcon
);
568 DPRINT("Leave NtUserCreateCursorIconHandle, ret=%i\n",_ret_
);
581 PUNICODE_STRING lpInstName
, // optional
582 PUNICODE_STRING lpResName
, // optional
583 LPDWORD pbpp
, // optional
587 PCURICON_OBJECT CurIcon
;
588 NTSTATUS Status
= STATUS_SUCCESS
;
592 DPRINT("Enter NtUserGetIconInfo\n");
593 UserEnterExclusive();
597 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
601 if (!(CurIcon
= UserGetCurIconObject(hCurIcon
)))
606 RtlCopyMemory(&ii
, &CurIcon
->IconInfo
, sizeof(ICONINFO
));
609 ii
.hbmMask
= BITMAP_CopyBitmap(CurIcon
->IconInfo
.hbmMask
);
610 ii
.hbmColor
= BITMAP_CopyBitmap(CurIcon
->IconInfo
.hbmColor
);
616 psurfBmp
= SURFACE_LockSurface(CurIcon
->IconInfo
.hbmColor
);
619 colorBpp
= BitsPerFormat(psurfBmp
->SurfObj
.iBitmapFormat
);
620 SURFACE_UnlockSurface(psurfBmp
);
627 ProbeForWrite(IconInfo
, sizeof(ICONINFO
), 1);
628 RtlCopyMemory(IconInfo
, &ii
, sizeof(ICONINFO
));
632 ProbeForWrite(pbpp
, sizeof(DWORD
), 1);
636 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
638 Status
= _SEH2_GetExceptionCode();
642 if (NT_SUCCESS(Status
))
645 SetLastNtError(Status
);
647 UserDereferenceObject(CurIcon
);
650 DPRINT("Leave NtUserGetIconInfo, ret=%i\n", Ret
);
665 PLONG plcx
, // &size.cx
666 PLONG plcy
) // &size.cy
668 PCURICON_OBJECT CurIcon
;
669 NTSTATUS Status
= STATUS_SUCCESS
;
672 DPRINT("Enter NtUserGetIconSize\n");
673 UserEnterExclusive();
675 if (!(CurIcon
= UserGetCurIconObject(hCurIcon
)))
682 ProbeForWrite(plcx
, sizeof(LONG
), 1);
683 RtlCopyMemory(plcx
, &CurIcon
->Size
.cx
, sizeof(LONG
));
684 ProbeForWrite(plcy
, sizeof(LONG
), 1);
685 RtlCopyMemory(plcy
, &CurIcon
->Size
.cy
, sizeof(LONG
));
687 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
689 Status
= _SEH2_GetExceptionCode();
693 if (NT_SUCCESS(Status
))
696 SetLastNtError(Status
); // maybe not, test this
698 UserDereferenceObject(CurIcon
);
701 DPRINT("Leave NtUserGetIconSize, ret=%i\n", bRet
);
712 NtUserGetCursorFrameInfo(
733 PSYSTEM_CURSORINFO CurInfo
;
734 NTSTATUS Status
= STATUS_SUCCESS
;
735 PCURICON_OBJECT CurIcon
;
737 DECLARE_RETURN(BOOL
);
739 DPRINT("Enter NtUserGetCursorInfo\n");
740 UserEnterExclusive();
742 CurInfo
= IntGetSysCursorInfo();
743 CurIcon
= (PCURICON_OBJECT
)CurInfo
->CurrentCursorObject
;
745 SafeCi
.cbSize
= sizeof(CURSORINFO
);
746 SafeCi
.flags
= ((CurInfo
->ShowingCursor
&& CurIcon
) ? CURSOR_SHOWING
: 0);
747 SafeCi
.hCursor
= (CurIcon
? (HCURSOR
)CurIcon
->Self
: (HCURSOR
)0);
749 SafeCi
.ptScreenPos
= gpsi
->ptCursor
;
753 if (pci
->cbSize
== sizeof(CURSORINFO
))
755 ProbeForWrite(pci
, sizeof(CURSORINFO
), 1);
756 RtlCopyMemory(pci
, &SafeCi
, sizeof(CURSORINFO
));
761 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
764 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
766 Status
= _SEH2_GetExceptionCode();
769 if (!NT_SUCCESS(Status
))
771 SetLastNtError(Status
);
777 DPRINT("Leave NtUserGetCursorInfo, ret=%i\n",_ret_
);
791 /* FIXME - check if process has WINSTA_WRITEATTRIBUTES */
792 PSYSTEM_CURSORINFO CurInfo
;
794 PWINDOW_OBJECT DesktopWindow
= NULL
;
795 DECLARE_RETURN(BOOL
);
797 DPRINT("Enter NtUserClipCursor\n");
798 UserEnterExclusive();
800 if (NULL
!= UnsafeRect
&& ! NT_SUCCESS(MmCopyFromCaller(&Rect
, UnsafeRect
, sizeof(RECT
))))
802 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
806 CurInfo
= IntGetSysCursorInfo();
808 DesktopWindow
= UserGetDesktopWindow();
810 if ((Rect
.right
> Rect
.left
) && (Rect
.bottom
> Rect
.top
)
811 && DesktopWindow
&& UnsafeRect
!= NULL
)
814 CurInfo
->CursorClipInfo
.IsClipped
= TRUE
;
815 CurInfo
->CursorClipInfo
.Left
= max(Rect
.left
, DesktopWindow
->Wnd
->rcWindow
.left
);
816 CurInfo
->CursorClipInfo
.Top
= max(Rect
.top
, DesktopWindow
->Wnd
->rcWindow
.top
);
817 CurInfo
->CursorClipInfo
.Right
= min(Rect
.right
, DesktopWindow
->Wnd
->rcWindow
.right
);
818 CurInfo
->CursorClipInfo
.Bottom
= min(Rect
.bottom
, DesktopWindow
->Wnd
->rcWindow
.bottom
);
820 UserSetCursorPos(gpsi
->ptCursor
.x
, gpsi
->ptCursor
.y
, FALSE
);
825 CurInfo
->CursorClipInfo
.IsClipped
= FALSE
;
829 DPRINT("Leave NtUserClipCursor, ret=%i\n",_ret_
);
844 PCURICON_OBJECT CurIcon
;
846 DECLARE_RETURN(BOOL
);
848 DPRINT("Enter NtUserDestroyCursorIcon\n");
849 UserEnterExclusive();
851 if (!(CurIcon
= UserGetCurIconObject(hCurIcon
)))
856 ret
= IntDestroyCurIconObject(CurIcon
, FALSE
);
857 /* Note: IntDestroyCurIconObject will remove our reference for us! */
862 DPRINT("Leave NtUserDestroyCursorIcon, ret=%i\n",_ret_
);
873 NtUserFindExistingCursorIcon(
879 PCURICON_OBJECT CurIcon
;
880 HANDLE Ret
= (HANDLE
)0;
881 DECLARE_RETURN(HICON
);
883 DPRINT("Enter NtUserFindExistingCursorIcon\n");
884 UserEnterExclusive();
886 CurIcon
= IntFindExistingCurIconObject(hModule
, hRsrc
, cx
, cy
);
891 // IntReleaseCurIconObject(CurIcon);//faxme: is this correct? does IntFindExistingCurIconObject add a ref?
895 SetLastWin32Error(ERROR_INVALID_CURSOR_HANDLE
);
899 DPRINT("Leave NtUserFindExistingCursorIcon, ret=%i\n",_ret_
);
913 /* FIXME - check if process has WINSTA_READATTRIBUTES */
914 PSYSTEM_CURSORINFO CurInfo
;
917 DECLARE_RETURN(BOOL
);
919 DPRINT("Enter NtUserGetClipCursor\n");
920 UserEnterExclusive();
925 CurInfo
= IntGetSysCursorInfo();
926 if (CurInfo
->CursorClipInfo
.IsClipped
)
928 Rect
.left
= CurInfo
->CursorClipInfo
.Left
;
929 Rect
.top
= CurInfo
->CursorClipInfo
.Top
;
930 Rect
.right
= CurInfo
->CursorClipInfo
.Right
;
931 Rect
.bottom
= CurInfo
->CursorClipInfo
.Bottom
;
937 Rect
.right
= UserGetSystemMetrics(SM_CXSCREEN
);
938 Rect
.bottom
= UserGetSystemMetrics(SM_CYSCREEN
);
941 Status
= MmCopyToCaller(lpRect
, &Rect
, sizeof(RECT
));
942 if (!NT_SUCCESS(Status
))
944 SetLastNtError(Status
);
951 DPRINT("Leave NtUserGetClipCursor, ret=%i\n",_ret_
);
965 PCURICON_OBJECT CurIcon
;
967 DECLARE_RETURN(HCURSOR
);
969 DPRINT("Enter NtUserSetCursor\n");
970 UserEnterExclusive();
974 if (!(CurIcon
= UserGetCurIconObject(hCursor
)))
984 OldCursor
= UserSetCursor(CurIcon
, FALSE
);
988 UserDereferenceObject(CurIcon
);
994 DPRINT("Leave NtUserSetCursor, ret=%i\n",_ret_
);
1005 NtUserSetCursorContents(
1007 PICONINFO UnsafeIconInfo
)
1009 PCURICON_OBJECT CurIcon
;
1014 DECLARE_RETURN(BOOL
);
1016 DPRINT("Enter NtUserSetCursorContents\n");
1017 UserEnterExclusive();
1019 if (!(CurIcon
= UserGetCurIconObject(hCurIcon
)))
1025 Status
= MmCopyFromCaller(&IconInfo
, UnsafeIconInfo
, sizeof(ICONINFO
));
1026 if (!NT_SUCCESS(Status
))
1028 SetLastNtError(Status
);
1032 /* Delete old bitmaps */
1033 if ((CurIcon
->IconInfo
.hbmColor
)
1034 && (CurIcon
->IconInfo
.hbmColor
!= IconInfo
.hbmColor
))
1036 GreDeleteObject(CurIcon
->IconInfo
.hbmColor
);
1038 if ((CurIcon
->IconInfo
.hbmMask
)
1039 && (CurIcon
->IconInfo
.hbmMask
!= IconInfo
.hbmMask
))
1041 GreDeleteObject(CurIcon
->IconInfo
.hbmMask
);
1044 /* Copy new IconInfo field */
1045 CurIcon
->IconInfo
= IconInfo
;
1047 psurfBmp
= SURFACE_LockSurface(CurIcon
->IconInfo
.hbmColor
);
1050 CurIcon
->Size
.cx
= psurfBmp
->SurfObj
.sizlBitmap
.cx
;
1051 CurIcon
->Size
.cy
= psurfBmp
->SurfObj
.sizlBitmap
.cy
;
1052 SURFACE_UnlockSurface(psurfBmp
);
1053 GDIOBJ_SetOwnership(CurIcon
->IconInfo
.hbmColor
, NULL
);
1057 psurfBmp
= SURFACE_LockSurface(CurIcon
->IconInfo
.hbmMask
);
1061 CurIcon
->Size
.cx
= psurfBmp
->SurfObj
.sizlBitmap
.cx
;
1062 CurIcon
->Size
.cy
= psurfBmp
->SurfObj
.sizlBitmap
.cy
/ 2;
1064 SURFACE_UnlockSurface(psurfBmp
);
1065 GDIOBJ_SetOwnership(CurIcon
->IconInfo
.hbmMask
, NULL
);
1074 UserDereferenceObject(CurIcon
);
1079 DPRINT("Leave NtUserSetCursorContents, ret=%i\n",_ret_
);
1091 NtUserSetCursorIconData(
1094 PUNICODE_STRING pstrResName
,
1095 PICONINFO pIconInfo
)
1097 PCURICON_OBJECT CurIcon
;
1099 NTSTATUS Status
= STATUS_SUCCESS
;
1101 DECLARE_RETURN(BOOL
);
1103 DPRINT("Enter NtUserSetCursorIconData\n");
1104 UserEnterExclusive();
1106 if (!(CurIcon
= UserGetCurIconObject(Handle
)))
1111 CurIcon
->hModule
= hModule
;
1112 CurIcon
->hRsrc
= NULL
; //hRsrc;
1113 CurIcon
->hGroupRsrc
= NULL
; //hGroupRsrc;
1117 ProbeForRead(pIconInfo
, sizeof(ICONINFO
), 1);
1118 RtlCopyMemory(&CurIcon
->IconInfo
, pIconInfo
, sizeof(ICONINFO
));
1120 CurIcon
->IconInfo
.hbmMask
= BITMAP_CopyBitmap(pIconInfo
->hbmMask
);
1121 CurIcon
->IconInfo
.hbmColor
= BITMAP_CopyBitmap(pIconInfo
->hbmColor
);
1123 if (CurIcon
->IconInfo
.hbmColor
)
1125 if ((psurfBmp
= SURFACE_LockSurface(CurIcon
->IconInfo
.hbmColor
)))
1127 CurIcon
->Size
.cx
= psurfBmp
->SurfObj
.sizlBitmap
.cx
;
1128 CurIcon
->Size
.cy
= psurfBmp
->SurfObj
.sizlBitmap
.cy
;
1129 SURFACE_UnlockSurface(psurfBmp
);
1130 GDIOBJ_SetOwnership(GdiHandleTable
, CurIcon
->IconInfo
.hbmMask
, NULL
);
1133 if (CurIcon
->IconInfo
.hbmMask
)
1135 if (CurIcon
->IconInfo
.hbmColor
== NULL
)
1137 if ((psurfBmp
= SURFACE_LockSurface(CurIcon
->IconInfo
.hbmMask
)))
1139 CurIcon
->Size
.cx
= psurfBmp
->SurfObj
.sizlBitmap
.cx
;
1140 CurIcon
->Size
.cy
= psurfBmp
->SurfObj
.sizlBitmap
.cy
;
1141 SURFACE_UnlockSurface(psurfBmp
);
1144 GDIOBJ_SetOwnership(GdiHandleTable
, CurIcon
->IconInfo
.hbmMask
, NULL
);
1147 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1149 Status
= _SEH2_GetExceptionCode();
1153 if (!NT_SUCCESS(Status
))
1154 SetLastNtError(Status
);
1158 UserDereferenceObject(CurIcon
);
1162 DPRINT("Leave NtUserSetCursorIconData, ret=%i\n",_ret_
);
1169 NtUserSetCursorIconData(
1177 PCURICON_OBJECT CurIcon
;
1181 DECLARE_RETURN(BOOL
);
1183 DPRINT("Enter NtUserSetCursorIconData\n");
1184 UserEnterExclusive();
1186 if (!(CurIcon
= UserGetCurIconObject(hCurIcon
)))
1191 CurIcon
->hModule
= hModule
;
1192 CurIcon
->hRsrc
= hRsrc
;
1193 CurIcon
->hGroupRsrc
= hGroupRsrc
;
1198 Status
= MmCopyFromCaller(&CurIcon
->IconInfo
.fIcon
, fIcon
, sizeof(BOOL
));
1199 if (!NT_SUCCESS(Status
))
1201 SetLastNtError(Status
);
1213 Status
= MmCopyFromCaller(&SafeHotspot
, Hotspot
, sizeof(POINT
));
1214 if (NT_SUCCESS(Status
))
1216 CurIcon
->IconInfo
.xHotspot
= SafeHotspot
.x
;
1217 CurIcon
->IconInfo
.yHotspot
= SafeHotspot
.y
;
1222 SetLastNtError(Status
);
1225 if (!fIcon
&& !Hotspot
)
1233 /* This icon is shared now */
1234 GDIOBJ_SetOwnership(CurIcon
->IconInfo
.hbmMask
, NULL
);
1235 if(CurIcon
->IconInfo
.hbmColor
)
1237 GDIOBJ_SetOwnership(CurIcon
->IconInfo
.hbmColor
, NULL
);
1240 UserDereferenceObject(CurIcon
);
1245 DPRINT("Leave NtUserSetCursorIconData, ret=%i\n",_ret_
);
1256 NtUserSetSystemCursor(
1268 PCURICON_OBJECT pIcon
,
1272 HBRUSH hbrFlickerFreeDraw
,
1276 HBITMAP hbmMask
, hbmColor
;
1277 BITMAP bmpMask
, bmpColor
;
1282 HGDIOBJ hOldOffBrush
= 0;
1283 HGDIOBJ hOldOffBmp
= 0;
1286 HGDIOBJ hOldMask
= NULL
;
1288 HGDIOBJ hOldImage
= NULL
;
1289 BOOL bAlpha
= FALSE
;
1291 hbmMask
= pIcon
->IconInfo
.hbmMask
;
1292 hbmColor
= pIcon
->IconInfo
.hbmColor
;
1295 DPRINT1("NtUserDrawIconEx: istepIfAniCur is not supported!\n");
1297 if (!hbmMask
|| !IntGdiGetObject(hbmMask
, sizeof(BITMAP
), (PVOID
)&bmpMask
))
1302 if (hbmColor
&& !IntGdiGetObject(hbmColor
, sizeof(BITMAP
), (PVOID
)&bmpColor
))
1309 IconSize
.cx
= bmpColor
.bmWidth
;
1310 IconSize
.cy
= bmpColor
.bmHeight
;
1314 IconSize
.cx
= bmpMask
.bmWidth
;
1315 IconSize
.cy
= bmpMask
.bmHeight
/ 2;
1318 /* NtGdiCreateCompatibleBitmap will create a monochrome bitmap
1319 when cxWidth or cyHeight is 0 */
1320 if ((bmpColor
.bmBitsPixel
== 32) && (cxWidth
!= 0) && (cyHeight
!= 0))
1322 SURFACE
*psurfOff
= NULL
;
1323 PFN_DIB_GetPixel fnSource_GetPixel
= NULL
;
1326 /* In order to correctly display 32 bit icons Windows first scans the image,
1327 because information about transparency is not stored in any image's headers */
1328 psurfOff
= SURFACE_LockSurface(hbmColor
? hbmColor
: hbmMask
);
1331 fnSource_GetPixel
= DibFunctionsForBitmapFormat
[psurfOff
->SurfObj
.iBitmapFormat
].DIB_GetPixel
;
1332 if (fnSource_GetPixel
)
1334 for (x
= 0; x
< psurfOff
->SurfObj
.sizlBitmap
.cx
; x
++)
1336 for (y
= 0; y
< psurfOff
->SurfObj
.sizlBitmap
.cy
; y
++)
1338 bAlpha
= ((BYTE
)(fnSource_GetPixel(&psurfOff
->SurfObj
, x
, y
) >> 24) & 0xff);
1346 SURFACE_UnlockSurface(psurfOff
);
1351 diFlags
= DI_NORMAL
;
1354 cxWidth
= ((diFlags
& DI_DEFAULTSIZE
) ?
1355 UserGetSystemMetrics(SM_CXICON
) : IconSize
.cx
);
1358 cyHeight
= ((diFlags
& DI_DEFAULTSIZE
) ?
1359 UserGetSystemMetrics(SM_CYICON
) : IconSize
.cy
);
1361 DoFlickerFree
= (hbrFlickerFreeDraw
&&
1362 (GDI_HANDLE_GET_TYPE(hbrFlickerFreeDraw
) == GDI_OBJECT_TYPE_BRUSH
));
1364 if (DoFlickerFree
|| bAlpha
)
1368 SURFACE
*psurfOff
= NULL
;
1371 r
.bottom
= cyHeight
;
1373 hdcOff
= NtGdiCreateCompatibleDC(hDc
);
1376 DPRINT1("NtGdiCreateCompatibleDC() failed!\n");
1380 hbmOff
= NtGdiCreateCompatibleBitmap(hDc
, cxWidth
, cyHeight
);
1383 DPRINT1("NtGdiCreateCompatibleBitmap() failed!\n");
1387 /* make sure we have a 32 bit offscreen bitmap
1388 otherwise we can't do alpha blending */
1389 psurfOff
= SURFACE_LockSurface(hbmOff
);
1390 if (psurfOff
== NULL
)
1392 DPRINT1("BITMAPOBJ_LockBitmap() failed!\n");
1395 BITMAP_GetObject(psurfOff
, sizeof(BITMAP
), (PVOID
)&bm
);
1397 if (bm
.bmBitsPixel
!= 32)
1400 SURFACE_UnlockSurface(psurfOff
);
1402 hOldOffBmp
= NtGdiSelectBitmap(hdcOff
, hbmOff
);
1405 DPRINT1("NtGdiSelectBitmap() failed!\n");
1411 hOldOffBrush
= NtGdiSelectBrush(hdcOff
, hbrFlickerFreeDraw
);
1414 DPRINT1("NtGdiSelectBrush() failed!\n");
1418 NtGdiPatBlt(hdcOff
, 0, 0, r
.right
, r
.bottom
, PATCOPY
);
1424 if (diFlags
& DI_IMAGE
)
1426 hdcImage
= NtGdiCreateCompatibleDC(hDc
);
1429 DPRINT1("NtGdiCreateCompatibleDC() failed!\n");
1432 hOldImage
= NtGdiSelectBitmap(hdcImage
, (hbmColor
? hbmColor
: hbmMask
));
1435 DPRINT("NtGdiSelectBitmap() failed!\n");
1440 /* If DI_IMAGE flag is specified and hbmMask exists, then always use mask for drawing */
1441 if (diFlags
& DI_MASK
|| (diFlags
& DI_IMAGE
&& hbmMask
))
1443 hdcMask
= NtGdiCreateCompatibleDC(hDc
);
1446 DPRINT1("NtGdiCreateCompatibleDC() failed!\n");
1450 hOldMask
= NtGdiSelectBitmap(hdcMask
, hbmMask
);
1453 DPRINT("NtGdiSelectBitmap() failed!\n");
1458 if (hdcMask
|| hdcImage
)
1460 GreStretchBltMask(hdcOff
,
1461 (DoFlickerFree
|| bAlpha
) ? 0 : xLeft
,
1462 (DoFlickerFree
|| bAlpha
) ? 0 : yTop
,
1465 hdcImage
? hdcImage
: hdcMask
,
1474 hdcImage
? 0 : IconSize
.cy
);
1477 if (hOldMask
) NtGdiSelectBitmap(hdcMask
, hOldMask
);
1478 if (hOldImage
) NtGdiSelectBitmap(hdcImage
, hOldImage
);
1479 if (hdcImage
) NtGdiDeleteObjectApp(hdcImage
);
1480 if (hdcMask
) NtGdiDeleteObjectApp(hdcMask
);
1485 SURFACE
*psurfOff
= NULL
;
1487 BLENDFUNCTION BlendFunc
;
1489 BYTE Red
, Green
, Blue
, Alpha
;
1493 psurfOff
= SURFACE_LockSurface(hbmOff
);
1494 if (psurfOff
== NULL
)
1496 DPRINT1("BITMAPOBJ_LockBitmap() failed!\n");
1499 BITMAP_GetObject(psurfOff
, sizeof(BITMAP
), (PVOID
)&bm
);
1501 pBits
= ExAllocatePoolWithTag(PagedPool
, bm
.bmWidthBytes
* abs(bm
.bmHeight
), TAG_BITMAP
);
1504 DPRINT1("ExAllocatePoolWithTag() failed!\n");
1505 SURFACE_UnlockSurface(psurfOff
);
1510 IntGetBitmapBits(psurfOff
, bm
.bmWidthBytes
* abs(bm
.bmHeight
), pBits
);
1512 /* premultiply with the alpha channel value */
1513 for (i
= 0; i
< cyHeight
; i
++)
1515 for (j
= 0; j
< cxWidth
; j
++)
1517 Pixel
= *(DWORD
*)(pBits
+ Count
);
1519 Alpha
= ((BYTE
)(Pixel
>> 24) & 0xff);
1521 Red
= (((BYTE
)(Pixel
>> 0)) * Alpha
) / 0xff;
1522 Green
= (((BYTE
)(Pixel
>> 8)) * Alpha
) / 0xff;
1523 Blue
= (((BYTE
)(Pixel
>> 16)) * Alpha
) / 0xff;
1525 *(DWORD
*)(pBits
+ Count
) = (DWORD
)(Red
| (Green
<< 8) | (Blue
<< 16) | (Alpha
<< 24));
1527 Count
+= sizeof(DWORD
);
1532 IntSetBitmapBits(psurfOff
, bm
.bmWidthBytes
* abs(bm
.bmHeight
), pBits
);
1533 ExFreePoolWithTag(pBits
, TAG_BITMAP
);
1535 SURFACE_UnlockSurface(psurfOff
);
1537 BlendFunc
.BlendOp
= AC_SRC_OVER
;
1538 BlendFunc
.BlendFlags
= 0;
1539 BlendFunc
.SourceConstantAlpha
= 255;
1540 BlendFunc
.AlphaFormat
= AC_SRC_ALPHA
;
1542 NtGdiAlphaBlend(hDc
, xLeft
, yTop
, cxWidth
, cyHeight
,
1543 hdcOff
, 0, 0, cxWidth
, cyHeight
, BlendFunc
, 0);
1545 else if (DoFlickerFree
)
1547 NtGdiBitBlt(hDc
, xLeft
, yTop
, cxWidth
,
1548 cyHeight
, hdcOff
, 0, 0, SRCCOPY
, 0, 0);
1554 if (DoFlickerFree
|| bAlpha
)
1556 if (hOldOffBmp
) NtGdiSelectBitmap(hdcOff
, hOldOffBmp
);
1557 if (hOldOffBrush
) NtGdiSelectBrush(hdcOff
, hOldOffBrush
);
1558 if (hbmOff
) GreDeleteObject(hbmOff
);
1559 if (hdcOff
) NtGdiDeleteObjectApp(hdcOff
);
1578 HBRUSH hbrFlickerFreeDraw
,
1580 BOOL bMetaHDC
, // When TRUE, GDI functions need to be handled in User32!
1583 PCURICON_OBJECT pIcon
;
1586 DPRINT("Enter NtUserDrawIconEx\n");
1587 UserEnterExclusive();
1589 if (!(pIcon
= UserGetCurIconObject(hIcon
)))
1591 DPRINT1("UserGetCurIconObject() failed!\n");
1596 Ret
= UserDrawIconEx(hdc
,
1606 UserDereferenceObject(pIcon
);