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
);
502 PUNICODE_STRING lpInstName
, // optional
503 PUNICODE_STRING lpResName
, // optional
504 LPDWORD pbpp
, // optional
508 PCURICON_OBJECT CurIcon
;
509 NTSTATUS Status
= STATUS_SUCCESS
;
513 DPRINT("Enter NtUserGetIconInfo\n");
514 UserEnterExclusive();
518 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
522 if (!(CurIcon
= UserGetCurIconObject(hCurIcon
)))
527 RtlCopyMemory(&ii
, &CurIcon
->IconInfo
, sizeof(ICONINFO
));
530 ii
.hbmMask
= BITMAP_CopyBitmap(CurIcon
->IconInfo
.hbmMask
);
531 ii
.hbmColor
= BITMAP_CopyBitmap(CurIcon
->IconInfo
.hbmColor
);
537 psurfBmp
= SURFACE_LockSurface(CurIcon
->IconInfo
.hbmColor
);
540 colorBpp
= BitsPerFormat(psurfBmp
->SurfObj
.iBitmapFormat
);
541 SURFACE_UnlockSurface(psurfBmp
);
548 ProbeForWrite(IconInfo
, sizeof(ICONINFO
), 1);
549 RtlCopyMemory(IconInfo
, &ii
, sizeof(ICONINFO
));
553 ProbeForWrite(pbpp
, sizeof(DWORD
), 1);
557 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
559 Status
= _SEH2_GetExceptionCode();
563 if (NT_SUCCESS(Status
))
566 SetLastNtError(Status
);
568 UserDereferenceObject(CurIcon
);
571 DPRINT("Leave NtUserGetIconInfo, ret=%i\n", Ret
);
586 PLONG plcx
, // &size.cx
587 PLONG plcy
) // &size.cy
589 PCURICON_OBJECT CurIcon
;
590 NTSTATUS Status
= STATUS_SUCCESS
;
593 DPRINT("Enter NtUserGetIconSize\n");
594 UserEnterExclusive();
596 if (!(CurIcon
= UserGetCurIconObject(hCurIcon
)))
603 ProbeForWrite(plcx
, sizeof(LONG
), 1);
604 RtlCopyMemory(plcx
, &CurIcon
->Size
.cx
, sizeof(LONG
));
605 ProbeForWrite(plcy
, sizeof(LONG
), 1);
606 RtlCopyMemory(plcy
, &CurIcon
->Size
.cy
, sizeof(LONG
));
608 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
610 Status
= _SEH2_GetExceptionCode();
614 if (NT_SUCCESS(Status
))
617 SetLastNtError(Status
); // maybe not, test this
619 UserDereferenceObject(CurIcon
);
622 DPRINT("Leave NtUserGetIconSize, ret=%i\n", bRet
);
633 NtUserGetCursorFrameInfo(
654 PSYSTEM_CURSORINFO CurInfo
;
655 NTSTATUS Status
= STATUS_SUCCESS
;
656 PCURICON_OBJECT CurIcon
;
658 DECLARE_RETURN(BOOL
);
660 DPRINT("Enter NtUserGetCursorInfo\n");
661 UserEnterExclusive();
663 CurInfo
= IntGetSysCursorInfo();
664 CurIcon
= (PCURICON_OBJECT
)CurInfo
->CurrentCursorObject
;
666 SafeCi
.cbSize
= sizeof(CURSORINFO
);
667 SafeCi
.flags
= ((CurInfo
->ShowingCursor
&& CurIcon
) ? CURSOR_SHOWING
: 0);
668 SafeCi
.hCursor
= (CurIcon
? (HCURSOR
)CurIcon
->Self
: (HCURSOR
)0);
670 SafeCi
.ptScreenPos
= gpsi
->ptCursor
;
674 if (pci
->cbSize
== sizeof(CURSORINFO
))
676 ProbeForWrite(pci
, sizeof(CURSORINFO
), 1);
677 RtlCopyMemory(pci
, &SafeCi
, sizeof(CURSORINFO
));
682 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
685 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
687 Status
= _SEH2_GetExceptionCode();
690 if (!NT_SUCCESS(Status
))
692 SetLastNtError(Status
);
698 DPRINT("Leave NtUserGetCursorInfo, ret=%i\n",_ret_
);
712 /* FIXME - check if process has WINSTA_WRITEATTRIBUTES */
713 PSYSTEM_CURSORINFO CurInfo
;
715 PWINDOW_OBJECT DesktopWindow
= NULL
;
716 DECLARE_RETURN(BOOL
);
718 DPRINT("Enter NtUserClipCursor\n");
719 UserEnterExclusive();
721 if (NULL
!= UnsafeRect
&& ! NT_SUCCESS(MmCopyFromCaller(&Rect
, UnsafeRect
, sizeof(RECT
))))
723 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
727 CurInfo
= IntGetSysCursorInfo();
729 DesktopWindow
= UserGetDesktopWindow();
731 if ((Rect
.right
> Rect
.left
) && (Rect
.bottom
> Rect
.top
)
732 && DesktopWindow
&& UnsafeRect
!= NULL
)
735 CurInfo
->CursorClipInfo
.IsClipped
= TRUE
;
736 CurInfo
->CursorClipInfo
.Left
= max(Rect
.left
, DesktopWindow
->Wnd
->rcWindow
.left
);
737 CurInfo
->CursorClipInfo
.Top
= max(Rect
.top
, DesktopWindow
->Wnd
->rcWindow
.top
);
738 CurInfo
->CursorClipInfo
.Right
= min(Rect
.right
, DesktopWindow
->Wnd
->rcWindow
.right
);
739 CurInfo
->CursorClipInfo
.Bottom
= min(Rect
.bottom
, DesktopWindow
->Wnd
->rcWindow
.bottom
);
741 UserSetCursorPos(gpsi
->ptCursor
.x
, gpsi
->ptCursor
.y
, FALSE
);
746 CurInfo
->CursorClipInfo
.IsClipped
= FALSE
;
750 DPRINT("Leave NtUserClipCursor, ret=%i\n",_ret_
);
765 PCURICON_OBJECT CurIcon
;
767 DECLARE_RETURN(BOOL
);
769 DPRINT("Enter NtUserDestroyCursorIcon\n");
770 UserEnterExclusive();
772 if (!(CurIcon
= UserGetCurIconObject(hCurIcon
)))
777 ret
= IntDestroyCurIconObject(CurIcon
, FALSE
);
778 /* Note: IntDestroyCurIconObject will remove our reference for us! */
783 DPRINT("Leave NtUserDestroyCursorIcon, ret=%i\n",_ret_
);
794 NtUserFindExistingCursorIcon(
800 PCURICON_OBJECT CurIcon
;
801 HANDLE Ret
= (HANDLE
)0;
802 DECLARE_RETURN(HICON
);
804 DPRINT("Enter NtUserFindExistingCursorIcon\n");
805 UserEnterExclusive();
807 CurIcon
= IntFindExistingCurIconObject(hModule
, hRsrc
, cx
, cy
);
812 // IntReleaseCurIconObject(CurIcon);//faxme: is this correct? does IntFindExistingCurIconObject add a ref?
816 SetLastWin32Error(ERROR_INVALID_CURSOR_HANDLE
);
820 DPRINT("Leave NtUserFindExistingCursorIcon, ret=%i\n",_ret_
);
834 /* FIXME - check if process has WINSTA_READATTRIBUTES */
835 PSYSTEM_CURSORINFO CurInfo
;
838 DECLARE_RETURN(BOOL
);
840 DPRINT("Enter NtUserGetClipCursor\n");
841 UserEnterExclusive();
846 CurInfo
= IntGetSysCursorInfo();
847 if (CurInfo
->CursorClipInfo
.IsClipped
)
849 Rect
.left
= CurInfo
->CursorClipInfo
.Left
;
850 Rect
.top
= CurInfo
->CursorClipInfo
.Top
;
851 Rect
.right
= CurInfo
->CursorClipInfo
.Right
;
852 Rect
.bottom
= CurInfo
->CursorClipInfo
.Bottom
;
858 Rect
.right
= UserGetSystemMetrics(SM_CXSCREEN
);
859 Rect
.bottom
= UserGetSystemMetrics(SM_CYSCREEN
);
862 Status
= MmCopyToCaller(lpRect
, &Rect
, sizeof(RECT
));
863 if (!NT_SUCCESS(Status
))
865 SetLastNtError(Status
);
872 DPRINT("Leave NtUserGetClipCursor, ret=%i\n",_ret_
);
886 PCURICON_OBJECT CurIcon
;
888 DECLARE_RETURN(HCURSOR
);
890 DPRINT("Enter NtUserSetCursor\n");
891 UserEnterExclusive();
895 if (!(CurIcon
= UserGetCurIconObject(hCursor
)))
905 OldCursor
= UserSetCursor(CurIcon
, FALSE
);
909 UserDereferenceObject(CurIcon
);
915 DPRINT("Leave NtUserSetCursor, ret=%i\n",_ret_
);
926 NtUserSetCursorContents(
928 PICONINFO UnsafeIconInfo
)
930 PCURICON_OBJECT CurIcon
;
935 DECLARE_RETURN(BOOL
);
937 DPRINT("Enter NtUserSetCursorContents\n");
938 UserEnterExclusive();
940 if (!(CurIcon
= UserGetCurIconObject(hCurIcon
)))
946 Status
= MmCopyFromCaller(&IconInfo
, UnsafeIconInfo
, sizeof(ICONINFO
));
947 if (!NT_SUCCESS(Status
))
949 SetLastNtError(Status
);
953 /* Delete old bitmaps */
954 if ((CurIcon
->IconInfo
.hbmColor
)
955 && (CurIcon
->IconInfo
.hbmColor
!= IconInfo
.hbmColor
))
957 GreDeleteObject(CurIcon
->IconInfo
.hbmColor
);
959 if ((CurIcon
->IconInfo
.hbmMask
)
960 && (CurIcon
->IconInfo
.hbmMask
!= IconInfo
.hbmMask
))
962 GreDeleteObject(CurIcon
->IconInfo
.hbmMask
);
965 /* Copy new IconInfo field */
966 CurIcon
->IconInfo
= IconInfo
;
968 psurfBmp
= SURFACE_LockSurface(CurIcon
->IconInfo
.hbmColor
);
971 CurIcon
->Size
.cx
= psurfBmp
->SurfObj
.sizlBitmap
.cx
;
972 CurIcon
->Size
.cy
= psurfBmp
->SurfObj
.sizlBitmap
.cy
;
973 SURFACE_UnlockSurface(psurfBmp
);
974 GDIOBJ_SetOwnership(CurIcon
->IconInfo
.hbmColor
, NULL
);
978 psurfBmp
= SURFACE_LockSurface(CurIcon
->IconInfo
.hbmMask
);
982 CurIcon
->Size
.cx
= psurfBmp
->SurfObj
.sizlBitmap
.cx
;
983 CurIcon
->Size
.cy
= psurfBmp
->SurfObj
.sizlBitmap
.cy
/ 2;
985 SURFACE_UnlockSurface(psurfBmp
);
986 GDIOBJ_SetOwnership(CurIcon
->IconInfo
.hbmMask
, NULL
);
995 UserDereferenceObject(CurIcon
);
1000 DPRINT("Leave NtUserSetCursorContents, ret=%i\n",_ret_
);
1012 NtUserSetCursorIconData(
1015 PUNICODE_STRING pstrResName
,
1016 PICONINFO pIconInfo
)
1018 PCURICON_OBJECT CurIcon
;
1020 NTSTATUS Status
= STATUS_SUCCESS
;
1022 DECLARE_RETURN(BOOL
);
1024 DPRINT("Enter NtUserSetCursorIconData\n");
1025 UserEnterExclusive();
1027 if (!(CurIcon
= UserGetCurIconObject(Handle
)))
1032 CurIcon
->hModule
= hModule
;
1033 CurIcon
->hRsrc
= NULL
; //hRsrc;
1034 CurIcon
->hGroupRsrc
= NULL
; //hGroupRsrc;
1038 ProbeForRead(pIconInfo
, sizeof(ICONINFO
), 1);
1039 RtlCopyMemory(&CurIcon
->IconInfo
, pIconInfo
, sizeof(ICONINFO
));
1041 CurIcon
->IconInfo
.hbmMask
= BITMAP_CopyBitmap(pIconInfo
->hbmMask
);
1042 CurIcon
->IconInfo
.hbmColor
= BITMAP_CopyBitmap(pIconInfo
->hbmColor
);
1044 if (CurIcon
->IconInfo
.hbmColor
)
1046 if ((psurfBmp
= SURFACE_LockSurface(CurIcon
->IconInfo
.hbmColor
)))
1048 CurIcon
->Size
.cx
= psurfBmp
->SurfObj
.sizlBitmap
.cx
;
1049 CurIcon
->Size
.cy
= psurfBmp
->SurfObj
.sizlBitmap
.cy
;
1050 SURFACE_UnlockSurface(psurfBmp
);
1051 GDIOBJ_SetOwnership(GdiHandleTable
, CurIcon
->IconInfo
.hbmMask
, NULL
);
1054 if (CurIcon
->IconInfo
.hbmMask
)
1056 if (CurIcon
->IconInfo
.hbmColor
== NULL
)
1058 if ((psurfBmp
= SURFACE_LockSurface(CurIcon
->IconInfo
.hbmMask
)))
1060 CurIcon
->Size
.cx
= psurfBmp
->SurfObj
.sizlBitmap
.cx
;
1061 CurIcon
->Size
.cy
= psurfBmp
->SurfObj
.sizlBitmap
.cy
;
1062 SURFACE_UnlockSurface(psurfBmp
);
1065 GDIOBJ_SetOwnership(GdiHandleTable
, CurIcon
->IconInfo
.hbmMask
, NULL
);
1068 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1070 Status
= _SEH2_GetExceptionCode();
1074 if (!NT_SUCCESS(Status
))
1075 SetLastNtError(Status
);
1079 UserDereferenceObject(CurIcon
);
1083 DPRINT("Leave NtUserSetCursorIconData, ret=%i\n",_ret_
);
1090 NtUserSetCursorIconData(
1098 PCURICON_OBJECT CurIcon
;
1102 DECLARE_RETURN(BOOL
);
1104 DPRINT("Enter NtUserSetCursorIconData\n");
1105 UserEnterExclusive();
1107 if (!(CurIcon
= UserGetCurIconObject(hCurIcon
)))
1112 CurIcon
->hModule
= hModule
;
1113 CurIcon
->hRsrc
= hRsrc
;
1114 CurIcon
->hGroupRsrc
= hGroupRsrc
;
1119 Status
= MmCopyFromCaller(&CurIcon
->IconInfo
.fIcon
, fIcon
, sizeof(BOOL
));
1120 if (!NT_SUCCESS(Status
))
1122 SetLastNtError(Status
);
1134 Status
= MmCopyFromCaller(&SafeHotspot
, Hotspot
, sizeof(POINT
));
1135 if (NT_SUCCESS(Status
))
1137 CurIcon
->IconInfo
.xHotspot
= SafeHotspot
.x
;
1138 CurIcon
->IconInfo
.yHotspot
= SafeHotspot
.y
;
1143 SetLastNtError(Status
);
1146 if (!fIcon
&& !Hotspot
)
1154 /* This icon is shared now */
1155 GDIOBJ_SetOwnership(CurIcon
->IconInfo
.hbmMask
, NULL
);
1156 if(CurIcon
->IconInfo
.hbmColor
)
1158 GDIOBJ_SetOwnership(CurIcon
->IconInfo
.hbmColor
, NULL
);
1161 UserDereferenceObject(CurIcon
);
1166 DPRINT("Leave NtUserSetCursorIconData, ret=%i\n",_ret_
);
1177 NtUserSetSystemCursor(
1189 PCURICON_OBJECT pIcon
,
1193 HBRUSH hbrFlickerFreeDraw
,
1197 HBITMAP hbmMask
, hbmColor
;
1198 BITMAP bmpMask
, bmpColor
;
1203 HGDIOBJ hOldOffBrush
= 0;
1204 HGDIOBJ hOldOffBmp
= 0;
1207 HGDIOBJ hOldMask
= NULL
;
1209 HGDIOBJ hOldImage
= NULL
;
1210 BOOL bAlpha
= FALSE
;
1212 hbmMask
= pIcon
->IconInfo
.hbmMask
;
1213 hbmColor
= pIcon
->IconInfo
.hbmColor
;
1216 DPRINT1("NtUserDrawIconEx: istepIfAniCur is not supported!\n");
1218 if (!hbmMask
|| !IntGdiGetObject(hbmMask
, sizeof(BITMAP
), (PVOID
)&bmpMask
))
1223 if (hbmColor
&& !IntGdiGetObject(hbmColor
, sizeof(BITMAP
), (PVOID
)&bmpColor
))
1230 IconSize
.cx
= bmpColor
.bmWidth
;
1231 IconSize
.cy
= bmpColor
.bmHeight
;
1235 IconSize
.cx
= bmpMask
.bmWidth
;
1236 IconSize
.cy
= bmpMask
.bmHeight
/ 2;
1239 /* NtGdiCreateCompatibleBitmap will create a monochrome bitmap
1240 when cxWidth or cyHeight is 0 */
1241 if ((bmpColor
.bmBitsPixel
== 32) && (cxWidth
!= 0) && (cyHeight
!= 0))
1243 SURFACE
*psurfOff
= NULL
;
1244 PFN_DIB_GetPixel fnSource_GetPixel
= NULL
;
1247 /* In order to correctly display 32 bit icons Windows first scans the image,
1248 because information about transparency is not stored in any image's headers */
1249 psurfOff
= SURFACE_LockSurface(hbmColor
? hbmColor
: hbmMask
);
1252 fnSource_GetPixel
= DibFunctionsForBitmapFormat
[psurfOff
->SurfObj
.iBitmapFormat
].DIB_GetPixel
;
1253 if (fnSource_GetPixel
)
1255 for (x
= 0; x
< psurfOff
->SurfObj
.sizlBitmap
.cx
; x
++)
1257 for (y
= 0; y
< psurfOff
->SurfObj
.sizlBitmap
.cy
; y
++)
1259 bAlpha
= ((BYTE
)(fnSource_GetPixel(&psurfOff
->SurfObj
, x
, y
) >> 24) & 0xff);
1267 SURFACE_UnlockSurface(psurfOff
);
1272 diFlags
= DI_NORMAL
;
1275 cxWidth
= ((diFlags
& DI_DEFAULTSIZE
) ?
1276 UserGetSystemMetrics(SM_CXICON
) : IconSize
.cx
);
1279 cyHeight
= ((diFlags
& DI_DEFAULTSIZE
) ?
1280 UserGetSystemMetrics(SM_CYICON
) : IconSize
.cy
);
1282 DoFlickerFree
= (hbrFlickerFreeDraw
&&
1283 (GDI_HANDLE_GET_TYPE(hbrFlickerFreeDraw
) == GDI_OBJECT_TYPE_BRUSH
));
1285 if (DoFlickerFree
|| bAlpha
)
1289 SURFACE
*psurfOff
= NULL
;
1292 r
.bottom
= cyHeight
;
1294 hdcOff
= NtGdiCreateCompatibleDC(hDc
);
1297 DPRINT1("NtGdiCreateCompatibleDC() failed!\n");
1301 hbmOff
= NtGdiCreateCompatibleBitmap(hDc
, cxWidth
, cyHeight
);
1304 DPRINT1("NtGdiCreateCompatibleBitmap() failed!\n");
1308 /* make sure we have a 32 bit offscreen bitmap
1309 otherwise we can't do alpha blending */
1310 psurfOff
= SURFACE_LockSurface(hbmOff
);
1311 if (psurfOff
== NULL
)
1313 DPRINT1("BITMAPOBJ_LockBitmap() failed!\n");
1316 BITMAP_GetObject(psurfOff
, sizeof(BITMAP
), (PVOID
)&bm
);
1318 if (bm
.bmBitsPixel
!= 32)
1321 SURFACE_UnlockSurface(psurfOff
);
1323 hOldOffBmp
= NtGdiSelectBitmap(hdcOff
, hbmOff
);
1326 DPRINT1("NtGdiSelectBitmap() failed!\n");
1332 hOldOffBrush
= NtGdiSelectBrush(hdcOff
, hbrFlickerFreeDraw
);
1335 DPRINT1("NtGdiSelectBrush() failed!\n");
1339 NtGdiPatBlt(hdcOff
, 0, 0, r
.right
, r
.bottom
, PATCOPY
);
1345 if (diFlags
& DI_IMAGE
)
1347 hdcImage
= NtGdiCreateCompatibleDC(hDc
);
1350 DPRINT1("NtGdiCreateCompatibleDC() failed!\n");
1353 hOldImage
= NtGdiSelectBitmap(hdcImage
, (hbmColor
? hbmColor
: hbmMask
));
1356 DPRINT("NtGdiSelectBitmap() failed!\n");
1361 /* If DI_IMAGE flag is specified and hbmMask exists, then always use mask for drawing */
1362 if (diFlags
& DI_MASK
|| (diFlags
& DI_IMAGE
&& hbmMask
))
1364 hdcMask
= NtGdiCreateCompatibleDC(hDc
);
1367 DPRINT1("NtGdiCreateCompatibleDC() failed!\n");
1371 hOldMask
= NtGdiSelectBitmap(hdcMask
, hbmMask
);
1374 DPRINT("NtGdiSelectBitmap() failed!\n");
1379 if (hdcMask
|| hdcImage
)
1381 GreStretchBltMask(hdcOff
,
1382 (DoFlickerFree
|| bAlpha
) ? 0 : xLeft
,
1383 (DoFlickerFree
|| bAlpha
) ? 0 : yTop
,
1386 hdcImage
? hdcImage
: hdcMask
,
1393 bAlpha
? 0 : hdcMask
,
1395 hdcImage
? 0 : IconSize
.cy
);
1398 if (hOldMask
) NtGdiSelectBitmap(hdcMask
, hOldMask
);
1399 if (hOldImage
) NtGdiSelectBitmap(hdcImage
, hOldImage
);
1400 if (hdcImage
) NtGdiDeleteObjectApp(hdcImage
);
1401 if (hdcMask
) NtGdiDeleteObjectApp(hdcMask
);
1406 SURFACE
*psurfOff
= NULL
;
1408 BLENDFUNCTION BlendFunc
;
1410 BYTE Red
, Green
, Blue
, Alpha
;
1414 psurfOff
= SURFACE_LockSurface(hbmOff
);
1415 if (psurfOff
== NULL
)
1417 DPRINT1("BITMAPOBJ_LockBitmap() failed!\n");
1420 BITMAP_GetObject(psurfOff
, sizeof(BITMAP
), (PVOID
)&bm
);
1422 pBits
= ExAllocatePoolWithTag(PagedPool
, bm
.bmWidthBytes
* abs(bm
.bmHeight
), TAG_BITMAP
);
1425 DPRINT1("ExAllocatePoolWithTag() failed!\n");
1426 SURFACE_UnlockSurface(psurfOff
);
1431 IntGetBitmapBits(psurfOff
, bm
.bmWidthBytes
* abs(bm
.bmHeight
), pBits
);
1433 /* premultiply with the alpha channel value */
1434 for (i
= 0; i
< cyHeight
; i
++)
1436 for (j
= 0; j
< cxWidth
; j
++)
1438 Pixel
= *(DWORD
*)(pBits
+ Count
);
1440 Alpha
= ((BYTE
)(Pixel
>> 24) & 0xff);
1442 Red
= (((BYTE
)(Pixel
>> 0)) * Alpha
) / 0xff;
1443 Green
= (((BYTE
)(Pixel
>> 8)) * Alpha
) / 0xff;
1444 Blue
= (((BYTE
)(Pixel
>> 16)) * Alpha
) / 0xff;
1446 *(DWORD
*)(pBits
+ Count
) = (DWORD
)(Red
| (Green
<< 8) | (Blue
<< 16) | (Alpha
<< 24));
1448 Count
+= sizeof(DWORD
);
1453 IntSetBitmapBits(psurfOff
, bm
.bmWidthBytes
* abs(bm
.bmHeight
), pBits
);
1454 ExFreePoolWithTag(pBits
, TAG_BITMAP
);
1456 SURFACE_UnlockSurface(psurfOff
);
1458 BlendFunc
.BlendOp
= AC_SRC_OVER
;
1459 BlendFunc
.BlendFlags
= 0;
1460 BlendFunc
.SourceConstantAlpha
= 255;
1461 BlendFunc
.AlphaFormat
= AC_SRC_ALPHA
;
1463 NtGdiAlphaBlend(hDc
, xLeft
, yTop
, cxWidth
, cyHeight
,
1464 hdcOff
, 0, 0, cxWidth
, cyHeight
, BlendFunc
, 0);
1466 else if (DoFlickerFree
)
1468 NtGdiBitBlt(hDc
, xLeft
, yTop
, cxWidth
,
1469 cyHeight
, hdcOff
, 0, 0, SRCCOPY
, 0, 0);
1475 if (DoFlickerFree
|| bAlpha
)
1477 if (hOldOffBmp
) NtGdiSelectBitmap(hdcOff
, hOldOffBmp
);
1478 if (hOldOffBrush
) NtGdiSelectBrush(hdcOff
, hOldOffBrush
);
1479 if (hbmOff
) GreDeleteObject(hbmOff
);
1480 if (hdcOff
) NtGdiDeleteObjectApp(hdcOff
);
1499 HBRUSH hbrFlickerFreeDraw
,
1501 BOOL bMetaHDC
, // When TRUE, GDI functions need to be handled in User32!
1504 PCURICON_OBJECT pIcon
;
1507 DPRINT("Enter NtUserDrawIconEx\n");
1508 UserEnterExclusive();
1510 if (!(pIcon
= UserGetCurIconObject(hIcon
)))
1512 DPRINT1("UserGetCurIconObject() failed!\n");
1517 Ret
= UserDrawIconEx(hdc
,
1527 UserDereferenceObject(pIcon
);