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;
73 PSYSTEM_CURSORINFO FASTCALL
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
)
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 //Generate a mouse move message
228 Msg
.message
= WM_MOUSEMOVE
;
229 Msg
.wParam
= CurInfo
->ButtonsDown
;
230 Msg
.lParam
= MAKELPARAM(x
, y
);
231 Msg
.pt
= gpsi
->ptCursor
;
232 MsqInsertSystemMessage(&Msg
);
237 /* Called from NtUserCallOneParam with Routine ONEPARAM_ROUTINE_SHOWCURSOR
238 * User32 macro NtUserShowCursor */
239 int UserShowCursor(BOOL bShow
)
241 PSYSTEM_CURSORINFO CurInfo
= IntGetSysCursorInfo();;
244 if (!(hdcScreen
= IntGetScreenDC()))
246 return 0; /* No mouse */
251 /* Check if were diplaying a cursor */
252 if (CurInfo
->ShowingCursor
== 1)
254 /* Remove the pointer */
255 GreMovePointer(hdcScreen
, -1, -1);
256 DPRINT("Removing pointer!\n");
258 CurInfo
->ShowingCursor
--;
262 if (CurInfo
->ShowingCursor
== 0)
265 GreMovePointer(hdcScreen
, gpsi
->ptCursor
.x
, gpsi
->ptCursor
.y
);
267 CurInfo
->ShowingCursor
++;
270 return CurInfo
->ShowingCursor
;
274 * We have to register that this object is in use by the current
275 * process. The only way to do that seems to be to walk the list
276 * of cursor/icon objects starting at W32Process->CursorIconListHead.
277 * If the object is already present in the list, we don't have to do
278 * anything, if it's not present we add it and inc the ProcessCount
279 * in the object. Having to walk the list kind of sucks, but that's
282 static BOOLEAN FASTCALL
283 ReferenceCurIconByProcess(PCURICON_OBJECT CurIcon
)
285 PPROCESSINFO Win32Process
;
286 PCURICON_PROCESS Current
;
288 Win32Process
= PsGetCurrentProcessWin32Process();
290 LIST_FOR_EACH(Current
, &CurIcon
->ProcessList
, CURICON_PROCESS
, ListEntry
)
292 if (Current
->Process
== Win32Process
)
294 /* Already registered for this process */
299 /* Not registered yet */
300 Current
= ExAllocateFromPagedLookasideList(&gProcessLookasideList
);
305 InsertHeadList(&CurIcon
->ProcessList
, &Current
->ListEntry
);
306 Current
->Process
= Win32Process
;
311 PCURICON_OBJECT FASTCALL
312 IntFindExistingCurIconObject(HMODULE hModule
,
313 HRSRC hRsrc
, LONG cx
, LONG cy
)
315 PCURICON_OBJECT CurIcon
;
317 LIST_FOR_EACH(CurIcon
, &gCurIconList
, CURICON_OBJECT
, ListEntry
)
320 // if(NT_SUCCESS(UserReferenceObjectByPointer(Object, otCursorIcon))) //<- huh????
321 // UserReferenceObject( CurIcon);
323 if ((CurIcon
->hModule
== hModule
) && (CurIcon
->hRsrc
== hRsrc
))
325 if (cx
&& ((cx
!= CurIcon
->Size
.cx
) || (cy
!= CurIcon
->Size
.cy
)))
327 // UserDereferenceObject(CurIcon);
330 if (! ReferenceCurIconByProcess(CurIcon
))
338 // UserDereferenceObject(CurIcon);
345 PCURICON_OBJECT FASTCALL
346 IntCreateCurIconHandle()
348 PCURICON_OBJECT CurIcon
;
351 CurIcon
= UserCreateObject(gHandleTable
, NULL
, &hCurIcon
, otCursorIcon
, sizeof(CURICON_OBJECT
));
355 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
359 CurIcon
->Self
= hCurIcon
;
360 InitializeListHead(&CurIcon
->ProcessList
);
362 if (! ReferenceCurIconByProcess(CurIcon
))
364 DPRINT1("Failed to add process\n");
365 UserDeleteObject(hCurIcon
, otCursorIcon
);
366 UserDereferenceObject(CurIcon
);
370 InsertHeadList(&gCurIconList
, &CurIcon
->ListEntry
);
376 IntDestroyCurIconObject(PCURICON_OBJECT CurIcon
, BOOL ProcessCleanup
)
378 PSYSTEM_CURSORINFO CurInfo
;
379 HBITMAP bmpMask
, bmpColor
;
381 PCURICON_PROCESS Current
= NULL
;
382 PPROCESSINFO W32Process
= PsGetCurrentProcessWin32Process();
384 /* Private objects can only be destroyed by their own process */
385 if (NULL
== CurIcon
->hModule
)
387 ASSERT(CurIcon
->ProcessList
.Flink
->Flink
== &CurIcon
->ProcessList
);
388 Current
= CONTAINING_RECORD(CurIcon
->ProcessList
.Flink
, CURICON_PROCESS
, ListEntry
);
389 if (Current
->Process
!= W32Process
)
391 DPRINT1("Trying to destroy private icon/cursor of another process\n");
395 else if (! ProcessCleanup
)
397 DPRINT("Trying to destroy shared icon/cursor\n");
401 /* Now find this process in the list of processes referencing this object and
402 remove it from that list */
403 LIST_FOR_EACH(Current
, &CurIcon
->ProcessList
, CURICON_PROCESS
, ListEntry
)
405 if (Current
->Process
== W32Process
)
407 RemoveEntryList(&Current
->ListEntry
);
412 ExFreeToPagedLookasideList(&gProcessLookasideList
, Current
);
414 /* If there are still processes referencing this object we can't destroy it yet */
415 if (! IsListEmpty(&CurIcon
->ProcessList
))
421 if (! ProcessCleanup
)
423 RemoveEntryList(&CurIcon
->ListEntry
);
426 CurInfo
= IntGetSysCursorInfo();
428 if (CurInfo
->CurrentCursorObject
== CurIcon
)
430 /* Hide the cursor if we're destroying the current cursor */
431 UserSetCursor(NULL
, TRUE
);
434 bmpMask
= CurIcon
->IconInfo
.hbmMask
;
435 bmpColor
= CurIcon
->IconInfo
.hbmColor
;
440 GDIOBJ_SetOwnership(bmpMask
, PsGetCurrentProcess());
441 GreDeleteObject(bmpMask
);
442 CurIcon
->IconInfo
.hbmMask
= NULL
;
446 GDIOBJ_SetOwnership(bmpColor
, PsGetCurrentProcess());
447 GreDeleteObject(bmpColor
);
448 CurIcon
->IconInfo
.hbmColor
= NULL
;
451 /* We were given a pointer, no need to keep the reference anylonger! */
452 UserDereferenceObject(CurIcon
);
453 Ret
= UserDeleteObject(CurIcon
->Self
, otCursorIcon
);
459 IntCleanupCurIcons(struct _EPROCESS
*Process
, PPROCESSINFO Win32Process
)
461 PCURICON_OBJECT CurIcon
, tmp
;
462 PCURICON_PROCESS ProcessData
;
464 LIST_FOR_EACH_SAFE(CurIcon
, tmp
, &gCurIconList
, CURICON_OBJECT
, ListEntry
)
466 UserReferenceObject(CurIcon
);
467 // if(NT_SUCCESS(UserReferenceObjectByPointer(Object, otCursorIcon)))
469 LIST_FOR_EACH(ProcessData
, &CurIcon
->ProcessList
, CURICON_PROCESS
, ListEntry
)
471 if (Win32Process
== ProcessData
->Process
)
473 RemoveEntryList(&CurIcon
->ListEntry
);
474 IntDestroyCurIconObject(CurIcon
, TRUE
);
480 // UserDereferenceObject(Object);
485 UserDereferenceObject(CurIcon
);
496 NtUserCreateCursorIconHandle(PICONINFO IconInfo OPTIONAL
, BOOL Indirect
)
498 PCURICON_OBJECT CurIcon
;
502 DECLARE_RETURN(HANDLE
);
504 DPRINT("Enter NtUserCreateCursorIconHandle\n");
505 UserEnterExclusive();
507 if (!(CurIcon
= IntCreateCurIconHandle()))
509 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
517 Status
= MmCopyFromCaller(&CurIcon
->IconInfo
, IconInfo
, sizeof(ICONINFO
));
518 if (NT_SUCCESS(Status
))
520 /* Copy bitmaps and size info */
524 CurIcon
->IconInfo
.hbmMask
= BITMAP_CopyBitmap(CurIcon
->IconInfo
.hbmMask
);
525 CurIcon
->IconInfo
.hbmColor
= BITMAP_CopyBitmap(CurIcon
->IconInfo
.hbmColor
);
527 if (CurIcon
->IconInfo
.hbmColor
&&
528 (psurfBmp
= SURFACE_LockSurface(CurIcon
->IconInfo
.hbmColor
)))
530 CurIcon
->Size
.cx
= psurfBmp
->SurfObj
.sizlBitmap
.cx
;
531 CurIcon
->Size
.cy
= psurfBmp
->SurfObj
.sizlBitmap
.cy
;
532 SURFACE_UnlockSurface(psurfBmp
);
533 GDIOBJ_SetOwnership(CurIcon
->IconInfo
.hbmColor
, NULL
);
535 if (CurIcon
->IconInfo
.hbmMask
&&
536 (psurfBmp
= SURFACE_LockSurface(CurIcon
->IconInfo
.hbmMask
)))
538 if (CurIcon
->IconInfo
.hbmColor
== NULL
)
540 CurIcon
->Size
.cx
= psurfBmp
->SurfObj
.sizlBitmap
.cx
;
541 CurIcon
->Size
.cy
= psurfBmp
->SurfObj
.sizlBitmap
.cy
>> 1;
543 SURFACE_UnlockSurface(psurfBmp
);
544 GDIOBJ_SetOwnership(CurIcon
->IconInfo
.hbmMask
, NULL
);
547 /* Calculate icon hotspot */
548 if (CurIcon
->IconInfo
.fIcon
== TRUE
)
550 CurIcon
->IconInfo
.xHotspot
= CurIcon
->Size
.cx
>> 1;
551 CurIcon
->IconInfo
.yHotspot
= CurIcon
->Size
.cy
>> 1;
556 SetLastNtError(Status
);
557 /* FIXME - Don't exit here */
561 UserDereferenceObject(CurIcon
);
565 DPRINT("Leave NtUserCreateCursorIconHandle, ret=%i\n",_ret_
);
578 PUNICODE_STRING lpInstName
, // optional
579 PUNICODE_STRING lpResName
, // optional
580 LPDWORD pbpp
, // optional
584 PCURICON_OBJECT CurIcon
;
585 NTSTATUS Status
= STATUS_SUCCESS
;
589 DPRINT("Enter NtUserGetIconInfo\n");
590 UserEnterExclusive();
594 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
598 if (!(CurIcon
= UserGetCurIconObject(hCurIcon
)))
603 RtlCopyMemory(&ii
, &CurIcon
->IconInfo
, sizeof(ICONINFO
));
606 ii
.hbmMask
= BITMAP_CopyBitmap(CurIcon
->IconInfo
.hbmMask
);
607 ii
.hbmColor
= BITMAP_CopyBitmap(CurIcon
->IconInfo
.hbmColor
);
613 psurfBmp
= SURFACE_LockSurface(CurIcon
->IconInfo
.hbmColor
);
616 colorBpp
= BitsPerFormat(psurfBmp
->SurfObj
.iBitmapFormat
);
617 SURFACE_UnlockSurface(psurfBmp
);
624 ProbeForWrite(IconInfo
, sizeof(ICONINFO
), 1);
625 RtlCopyMemory(IconInfo
, &ii
, sizeof(ICONINFO
));
629 ProbeForWrite(pbpp
, sizeof(DWORD
), 1);
633 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
635 Status
= _SEH2_GetExceptionCode();
639 if (NT_SUCCESS(Status
))
642 SetLastNtError(Status
);
644 UserDereferenceObject(CurIcon
);
647 DPRINT("Leave NtUserGetIconInfo, ret=%i\n", Ret
);
662 PLONG plcx
, // &size.cx
663 PLONG plcy
) // &size.cy
665 PCURICON_OBJECT CurIcon
;
666 NTSTATUS Status
= STATUS_SUCCESS
;
669 DPRINT("Enter NtUserGetIconSize\n");
670 UserEnterExclusive();
672 if (!(CurIcon
= UserGetCurIconObject(hCurIcon
)))
679 ProbeForWrite(plcx
, sizeof(LONG
), 1);
680 RtlCopyMemory(plcx
, &CurIcon
->Size
.cx
, sizeof(LONG
));
681 ProbeForWrite(plcy
, sizeof(LONG
), 1);
682 RtlCopyMemory(plcy
, &CurIcon
->Size
.cy
, sizeof(LONG
));
684 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
686 Status
= _SEH2_GetExceptionCode();
690 if (NT_SUCCESS(Status
))
693 SetLastNtError(Status
); // maybe not, test this
695 UserDereferenceObject(CurIcon
);
698 DPRINT("Leave NtUserGetIconSize, ret=%i\n", bRet
);
709 NtUserGetCursorFrameInfo(
730 PSYSTEM_CURSORINFO CurInfo
;
731 NTSTATUS Status
= STATUS_SUCCESS
;
732 PCURICON_OBJECT CurIcon
;
734 DECLARE_RETURN(BOOL
);
736 DPRINT("Enter NtUserGetCursorInfo\n");
737 UserEnterExclusive();
739 CurInfo
= IntGetSysCursorInfo();
740 CurIcon
= (PCURICON_OBJECT
)CurInfo
->CurrentCursorObject
;
742 SafeCi
.cbSize
= sizeof(CURSORINFO
);
743 SafeCi
.flags
= ((CurInfo
->ShowingCursor
&& CurIcon
) ? CURSOR_SHOWING
: 0);
744 SafeCi
.hCursor
= (CurIcon
? (HCURSOR
)CurIcon
->Self
: (HCURSOR
)0);
746 SafeCi
.ptScreenPos
= gpsi
->ptCursor
;
750 if (pci
->cbSize
== sizeof(CURSORINFO
))
752 ProbeForWrite(pci
, sizeof(CURSORINFO
), 1);
753 RtlCopyMemory(pci
, &SafeCi
, sizeof(CURSORINFO
));
758 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
761 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
763 Status
= _SEH2_GetExceptionCode();
766 if (!NT_SUCCESS(Status
))
768 SetLastNtError(Status
);
774 DPRINT("Leave NtUserGetCursorInfo, ret=%i\n",_ret_
);
788 /* FIXME - check if process has WINSTA_WRITEATTRIBUTES */
789 PSYSTEM_CURSORINFO CurInfo
;
791 PWINDOW_OBJECT DesktopWindow
= NULL
;
792 DECLARE_RETURN(BOOL
);
794 DPRINT("Enter NtUserClipCursor\n");
795 UserEnterExclusive();
797 if (NULL
!= UnsafeRect
&& ! NT_SUCCESS(MmCopyFromCaller(&Rect
, UnsafeRect
, sizeof(RECT
))))
799 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
803 CurInfo
= IntGetSysCursorInfo();
805 DesktopWindow
= UserGetDesktopWindow();
807 if ((Rect
.right
> Rect
.left
) && (Rect
.bottom
> Rect
.top
)
808 && DesktopWindow
&& UnsafeRect
!= NULL
)
811 CurInfo
->CursorClipInfo
.IsClipped
= TRUE
;
812 CurInfo
->CursorClipInfo
.Left
= max(Rect
.left
, DesktopWindow
->Wnd
->rcWindow
.left
);
813 CurInfo
->CursorClipInfo
.Top
= max(Rect
.top
, DesktopWindow
->Wnd
->rcWindow
.top
);
814 CurInfo
->CursorClipInfo
.Right
= min(Rect
.right
, DesktopWindow
->Wnd
->rcWindow
.right
);
815 CurInfo
->CursorClipInfo
.Bottom
= min(Rect
.bottom
, DesktopWindow
->Wnd
->rcWindow
.bottom
);
817 UserSetCursorPos(gpsi
->ptCursor
.x
, gpsi
->ptCursor
.y
);
822 CurInfo
->CursorClipInfo
.IsClipped
= FALSE
;
826 DPRINT("Leave NtUserClipCursor, ret=%i\n",_ret_
);
841 PCURICON_OBJECT CurIcon
;
843 DECLARE_RETURN(BOOL
);
845 DPRINT("Enter NtUserDestroyCursorIcon\n");
846 UserEnterExclusive();
848 if (!(CurIcon
= UserGetCurIconObject(hCurIcon
)))
853 ret
= IntDestroyCurIconObject(CurIcon
, FALSE
);
854 /* Note: IntDestroyCurIconObject will remove our reference for us! */
859 DPRINT("Leave NtUserDestroyCursorIcon, ret=%i\n",_ret_
);
870 NtUserFindExistingCursorIcon(
876 PCURICON_OBJECT CurIcon
;
877 HANDLE Ret
= (HANDLE
)0;
878 DECLARE_RETURN(HICON
);
880 DPRINT("Enter NtUserFindExistingCursorIcon\n");
881 UserEnterExclusive();
883 CurIcon
= IntFindExistingCurIconObject(hModule
, hRsrc
, cx
, cy
);
888 // IntReleaseCurIconObject(CurIcon);//faxme: is this correct? does IntFindExistingCurIconObject add a ref?
892 SetLastWin32Error(ERROR_INVALID_CURSOR_HANDLE
);
896 DPRINT("Leave NtUserFindExistingCursorIcon, ret=%i\n",_ret_
);
910 /* FIXME - check if process has WINSTA_READATTRIBUTES */
911 PSYSTEM_CURSORINFO CurInfo
;
914 DECLARE_RETURN(BOOL
);
916 DPRINT("Enter NtUserGetClipCursor\n");
917 UserEnterExclusive();
922 CurInfo
= IntGetSysCursorInfo();
923 if (CurInfo
->CursorClipInfo
.IsClipped
)
925 Rect
.left
= CurInfo
->CursorClipInfo
.Left
;
926 Rect
.top
= CurInfo
->CursorClipInfo
.Top
;
927 Rect
.right
= CurInfo
->CursorClipInfo
.Right
;
928 Rect
.bottom
= CurInfo
->CursorClipInfo
.Bottom
;
934 Rect
.right
= UserGetSystemMetrics(SM_CXSCREEN
);
935 Rect
.bottom
= UserGetSystemMetrics(SM_CYSCREEN
);
938 Status
= MmCopyToCaller(lpRect
, &Rect
, sizeof(RECT
));
939 if (!NT_SUCCESS(Status
))
941 SetLastNtError(Status
);
948 DPRINT("Leave NtUserGetClipCursor, ret=%i\n",_ret_
);
962 PCURICON_OBJECT CurIcon
;
964 DECLARE_RETURN(HCURSOR
);
966 DPRINT("Enter NtUserSetCursor\n");
967 UserEnterExclusive();
971 if (!(CurIcon
= UserGetCurIconObject(hCursor
)))
981 OldCursor
= UserSetCursor(CurIcon
, FALSE
);
985 UserDereferenceObject(CurIcon
);
991 DPRINT("Leave NtUserSetCursor, ret=%i\n",_ret_
);
1002 NtUserSetCursorContents(
1004 PICONINFO UnsafeIconInfo
)
1006 PCURICON_OBJECT CurIcon
;
1011 DECLARE_RETURN(BOOL
);
1013 DPRINT("Enter NtUserSetCursorContents\n");
1014 UserEnterExclusive();
1016 if (!(CurIcon
= UserGetCurIconObject(hCurIcon
)))
1022 Status
= MmCopyFromCaller(&IconInfo
, UnsafeIconInfo
, sizeof(ICONINFO
));
1023 if (!NT_SUCCESS(Status
))
1025 SetLastNtError(Status
);
1029 /* Delete old bitmaps */
1030 if (CurIcon
->IconInfo
.hbmColor
!= IconInfo
.hbmColor
)
1032 GreDeleteObject(CurIcon
->IconInfo
.hbmColor
);
1034 if (CurIcon
->IconInfo
.hbmMask
!= IconInfo
.hbmMask
)
1036 GreDeleteObject(CurIcon
->IconInfo
.hbmMask
);
1039 /* Copy new IconInfo field */
1040 CurIcon
->IconInfo
= IconInfo
;
1042 psurfBmp
= SURFACE_LockSurface(CurIcon
->IconInfo
.hbmColor
);
1045 CurIcon
->Size
.cx
= psurfBmp
->SurfObj
.sizlBitmap
.cx
;
1046 CurIcon
->Size
.cy
= psurfBmp
->SurfObj
.sizlBitmap
.cy
;
1047 SURFACE_UnlockSurface(psurfBmp
);
1048 GDIOBJ_SetOwnership(CurIcon
->IconInfo
.hbmColor
, NULL
);
1052 psurfBmp
= SURFACE_LockSurface(CurIcon
->IconInfo
.hbmMask
);
1056 CurIcon
->Size
.cx
= psurfBmp
->SurfObj
.sizlBitmap
.cx
;
1057 CurIcon
->Size
.cy
= psurfBmp
->SurfObj
.sizlBitmap
.cy
/ 2;
1059 SURFACE_UnlockSurface(psurfBmp
);
1060 GDIOBJ_SetOwnership(CurIcon
->IconInfo
.hbmMask
, NULL
);
1069 UserDereferenceObject(CurIcon
);
1074 DPRINT("Leave NtUserSetCursorContents, ret=%i\n",_ret_
);
1086 NtUserSetCursorIconData(
1089 PUNICODE_STRING pstrResName
,
1090 PICONINFO pIconInfo
)
1092 PCURICON_OBJECT CurIcon
;
1094 NTSTATUS Status
= STATUS_SUCCESS
;
1096 DECLARE_RETURN(BOOL
);
1098 DPRINT("Enter NtUserSetCursorIconData\n");
1099 UserEnterExclusive();
1101 if (!(CurIcon
= UserGetCurIconObject(Handle
)))
1106 CurIcon
->hModule
= hModule
;
1107 CurIcon
->hRsrc
= NULL
; //hRsrc;
1108 CurIcon
->hGroupRsrc
= NULL
; //hGroupRsrc;
1112 ProbeForRead(pIconInfo
, sizeof(ICONINFO
), 1);
1113 RtlCopyMemory(&CurIcon
->IconInfo
, pIconInfo
, sizeof(ICONINFO
));
1115 CurIcon
->IconInfo
.hbmMask
= BITMAP_CopyBitmap(pIconInfo
->hbmMask
);
1116 CurIcon
->IconInfo
.hbmColor
= BITMAP_CopyBitmap(pIconInfo
->hbmColor
);
1118 if (CurIcon
->IconInfo
.hbmColor
)
1120 if ((psurfBmp
= SURFACE_LockSurface(CurIcon
->IconInfo
.hbmColor
)))
1122 CurIcon
->Size
.cx
= psurfBmp
->SurfObj
.sizlBitmap
.cx
;
1123 CurIcon
->Size
.cy
= psurfBmp
->SurfObj
.sizlBitmap
.cy
;
1124 SURFACE_UnlockSurface(psurfBmp
);
1125 GDIOBJ_SetOwnership(GdiHandleTable
, CurIcon
->IconInfo
.hbmMask
, NULL
);
1128 if (CurIcon
->IconInfo
.hbmMask
)
1130 if (CurIcon
->IconInfo
.hbmColor
== NULL
)
1132 if ((psurfBmp
= SURFACE_LockSurface(CurIcon
->IconInfo
.hbmMask
)))
1134 CurIcon
->Size
.cx
= psurfBmp
->SurfObj
.sizlBitmap
.cx
;
1135 CurIcon
->Size
.cy
= psurfBmp
->SurfObj
.sizlBitmap
.cy
;
1136 SURFACE_UnlockSurface(psurfBmp
);
1139 GDIOBJ_SetOwnership(GdiHandleTable
, CurIcon
->IconInfo
.hbmMask
, NULL
);
1142 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1144 Status
= _SEH2_GetExceptionCode();
1148 if (!NT_SUCCESS(Status
))
1149 SetLastNtError(Status
);
1153 UserDereferenceObject(CurIcon
);
1157 DPRINT("Leave NtUserSetCursorIconData, ret=%i\n",_ret_
);
1164 NtUserSetCursorIconData(
1172 PCURICON_OBJECT CurIcon
;
1176 DECLARE_RETURN(BOOL
);
1178 DPRINT("Enter NtUserSetCursorIconData\n");
1179 UserEnterExclusive();
1181 if (!(CurIcon
= UserGetCurIconObject(hCurIcon
)))
1186 CurIcon
->hModule
= hModule
;
1187 CurIcon
->hRsrc
= hRsrc
;
1188 CurIcon
->hGroupRsrc
= hGroupRsrc
;
1193 Status
= MmCopyFromCaller(&CurIcon
->IconInfo
.fIcon
, fIcon
, sizeof(BOOL
));
1194 if (!NT_SUCCESS(Status
))
1196 SetLastNtError(Status
);
1208 Status
= MmCopyFromCaller(&SafeHotspot
, Hotspot
, sizeof(POINT
));
1209 if (NT_SUCCESS(Status
))
1211 CurIcon
->IconInfo
.xHotspot
= SafeHotspot
.x
;
1212 CurIcon
->IconInfo
.yHotspot
= SafeHotspot
.y
;
1217 SetLastNtError(Status
);
1220 if (!fIcon
&& !Hotspot
)
1226 UserDereferenceObject(CurIcon
);
1231 DPRINT("Leave NtUserSetCursorIconData, ret=%i\n",_ret_
);
1242 NtUserSetSystemCursor(
1254 PCURICON_OBJECT pIcon
,
1258 HBRUSH hbrFlickerFreeDraw
,
1262 HBITMAP hbmMask
, hbmColor
;
1263 BITMAP bmpMask
, bmpColor
;
1268 HGDIOBJ hOldOffBrush
= 0;
1269 HGDIOBJ hOldOffBmp
= 0;
1272 HGDIOBJ hOldMask
= NULL
;
1274 HGDIOBJ hOldImage
= NULL
;
1275 BOOL bAlpha
= FALSE
;
1277 hbmMask
= pIcon
->IconInfo
.hbmMask
;
1278 hbmColor
= pIcon
->IconInfo
.hbmColor
;
1281 DPRINT1("NtUserDrawIconEx: istepIfAniCur is not supported!\n");
1283 if (!hbmMask
|| !IntGdiGetObject(hbmMask
, sizeof(BITMAP
), (PVOID
)&bmpMask
))
1288 if (hbmColor
&& !IntGdiGetObject(hbmColor
, sizeof(BITMAP
), (PVOID
)&bmpColor
))
1295 IconSize
.cx
= bmpColor
.bmWidth
;
1296 IconSize
.cy
= bmpColor
.bmHeight
;
1300 IconSize
.cx
= bmpMask
.bmWidth
;
1301 IconSize
.cy
= bmpMask
.bmHeight
/ 2;
1304 /* NtGdiCreateCompatibleBitmap will create a monochrome bitmap
1305 when cxWidth or cyHeight is 0 */
1306 if ((bmpColor
.bmBitsPixel
== 32) && (cxWidth
!= 0) && (cyHeight
!= 0))
1308 SURFACE
*psurfOff
= NULL
;
1309 PFN_DIB_GetPixel fnSource_GetPixel
= NULL
;
1312 /* In order to correctly display 32 bit icons Windows first scans the image,
1313 because information about transparency is not stored in any image's headers */
1314 psurfOff
= SURFACE_LockSurface(hbmColor
? hbmColor
: hbmMask
);
1317 fnSource_GetPixel
= DibFunctionsForBitmapFormat
[psurfOff
->SurfObj
.iBitmapFormat
].DIB_GetPixel
;
1318 if (fnSource_GetPixel
)
1320 for (x
= 0; x
< psurfOff
->SurfObj
.sizlBitmap
.cx
; x
++)
1322 for (y
= 0; y
< psurfOff
->SurfObj
.sizlBitmap
.cy
; y
++)
1324 bAlpha
= ((BYTE
)(fnSource_GetPixel(&psurfOff
->SurfObj
, x
, y
) >> 24) & 0xff);
1332 SURFACE_UnlockSurface(psurfOff
);
1337 diFlags
= DI_NORMAL
;
1340 cxWidth
= ((diFlags
& DI_DEFAULTSIZE
) ?
1341 UserGetSystemMetrics(SM_CXICON
) : IconSize
.cx
);
1344 cyHeight
= ((diFlags
& DI_DEFAULTSIZE
) ?
1345 UserGetSystemMetrics(SM_CYICON
) : IconSize
.cy
);
1347 DoFlickerFree
= (hbrFlickerFreeDraw
&&
1348 (GDI_HANDLE_GET_TYPE(hbrFlickerFreeDraw
) == GDI_OBJECT_TYPE_BRUSH
));
1350 if (DoFlickerFree
|| bAlpha
)
1354 SURFACE
*psurfOff
= NULL
;
1357 r
.bottom
= cyHeight
;
1359 hdcOff
= NtGdiCreateCompatibleDC(hDc
);
1362 DPRINT1("NtGdiCreateCompatibleDC() failed!\n");
1366 hbmOff
= NtGdiCreateCompatibleBitmap(hDc
, cxWidth
, cyHeight
);
1369 DPRINT1("NtGdiCreateCompatibleBitmap() failed!\n");
1373 /* make sure we have a 32 bit offscreen bitmap
1374 otherwise we can't do alpha blending */
1375 psurfOff
= SURFACE_LockSurface(hbmOff
);
1376 if (psurfOff
== NULL
)
1378 DPRINT1("BITMAPOBJ_LockBitmap() failed!\n");
1381 BITMAP_GetObject(psurfOff
, sizeof(BITMAP
), (PVOID
)&bm
);
1383 if (bm
.bmBitsPixel
!= 32)
1386 SURFACE_UnlockSurface(psurfOff
);
1388 hOldOffBmp
= NtGdiSelectBitmap(hdcOff
, hbmOff
);
1391 DPRINT1("NtGdiSelectBitmap() failed!\n");
1397 hOldOffBrush
= NtGdiSelectBrush(hdcOff
, hbrFlickerFreeDraw
);
1400 DPRINT1("NtGdiSelectBrush() failed!\n");
1404 NtGdiPatBlt(hdcOff
, 0, 0, r
.right
, r
.bottom
, PATCOPY
);
1410 if (diFlags
& DI_IMAGE
)
1412 hdcImage
= NtGdiCreateCompatibleDC(hDc
);
1415 DPRINT1("NtGdiCreateCompatibleDC() failed!\n");
1418 hOldImage
= NtGdiSelectBitmap(hdcImage
, (hbmColor
? hbmColor
: hbmMask
));
1421 DPRINT("NtGdiSelectBitmap() failed!\n");
1426 /* If DI_IMAGE flag is specified and hbmMask exists, then always use mask for drawing */
1427 if (diFlags
& DI_MASK
|| (diFlags
& DI_IMAGE
&& hbmMask
))
1429 hdcMask
= NtGdiCreateCompatibleDC(hDc
);
1432 DPRINT1("NtGdiCreateCompatibleDC() failed!\n");
1436 hOldMask
= NtGdiSelectBitmap(hdcMask
, hbmMask
);
1439 DPRINT("NtGdiSelectBitmap() failed!\n");
1444 if (hdcMask
|| hdcImage
)
1446 GreStretchBltMask(hdcOff
,
1447 (DoFlickerFree
|| bAlpha
) ? 0 : xLeft
,
1448 (DoFlickerFree
|| bAlpha
) ? 0 : yTop
,
1451 hdcImage
? hdcImage
: hdcMask
,
1460 hdcImage
? 0 : IconSize
.cy
);
1463 if (hOldMask
) NtGdiSelectBitmap(hdcMask
, hOldMask
);
1464 if (hOldImage
) NtGdiSelectBitmap(hdcImage
, hOldImage
);
1465 if (hdcImage
) NtGdiDeleteObjectApp(hdcImage
);
1466 if (hdcMask
) NtGdiDeleteObjectApp(hdcMask
);
1471 SURFACE
*psurfOff
= NULL
;
1473 BLENDFUNCTION BlendFunc
;
1475 BYTE Red
, Green
, Blue
, Alpha
;
1479 psurfOff
= SURFACE_LockSurface(hbmOff
);
1480 if (psurfOff
== NULL
)
1482 DPRINT1("BITMAPOBJ_LockBitmap() failed!\n");
1485 BITMAP_GetObject(psurfOff
, sizeof(BITMAP
), (PVOID
)&bm
);
1487 pBits
= ExAllocatePoolWithTag(PagedPool
, bm
.bmWidthBytes
* abs(bm
.bmHeight
), TAG_BITMAP
);
1490 DPRINT1("ExAllocatePoolWithTag() failed!\n");
1491 SURFACE_UnlockSurface(psurfOff
);
1496 IntGetBitmapBits(psurfOff
, bm
.bmWidthBytes
* abs(bm
.bmHeight
), pBits
);
1498 /* premultiply with the alpha channel value */
1499 for (i
= 0; i
< cyHeight
; i
++)
1501 for (j
= 0; j
< cxWidth
; j
++)
1503 Pixel
= *(DWORD
*)(pBits
+ Count
);
1505 Alpha
= ((BYTE
)(Pixel
>> 24) & 0xff);
1507 Red
= (((BYTE
)(Pixel
>> 0)) * Alpha
) / 0xff;
1508 Green
= (((BYTE
)(Pixel
>> 8)) * Alpha
) / 0xff;
1509 Blue
= (((BYTE
)(Pixel
>> 16)) * Alpha
) / 0xff;
1511 *(DWORD
*)(pBits
+ Count
) = (DWORD
)(Red
| (Green
<< 8) | (Blue
<< 16) | (Alpha
<< 24));
1513 Count
+= sizeof(DWORD
);
1518 IntSetBitmapBits(psurfOff
, bm
.bmWidthBytes
* abs(bm
.bmHeight
), pBits
);
1519 ExFreePoolWithTag(pBits
, TAG_BITMAP
);
1521 SURFACE_UnlockSurface(psurfOff
);
1523 BlendFunc
.BlendOp
= AC_SRC_OVER
;
1524 BlendFunc
.BlendFlags
= 0;
1525 BlendFunc
.SourceConstantAlpha
= 255;
1526 BlendFunc
.AlphaFormat
= AC_SRC_ALPHA
;
1528 NtGdiAlphaBlend(hDc
, xLeft
, yTop
, cxWidth
, cyHeight
,
1529 hdcOff
, 0, 0, cxWidth
, cyHeight
, BlendFunc
, 0);
1531 else if (DoFlickerFree
)
1533 NtGdiBitBlt(hDc
, xLeft
, yTop
, cxWidth
,
1534 cyHeight
, hdcOff
, 0, 0, SRCCOPY
, 0, 0);
1540 if (DoFlickerFree
|| bAlpha
)
1542 if (hOldOffBmp
) NtGdiSelectBitmap(hdcOff
, hOldOffBmp
);
1543 if (hOldOffBrush
) NtGdiSelectBrush(hdcOff
, hOldOffBrush
);
1544 if (hbmOff
) GreDeleteObject(hbmOff
);
1545 if (hdcOff
) NtGdiDeleteObjectApp(hdcOff
);
1564 HBRUSH hbrFlickerFreeDraw
,
1569 PCURICON_OBJECT pIcon
;
1572 DPRINT("Enter NtUserDrawIconEx\n");
1573 UserEnterExclusive();
1575 if (!(pIcon
= UserGetCurIconObject(hIcon
)))
1577 DPRINT1("UserGetCurIconObject() failed!\n");
1582 Ret
= UserDrawIconEx(hdc
,
1592 UserDereferenceObject(pIcon
);