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
.bClipped
= 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;
113 CurInfo
= IntGetSysCursorInfo();
115 OldCursor
= CurInfo
->CurrentCursorObject
;
118 hOldCursor
= (HCURSOR
)OldCursor
->Self
;
121 /* Is the new cursor the same as the old cursor? */
122 if (OldCursor
== NewCursor
)
124 /* Nothing to to do in this case */
128 /* Get the screen DC */
129 if(!(hdcScreen
= IntGetScreenDC()))
134 /* Do we have a new cursor? */
137 UserReferenceObject(NewCursor
);
139 CurInfo
->ShowingCursor
= 1;
140 CurInfo
->CurrentCursorObject
= NewCursor
;
142 /* Call GDI to set the new screen cursor */
143 GreSetPointerShape(hdcScreen
,
144 NewCursor
->IconInfo
.hbmMask
,
145 NewCursor
->IconInfo
.hbmColor
,
146 NewCursor
->IconInfo
.xHotspot
,
147 NewCursor
->IconInfo
.yHotspot
,
155 /* Check if were diplaying a cursor */
156 if (OldCursor
&& CurInfo
->ShowingCursor
)
158 /* Remove the cursor */
159 GreMovePointer(hdcScreen
, -1, -1);
160 DPRINT("Removing pointer!\n");
163 CurInfo
->CurrentCursorObject
= NULL
;
164 CurInfo
->ShowingCursor
= 0;
167 /* OldCursor is not in use anymore */
170 UserDereferenceObject(OldCursor
);
173 /* Return handle of the old cursor */
177 BOOL
UserSetCursorPos( INT x
, INT y
, BOOL SendMouseMoveMsg
)
180 PSYSTEM_CURSORINFO CurInfo
;
186 if(!(hDC
= IntGetScreenDC()))
191 if(!(DesktopWindow
= UserGetDesktopWindow()))
196 CurInfo
= IntGetSysCursorInfo();
198 /* Clip cursor position */
199 if (!CurInfo
->bClipped
)
200 rcClip
= DesktopWindow
->rcClient
;
202 rcClip
= CurInfo
->rcClip
;
204 if(x
>= rcClip
.right
) x
= rcClip
.right
- 1;
205 if(x
< rcClip
.left
) x
= rcClip
.left
;
206 if(y
>= rcClip
.bottom
) y
= rcClip
.bottom
- 1;
207 if(y
< rcClip
.top
) y
= rcClip
.top
;
213 if (SendMouseMoveMsg
)
215 /* Generate a mouse move message */
216 Msg
.message
= WM_MOUSEMOVE
;
217 Msg
.wParam
= CurInfo
->ButtonsDown
;
218 Msg
.lParam
= MAKELPARAM(x
, y
);
220 co_MsqInsertMouseMessage(&Msg
);
223 /* Store the new cursor position */
226 /* Move the mouse pointer */
227 GreMovePointer(hDC
, x
, y
);
232 /* Called from NtUserCallOneParam with Routine ONEPARAM_ROUTINE_SHOWCURSOR
233 * User32 macro NtUserShowCursor */
234 int UserShowCursor(BOOL bShow
)
236 PSYSTEM_CURSORINFO CurInfo
= IntGetSysCursorInfo();
239 if (!(hdcScreen
= IntGetScreenDC()))
241 return 0; /* No mouse */
246 /* Check if were diplaying a cursor */
247 if (CurInfo
->ShowingCursor
== 1)
249 /* Remove the pointer */
250 GreMovePointer(hdcScreen
, -1, -1);
251 DPRINT("Removing pointer!\n");
253 CurInfo
->ShowingCursor
--;
257 if (CurInfo
->ShowingCursor
== 0)
260 GreMovePointer(hdcScreen
, gpsi
->ptCursor
.x
, gpsi
->ptCursor
.y
);
262 CurInfo
->ShowingCursor
++;
265 return CurInfo
->ShowingCursor
;
269 * We have to register that this object is in use by the current
270 * process. The only way to do that seems to be to walk the list
271 * of cursor/icon objects starting at W32Process->CursorIconListHead.
272 * If the object is already present in the list, we don't have to do
273 * anything, if it's not present we add it and inc the ProcessCount
274 * in the object. Having to walk the list kind of sucks, but that's
277 static BOOLEAN FASTCALL
278 ReferenceCurIconByProcess(PCURICON_OBJECT CurIcon
)
280 PPROCESSINFO Win32Process
;
281 PCURICON_PROCESS Current
;
283 Win32Process
= PsGetCurrentProcessWin32Process();
285 LIST_FOR_EACH(Current
, &CurIcon
->ProcessList
, CURICON_PROCESS
, ListEntry
)
287 if (Current
->Process
== Win32Process
)
289 /* Already registered for this process */
294 /* Not registered yet */
295 Current
= ExAllocateFromPagedLookasideList(&gProcessLookasideList
);
300 InsertHeadList(&CurIcon
->ProcessList
, &Current
->ListEntry
);
301 Current
->Process
= Win32Process
;
306 PCURICON_OBJECT FASTCALL
307 IntFindExistingCurIconObject(HMODULE hModule
,
308 HRSRC hRsrc
, LONG cx
, LONG cy
)
310 PCURICON_OBJECT CurIcon
;
312 LIST_FOR_EACH(CurIcon
, &gCurIconList
, CURICON_OBJECT
, ListEntry
)
315 // if(NT_SUCCESS(UserReferenceObjectByPointer(Object, otCursorIcon))) //<- huh????
316 // UserReferenceObject( CurIcon);
318 if ((CurIcon
->hModule
== hModule
) && (CurIcon
->hRsrc
== hRsrc
))
320 if (cx
&& ((cx
!= CurIcon
->Size
.cx
) || (cy
!= CurIcon
->Size
.cy
)))
322 // UserDereferenceObject(CurIcon);
325 if (! ReferenceCurIconByProcess(CurIcon
))
333 // UserDereferenceObject(CurIcon);
341 IntCreateCurIconHandle()
343 PCURICON_OBJECT CurIcon
;
346 CurIcon
= UserCreateObject(gHandleTable
, NULL
, &hCurIcon
, otCursorIcon
, sizeof(CURICON_OBJECT
));
350 SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY
);
354 CurIcon
->Self
= hCurIcon
;
355 InitializeListHead(&CurIcon
->ProcessList
);
357 if (! ReferenceCurIconByProcess(CurIcon
))
359 DPRINT1("Failed to add process\n");
360 UserDeleteObject(hCurIcon
, otCursorIcon
);
361 UserDereferenceObject(CurIcon
);
365 InsertHeadList(&gCurIconList
, &CurIcon
->ListEntry
);
371 IntDestroyCurIconObject(PCURICON_OBJECT CurIcon
, BOOL ProcessCleanup
)
373 PSYSTEM_CURSORINFO CurInfo
;
374 HBITMAP bmpMask
, bmpColor
;
376 PCURICON_PROCESS Current
= NULL
;
377 PPROCESSINFO W32Process
= PsGetCurrentProcessWin32Process();
379 /* Private objects can only be destroyed by their own process */
380 if (NULL
== CurIcon
->hModule
)
382 ASSERT(CurIcon
->ProcessList
.Flink
->Flink
== &CurIcon
->ProcessList
);
383 Current
= CONTAINING_RECORD(CurIcon
->ProcessList
.Flink
, CURICON_PROCESS
, ListEntry
);
384 if (Current
->Process
!= W32Process
)
386 DPRINT1("Trying to destroy private icon/cursor of another process\n");
390 else if (! ProcessCleanup
)
392 DPRINT("Trying to destroy shared icon/cursor\n");
396 /* Now find this process in the list of processes referencing this object and
397 remove it from that list */
398 LIST_FOR_EACH(Current
, &CurIcon
->ProcessList
, CURICON_PROCESS
, ListEntry
)
400 if (Current
->Process
== W32Process
)
402 RemoveEntryList(&Current
->ListEntry
);
407 ExFreeToPagedLookasideList(&gProcessLookasideList
, Current
);
409 /* If there are still processes referencing this object we can't destroy it yet */
410 if (! IsListEmpty(&CurIcon
->ProcessList
))
416 if (! ProcessCleanup
)
418 RemoveEntryList(&CurIcon
->ListEntry
);
421 CurInfo
= IntGetSysCursorInfo();
423 if (CurInfo
->CurrentCursorObject
== CurIcon
)
425 /* Hide the cursor if we're destroying the current cursor */
426 UserSetCursor(NULL
, TRUE
);
429 bmpMask
= CurIcon
->IconInfo
.hbmMask
;
430 bmpColor
= CurIcon
->IconInfo
.hbmColor
;
435 GDIOBJ_SetOwnership(bmpMask
, PsGetCurrentProcess());
436 GreDeleteObject(bmpMask
);
437 CurIcon
->IconInfo
.hbmMask
= NULL
;
441 GDIOBJ_SetOwnership(bmpColor
, PsGetCurrentProcess());
442 GreDeleteObject(bmpColor
);
443 CurIcon
->IconInfo
.hbmColor
= NULL
;
446 /* We were given a pointer, no need to keep the reference anylonger! */
447 UserDereferenceObject(CurIcon
);
448 Ret
= UserDeleteObject(CurIcon
->Self
, otCursorIcon
);
454 IntCleanupCurIcons(struct _EPROCESS
*Process
, PPROCESSINFO Win32Process
)
456 PCURICON_OBJECT CurIcon
, tmp
;
457 PCURICON_PROCESS ProcessData
;
459 LIST_FOR_EACH_SAFE(CurIcon
, tmp
, &gCurIconList
, CURICON_OBJECT
, ListEntry
)
461 UserReferenceObject(CurIcon
);
462 // if(NT_SUCCESS(UserReferenceObjectByPointer(Object, otCursorIcon)))
464 LIST_FOR_EACH(ProcessData
, &CurIcon
->ProcessList
, CURICON_PROCESS
, ListEntry
)
466 if (Win32Process
== ProcessData
->Process
)
468 RemoveEntryList(&CurIcon
->ListEntry
);
469 IntDestroyCurIconObject(CurIcon
, TRUE
);
475 // UserDereferenceObject(Object);
480 UserDereferenceObject(CurIcon
);
495 PUNICODE_STRING lpInstName
, // optional
496 PUNICODE_STRING lpResName
, // optional
497 LPDWORD pbpp
, // optional
501 PCURICON_OBJECT CurIcon
;
502 NTSTATUS Status
= STATUS_SUCCESS
;
506 DPRINT("Enter NtUserGetIconInfo\n");
507 UserEnterExclusive();
511 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
515 if (!(CurIcon
= UserGetCurIconObject(hCurIcon
)))
520 RtlCopyMemory(&ii
, &CurIcon
->IconInfo
, sizeof(ICONINFO
));
523 ii
.hbmMask
= BITMAP_CopyBitmap(CurIcon
->IconInfo
.hbmMask
);
524 ii
.hbmColor
= BITMAP_CopyBitmap(CurIcon
->IconInfo
.hbmColor
);
530 psurfBmp
= SURFACE_LockSurface(CurIcon
->IconInfo
.hbmColor
);
533 colorBpp
= BitsPerFormat(psurfBmp
->SurfObj
.iBitmapFormat
);
534 SURFACE_UnlockSurface(psurfBmp
);
541 ProbeForWrite(IconInfo
, sizeof(ICONINFO
), 1);
542 RtlCopyMemory(IconInfo
, &ii
, sizeof(ICONINFO
));
546 ProbeForWrite(pbpp
, sizeof(DWORD
), 1);
550 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
552 Status
= _SEH2_GetExceptionCode();
556 if (NT_SUCCESS(Status
))
559 SetLastNtError(Status
);
561 UserDereferenceObject(CurIcon
);
564 DPRINT("Leave NtUserGetIconInfo, ret=%i\n", Ret
);
579 PLONG plcx
, // &size.cx
580 PLONG plcy
) // &size.cy
582 PCURICON_OBJECT CurIcon
;
583 NTSTATUS Status
= STATUS_SUCCESS
;
586 DPRINT("Enter NtUserGetIconSize\n");
587 UserEnterExclusive();
589 if (!(CurIcon
= UserGetCurIconObject(hCurIcon
)))
596 ProbeForWrite(plcx
, sizeof(LONG
), 1);
597 RtlCopyMemory(plcx
, &CurIcon
->Size
.cx
, sizeof(LONG
));
598 ProbeForWrite(plcy
, sizeof(LONG
), 1);
599 RtlCopyMemory(plcy
, &CurIcon
->Size
.cy
, sizeof(LONG
));
601 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
603 Status
= _SEH2_GetExceptionCode();
607 if (NT_SUCCESS(Status
))
610 SetLastNtError(Status
); // maybe not, test this
612 UserDereferenceObject(CurIcon
);
615 DPRINT("Leave NtUserGetIconSize, ret=%i\n", bRet
);
626 NtUserGetCursorFrameInfo(
647 PSYSTEM_CURSORINFO CurInfo
;
648 NTSTATUS Status
= STATUS_SUCCESS
;
649 PCURICON_OBJECT CurIcon
;
651 DECLARE_RETURN(BOOL
);
653 DPRINT("Enter NtUserGetCursorInfo\n");
654 UserEnterExclusive();
656 CurInfo
= IntGetSysCursorInfo();
657 CurIcon
= (PCURICON_OBJECT
)CurInfo
->CurrentCursorObject
;
659 SafeCi
.cbSize
= sizeof(CURSORINFO
);
660 SafeCi
.flags
= ((CurInfo
->ShowingCursor
&& CurIcon
) ? CURSOR_SHOWING
: 0);
661 SafeCi
.hCursor
= (CurIcon
? (HCURSOR
)CurIcon
->Self
: (HCURSOR
)0);
663 SafeCi
.ptScreenPos
= gpsi
->ptCursor
;
667 if (pci
->cbSize
== sizeof(CURSORINFO
))
669 ProbeForWrite(pci
, sizeof(CURSORINFO
), 1);
670 RtlCopyMemory(pci
, &SafeCi
, sizeof(CURSORINFO
));
675 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
678 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
680 Status
= _SEH2_GetExceptionCode();
683 if (!NT_SUCCESS(Status
))
685 SetLastNtError(Status
);
691 DPRINT("Leave NtUserGetCursorInfo, ret=%i\n",_ret_
);
701 /* FIXME - check if process has WINSTA_WRITEATTRIBUTES */
702 PSYSTEM_CURSORINFO CurInfo
;
703 PWND DesktopWindow
= NULL
;
705 CurInfo
= IntGetSysCursorInfo();
707 DesktopWindow
= UserGetDesktopWindow();
710 (prcl
->right
> prcl
->left
) &&
711 (prcl
->bottom
> prcl
->top
) &&
712 DesktopWindow
!= NULL
)
714 CurInfo
->bClipped
= TRUE
;
715 RECTL_bIntersectRect(&CurInfo
->rcClip
, prcl
, &DesktopWindow
->rcWindow
);
716 UserSetCursorPos(gpsi
->ptCursor
.x
, gpsi
->ptCursor
.y
, FALSE
);
720 CurInfo
->bClipped
= FALSE
;
741 /* Probe and copy rect */
742 ProbeForRead(prcl
, sizeof(RECTL
), 1);
745 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
747 SetLastWin32Error(ERROR_INVALID_PARAMETER
);
748 _SEH2_YIELD(return FALSE
;)
755 UserEnterExclusive();
757 /* Call the internal function */
758 bResult
= UserClipCursor(prcl
);
775 PCURICON_OBJECT CurIcon
;
777 DECLARE_RETURN(BOOL
);
779 DPRINT("Enter NtUserDestroyCursorIcon\n");
780 UserEnterExclusive();
782 if (!(CurIcon
= UserGetCurIconObject(hCurIcon
)))
787 ret
= IntDestroyCurIconObject(CurIcon
, FALSE
);
788 /* Note: IntDestroyCurIconObject will remove our reference for us! */
793 DPRINT("Leave NtUserDestroyCursorIcon, ret=%i\n",_ret_
);
804 NtUserFindExistingCursorIcon(
810 PCURICON_OBJECT CurIcon
;
811 HANDLE Ret
= (HANDLE
)0;
812 DECLARE_RETURN(HICON
);
814 DPRINT("Enter NtUserFindExistingCursorIcon\n");
815 UserEnterExclusive();
817 CurIcon
= IntFindExistingCurIconObject(hModule
, hRsrc
, cx
, cy
);
822 // IntReleaseCurIconObject(CurIcon);//faxme: is this correct? does IntFindExistingCurIconObject add a ref?
826 SetLastWin32Error(ERROR_INVALID_CURSOR_HANDLE
);
830 DPRINT("Leave NtUserFindExistingCursorIcon, ret=%i\n",_ret_
);
844 /* FIXME - check if process has WINSTA_READATTRIBUTES */
845 PSYSTEM_CURSORINFO CurInfo
;
848 DECLARE_RETURN(BOOL
);
850 DPRINT("Enter NtUserGetClipCursor\n");
851 UserEnterExclusive();
856 CurInfo
= IntGetSysCursorInfo();
857 if (CurInfo
->bClipped
)
859 Rect
= CurInfo
->rcClip
;
865 Rect
.right
= UserGetSystemMetrics(SM_CXSCREEN
);
866 Rect
.bottom
= UserGetSystemMetrics(SM_CYSCREEN
);
869 Status
= MmCopyToCaller(lpRect
, &Rect
, sizeof(RECT
));
870 if (!NT_SUCCESS(Status
))
872 SetLastNtError(Status
);
879 DPRINT("Leave NtUserGetClipCursor, ret=%i\n",_ret_
);
893 PCURICON_OBJECT CurIcon
;
895 DECLARE_RETURN(HCURSOR
);
897 DPRINT("Enter NtUserSetCursor\n");
898 UserEnterExclusive();
902 if (!(CurIcon
= UserGetCurIconObject(hCursor
)))
912 OldCursor
= UserSetCursor(CurIcon
, FALSE
);
916 UserDereferenceObject(CurIcon
);
922 DPRINT("Leave NtUserSetCursor, ret=%i\n",_ret_
);
933 NtUserSetCursorContents(
935 PICONINFO UnsafeIconInfo
)
937 PCURICON_OBJECT CurIcon
;
942 DECLARE_RETURN(BOOL
);
944 DPRINT("Enter NtUserSetCursorContents\n");
945 UserEnterExclusive();
947 if (!(CurIcon
= UserGetCurIconObject(hCurIcon
)))
953 Status
= MmCopyFromCaller(&IconInfo
, UnsafeIconInfo
, sizeof(ICONINFO
));
954 if (!NT_SUCCESS(Status
))
956 SetLastNtError(Status
);
960 /* Delete old bitmaps */
961 if ((CurIcon
->IconInfo
.hbmColor
)
962 && (CurIcon
->IconInfo
.hbmColor
!= IconInfo
.hbmColor
))
964 GreDeleteObject(CurIcon
->IconInfo
.hbmColor
);
966 if ((CurIcon
->IconInfo
.hbmMask
)
967 && CurIcon
->IconInfo
.hbmMask
!= IconInfo
.hbmMask
)
969 GreDeleteObject(CurIcon
->IconInfo
.hbmMask
);
972 /* Copy new IconInfo field */
973 CurIcon
->IconInfo
= IconInfo
;
975 psurfBmp
= SURFACE_LockSurface(CurIcon
->IconInfo
.hbmColor
);
978 CurIcon
->Size
.cx
= psurfBmp
->SurfObj
.sizlBitmap
.cx
;
979 CurIcon
->Size
.cy
= psurfBmp
->SurfObj
.sizlBitmap
.cy
;
980 SURFACE_UnlockSurface(psurfBmp
);
981 GDIOBJ_SetOwnership(CurIcon
->IconInfo
.hbmColor
, NULL
);
985 psurfBmp
= SURFACE_LockSurface(CurIcon
->IconInfo
.hbmMask
);
989 CurIcon
->Size
.cx
= psurfBmp
->SurfObj
.sizlBitmap
.cx
;
990 CurIcon
->Size
.cy
= psurfBmp
->SurfObj
.sizlBitmap
.cy
/ 2;
992 SURFACE_UnlockSurface(psurfBmp
);
994 GDIOBJ_SetOwnership(CurIcon
->IconInfo
.hbmMask
, NULL
);
1002 UserDereferenceObject(CurIcon
);
1007 DPRINT("Leave NtUserSetCursorContents, ret=%i\n",_ret_
);
1019 NtUserSetCursorIconData(
1022 PUNICODE_STRING pstrResName
,
1023 PICONINFO pIconInfo
)
1025 PCURICON_OBJECT CurIcon
;
1027 NTSTATUS Status
= STATUS_SUCCESS
;
1029 DECLARE_RETURN(BOOL
);
1031 DPRINT("Enter NtUserSetCursorIconData\n");
1032 UserEnterExclusive();
1034 if (!(CurIcon
= UserGetCurIconObject(Handle
)))
1039 CurIcon
->hModule
= hModule
;
1040 CurIcon
->hRsrc
= NULL
; //hRsrc;
1041 CurIcon
->hGroupRsrc
= NULL
; //hGroupRsrc;
1045 ProbeForRead(pIconInfo
, sizeof(ICONINFO
), 1);
1046 RtlCopyMemory(&CurIcon
->IconInfo
, pIconInfo
, sizeof(ICONINFO
));
1048 CurIcon
->IconInfo
.hbmMask
= BITMAP_CopyBitmap(pIconInfo
->hbmMask
);
1049 CurIcon
->IconInfo
.hbmColor
= BITMAP_CopyBitmap(pIconInfo
->hbmColor
);
1051 if (CurIcon
->IconInfo
.hbmColor
)
1053 if ((psurfBmp
= SURFACE_LockSurface(CurIcon
->IconInfo
.hbmColor
)))
1055 CurIcon
->Size
.cx
= psurfBmp
->SurfObj
.sizlBitmap
.cx
;
1056 CurIcon
->Size
.cy
= psurfBmp
->SurfObj
.sizlBitmap
.cy
;
1057 SURFACE_UnlockSurface(psurfBmp
);
1058 GDIOBJ_SetOwnership(GdiHandleTable
, CurIcon
->IconInfo
.hbmMask
, NULL
);
1061 if (CurIcon
->IconInfo
.hbmMask
)
1063 if (CurIcon
->IconInfo
.hbmColor
== NULL
)
1065 if ((psurfBmp
= SURFACE_LockSurface(CurIcon
->IconInfo
.hbmMask
)))
1067 CurIcon
->Size
.cx
= psurfBmp
->SurfObj
.sizlBitmap
.cx
;
1068 CurIcon
->Size
.cy
= psurfBmp
->SurfObj
.sizlBitmap
.cy
;
1069 SURFACE_UnlockSurface(psurfBmp
);
1072 GDIOBJ_SetOwnership(GdiHandleTable
, CurIcon
->IconInfo
.hbmMask
, NULL
);
1075 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1077 Status
= _SEH2_GetExceptionCode();
1081 if (!NT_SUCCESS(Status
))
1082 SetLastNtError(Status
);
1086 UserDereferenceObject(CurIcon
);
1090 DPRINT("Leave NtUserSetCursorIconData, ret=%i\n",_ret_
);
1097 NtUserSetCursorIconData(
1105 PCURICON_OBJECT CurIcon
;
1109 DECLARE_RETURN(BOOL
);
1111 DPRINT("Enter NtUserSetCursorIconData\n");
1112 UserEnterExclusive();
1114 if (!(CurIcon
= UserGetCurIconObject(hCurIcon
)))
1119 CurIcon
->hModule
= hModule
;
1120 CurIcon
->hRsrc
= hRsrc
;
1121 CurIcon
->hGroupRsrc
= hGroupRsrc
;
1126 Status
= MmCopyFromCaller(&CurIcon
->IconInfo
.fIcon
, fIcon
, sizeof(BOOL
));
1127 if (!NT_SUCCESS(Status
))
1129 SetLastNtError(Status
);
1141 Status
= MmCopyFromCaller(&SafeHotspot
, Hotspot
, sizeof(POINT
));
1142 if (NT_SUCCESS(Status
))
1144 CurIcon
->IconInfo
.xHotspot
= SafeHotspot
.x
;
1145 CurIcon
->IconInfo
.yHotspot
= SafeHotspot
.y
;
1150 SetLastNtError(Status
);
1153 if (!fIcon
&& !Hotspot
)
1161 /* This icon is shared now */
1162 GDIOBJ_SetOwnership(CurIcon
->IconInfo
.hbmMask
, NULL
);
1163 if(CurIcon
->IconInfo
.hbmColor
)
1165 GDIOBJ_SetOwnership(CurIcon
->IconInfo
.hbmColor
, NULL
);
1168 UserDereferenceObject(CurIcon
);
1173 DPRINT("Leave NtUserSetCursorIconData, ret=%i\n",_ret_
);
1184 NtUserSetSystemCursor(
1191 /* Mostly inspired from wine code */
1197 PCURICON_OBJECT pIcon
,
1201 HBRUSH hbrFlickerFreeDraw
,
1205 HBITMAP hbmMask
, hbmColor
;
1206 BITMAP bmpColor
, bm
;
1208 INT iOldBkColor
= 0, iOldTxtColor
= 0;
1210 HDC hMemDC
, hDestDC
= hDc
;
1211 HGDIOBJ hOldOffBrush
= 0;
1212 HGDIOBJ hOldOffBmp
= 0;
1213 HBITMAP hTmpBmp
= 0, hOffBmp
= 0;
1214 BOOL bAlpha
= FALSE
;
1215 INT x
=xLeft
, y
=yTop
;
1217 hbmMask
= pIcon
->IconInfo
.hbmMask
;
1218 hbmColor
= pIcon
->IconInfo
.hbmColor
;
1221 DPRINT1("NtUserDrawIconEx: istepIfAniCur is not supported!\n");
1223 if (!hbmMask
|| !IntGdiGetObject(hbmMask
, sizeof(BITMAP
), (PVOID
)&bm
))
1228 if (hbmColor
&& !IntGdiGetObject(hbmColor
, sizeof(BITMAP
), (PVOID
)&bmpColor
))
1233 if(!(hMemDC
= NtGdiCreateCompatibleDC(hDc
)))
1235 DPRINT1("NtGdiCreateCompatibleDC failed!\n");
1239 /* Check for alpha */
1241 && (bmpColor
.bmBitsPixel
== 32)
1242 && (diFlags
& DI_IMAGE
))
1244 SURFACE
*psurfOff
= NULL
;
1245 PFN_DIB_GetPixel fnSource_GetPixel
= NULL
;
1248 /* In order to correctly display 32 bit icons Windows first scans the image,
1249 because information about transparency is not stored in any image's headers */
1250 psurfOff
= SURFACE_LockSurface(hbmColor
);
1253 fnSource_GetPixel
= DibFunctionsForBitmapFormat
[psurfOff
->SurfObj
.iBitmapFormat
].DIB_GetPixel
;
1254 if (fnSource_GetPixel
)
1256 for (i
= 0; i
< psurfOff
->SurfObj
.sizlBitmap
.cx
; i
++)
1258 for (j
= 0; j
< psurfOff
->SurfObj
.sizlBitmap
.cy
; j
++)
1260 bAlpha
= ((BYTE
)(fnSource_GetPixel(&psurfOff
->SurfObj
, i
, j
) >> 24) & 0xff);
1268 SURFACE_UnlockSurface(psurfOff
);
1273 cxWidth
= ((diFlags
& DI_DEFAULTSIZE
) ?
1274 UserGetSystemMetrics(SM_CXICON
) : pIcon
->Size
.cx
);
1277 cyHeight
= ((diFlags
& DI_DEFAULTSIZE
) ?
1278 UserGetSystemMetrics(SM_CYICON
) : pIcon
->Size
.cy
);
1280 DoFlickerFree
= (hbrFlickerFreeDraw
&&
1281 (GDI_HANDLE_GET_TYPE(hbrFlickerFreeDraw
) == GDI_OBJECT_TYPE_BRUSH
));
1285 hDestDC
= NtGdiCreateCompatibleDC(hDc
);
1288 DPRINT1("NtGdiCreateCompatibleDC failed!\n");
1292 hOffBmp
= NtGdiCreateCompatibleBitmap(hDc
, cxWidth
, cyHeight
);
1295 DPRINT1("NtGdiCreateCompatibleBitmap failed!\n");
1298 hOldOffBmp
= NtGdiSelectBitmap(hDestDC
, hOffBmp
);
1299 hOldOffBrush
= NtGdiSelectBrush(hDestDC
, hbrFlickerFreeDraw
);
1300 NtGdiPatBlt(hDestDC
, 0, 0, cxWidth
, cyHeight
, PATCOPY
);
1301 NtGdiSelectBrush(hDestDC
, hOldOffBrush
);
1305 /* Set Background/foreground colors */
1306 iOldTxtColor
= IntGdiSetTextColor(hDc
, 0); //black
1307 iOldBkColor
= IntGdiSetBkColor(hDc
, 0x00FFFFFF); //white
1309 if(bAlpha
&& (diFlags
& DI_IMAGE
))
1311 BLENDFUNCTION pixelblend
= { AC_SRC_OVER
, 0, 255, AC_SRC_ALPHA
};
1316 HBITMAP hMemBmp
= NULL
;
1318 hMemBmp
= BITMAP_CopyBitmap(hbmColor
);
1321 DPRINT1("BITMAP_CopyBitmap failed!");
1325 psurf
= SURFACE_LockSurface(hMemBmp
);
1328 DPRINT1("SURFACE_LockSurface failed!\n");
1332 /* premultiply with the alpha channel value */
1333 for (i
= 0; i
< psurf
->SurfObj
.sizlBitmap
.cy
; i
++)
1335 ptr
= (PBYTE
)psurf
->SurfObj
.pvScan0
+ i
*psurf
->SurfObj
.lDelta
;
1336 for (j
= 0; j
< psurf
->SurfObj
.sizlBitmap
.cx
; j
++)
1339 ptr
[0] = (ptr
[0] * Alpha
) / 0xff;
1340 ptr
[1] = (ptr
[1] * Alpha
) / 0xff;
1341 ptr
[2] = (ptr
[2] * Alpha
) / 0xff;
1347 SURFACE_UnlockSurface(psurf
);
1349 hTmpBmp
= NtGdiSelectBitmap(hMemDC
, hMemBmp
);
1351 Ret
= NtGdiAlphaBlend(hDestDC
,
1363 NtGdiSelectBitmap(hMemDC
, hTmpBmp
);
1365 if(hMemBmp
) NtGdiDeleteObjectApp(hMemBmp
);
1369 if (diFlags
& DI_MASK
)
1371 hTmpBmp
= NtGdiSelectBitmap(hMemDC
, hbmMask
);
1372 NtGdiStretchBlt(hDestDC
,
1384 NtGdiSelectBitmap(hMemDC
, hTmpBmp
);
1387 if(diFlags
& DI_IMAGE
)
1391 DWORD rop
= (diFlags
& DI_MASK
) ? SRCINVERT
: SRCCOPY
;
1392 hTmpBmp
= NtGdiSelectBitmap(hMemDC
, hbmColor
);
1393 NtGdiStretchBlt(hDestDC
,
1405 NtGdiSelectBitmap(hMemDC
, hTmpBmp
);
1409 /* Mask bitmap holds the information in its second half */
1410 DWORD rop
= (diFlags
& DI_MASK
) ? SRCINVERT
: SRCCOPY
;
1411 hTmpBmp
= NtGdiSelectBitmap(hMemDC
, hbmMask
);
1412 NtGdiStretchBlt(hDestDC
,
1424 NtGdiSelectBitmap(hMemDC
, hTmpBmp
);
1431 NtGdiBitBlt(hDc
, xLeft
, yTop
, cxWidth
, cyHeight
, hDestDC
, 0, 0, SRCCOPY
, 0, 0);
1434 /* Restore foreground and background colors */
1435 IntGdiSetBkColor(hDc
, iOldBkColor
);
1436 IntGdiSetTextColor(hDc
, iOldTxtColor
);
1441 NtGdiDeleteObjectApp(hMemDC
);
1444 if(hOldOffBmp
) NtGdiSelectBitmap(hDestDC
, hOldOffBmp
);
1445 NtGdiDeleteObjectApp(hDestDC
);
1446 if(hOffBmp
) NtGdiDeleteObjectApp(hOffBmp
);
1465 HBRUSH hbrFlickerFreeDraw
,
1467 BOOL bMetaHDC
, // When TRUE, GDI functions need to be handled in User32!
1470 PCURICON_OBJECT pIcon
;
1473 DPRINT("Enter NtUserDrawIconEx\n");
1474 UserEnterExclusive();
1476 if (!(pIcon
= UserGetCurIconObject(hIcon
)))
1478 DPRINT1("UserGetCurIconObject() failed!\n");
1483 Ret
= UserDrawIconEx(hdc
,
1493 UserDereferenceObject(pIcon
);