2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS win32 subsystem
4 * PURPOSE: Mouse pointer functions
5 * FILE: subsystems/win32k/eng/mouse.c
6 * PROGRAMER: Casper S. Hornstrup (chorns@users.sourceforge.net)
7 * Timo Kreuzer (timo.kreuzer@reactos.org)
9 /* INCLUDES ******************************************************************/
16 /* FUNCTIONS *****************************************************************/
27 // This function is obsolete for Windows 2000 and later.
28 // This function is still supported, but always returns FALSE.
29 // www.osr.com/ddk/graphics/gdifncs_4yav.htm
34 * FUNCTION: Notify the mouse driver that drawing is about to begin in
35 * a rectangle on a particular surface.
38 MouseSafetyOnDrawStart(
48 ASSERT(ppdev
!= NULL
);
49 ASSERT(ppdev
->pSurface
!= NULL
);
51 pgp
= &ppdev
->Pointer
;
53 if (pgp
->Exclude
.right
== -1)
58 ppdev
->SafetyRemoveCount
++;
60 if (ppdev
->SafetyRemoveLevel
!= 0)
65 if (HazardX1
> HazardX2
)
71 if (HazardY1
> HazardY2
)
78 if (pgp
->Exclude
.right
>= HazardX1
79 && pgp
->Exclude
.left
<= HazardX2
80 && pgp
->Exclude
.bottom
>= HazardY1
81 && pgp
->Exclude
.top
<= HazardY2
)
83 ppdev
->SafetyRemoveLevel
= ppdev
->SafetyRemoveCount
;
84 ppdev
->pfnMovePointer(&ppdev
->pSurface
->SurfObj
, -1, -1, NULL
);
91 * FUNCTION: Notify the mouse driver that drawing has finished on a surface.
99 ASSERT(ppdev
!= NULL
);
100 ASSERT(ppdev
->pSurface
!= NULL
);
102 pgp
= &ppdev
->Pointer
;
104 if (pgp
->Exclude
.right
== -1)
109 if (--ppdev
->SafetyRemoveCount
>= ppdev
->SafetyRemoveLevel
)
114 ppdev
->pfnMovePointer(&ppdev
->pSurface
->SurfObj
,
119 ppdev
->SafetyRemoveLevel
= 0;
124 /* SOFTWARE MOUSE POINTER IMPLEMENTATION **************************************/
140 pgp
= &ppdev
->Pointer
;
147 pgp
->Enabled
= FALSE
;
151 DPRINT("No SaveSurface!\n");
155 /* Calculate cursor coordinates */
156 pt
.x
= ppdev
->ptlPointer
.x
- pgp
->HotSpot
.x
;
157 pt
.y
= ppdev
->ptlPointer
.y
- pgp
->HotSpot
.y
;
159 rclDest
.left
= max(pt
.x
, 0);
160 rclDest
.top
= max(pt
.y
, 0);
161 rclDest
.right
= min(pt
.x
+ pgp
->Size
.cx
, psoDest
->sizlBitmap
.cx
);
162 rclDest
.bottom
= min(pt
.y
+ pgp
->Size
.cy
, psoDest
->sizlBitmap
.cy
);
164 ptlSave
.x
= rclDest
.left
- pt
.x
;
165 ptlSave
.y
= rclDest
.top
- pt
.y
;
167 IntEngBitBlt(psoDest
,
168 &pgp
->psurfSave
->SurfObj
,
177 ROP4_FROM_INDEX(R3_OPINDEX_SRCCOPY
));
182 IntShowMousePointer(PDEVOBJ
*ppdev
, SURFOBJ
*psoDest
)
186 RECTL rclSurf
, rclPointer
;
191 pgp
= &ppdev
->Pointer
;
200 /* Check if we have any mouse pointer */
201 if (!pgp
->psurfSave
) return;
203 /* Calculate pointer coordinates */
204 pt
.x
= ppdev
->ptlPointer
.x
- pgp
->HotSpot
.x
;
205 pt
.y
= ppdev
->ptlPointer
.y
- pgp
->HotSpot
.y
;
207 /* Calculate the rect on the surface */
208 rclSurf
.left
= max(pt
.x
, 0);
209 rclSurf
.top
= max(pt
.y
, 0);
210 rclSurf
.right
= min(pt
.x
+ pgp
->Size
.cx
, psoDest
->sizlBitmap
.cx
);
211 rclSurf
.bottom
= min(pt
.y
+ pgp
->Size
.cy
, psoDest
->sizlBitmap
.cy
);
213 /* Calculate the rect in the pointer bitmap */
214 rclPointer
.left
= rclSurf
.left
- pt
.x
;
215 rclPointer
.top
= rclSurf
.top
- pt
.y
;
216 rclPointer
.right
= min(pgp
->Size
.cx
, psoDest
->sizlBitmap
.cx
- pt
.x
);
217 rclPointer
.bottom
= min(pgp
->Size
.cy
, psoDest
->sizlBitmap
.cy
- pt
.y
);
219 /* Copy the pixels under the cursor to temporary surface. */
220 IntEngBitBlt(&pgp
->psurfSave
->SurfObj
,
230 ROP4_FROM_INDEX(R3_OPINDEX_SRCCOPY
));
232 /* Blt the pointer on the screen. */
235 if(!(pgp
->flags
& SPS_ALPHA
))
237 IntEngBitBlt(psoDest
,
238 &pgp
->psurfMask
->SurfObj
,
243 (POINTL
*)&rclPointer
,
249 IntEngBitBlt(psoDest
,
250 &pgp
->psurfColor
->SurfObj
,
255 (POINTL
*)&rclPointer
,
263 BLENDOBJ blendobj
= { {AC_SRC_OVER
, 0, 255, AC_SRC_ALPHA
} };
265 EXLATEOBJ_vInitialize(&exlo
,
266 pgp
->psurfColor
->ppal
,
271 IntEngAlphaBlend(psoDest
,
272 &pgp
->psurfColor
->SurfObj
,
278 EXLATEOBJ_vCleanup(&exlo
);
283 IntEngBitBlt(psoDest
,
284 &pgp
->psurfMask
->SurfObj
,
289 (POINTL
*)&rclPointer
,
293 ROP4_FROM_INDEX(R3_OPINDEX_SRCAND
));
295 rclPointer
.top
+= pgp
->Size
.cy
;
297 IntEngBitBlt(psoDest
,
298 &pgp
->psurfMask
->SurfObj
,
303 (POINTL
*)&rclPointer
,
307 ROP4_FROM_INDEX(R3_OPINDEX_SRCINVERT
));
318 IN SURFOBJ
*psoColor
,
330 HBITMAP hbmSave
= NULL
, hbmColor
= NULL
, hbmMask
= NULL
;
331 PSURFACE psurfSave
= NULL
, psurfColor
= NULL
, psurfMask
= NULL
;
333 SIZEL sizel
= {0, 0};
338 pgp
= &ppdev
->Pointer
;
340 /* Do we have any bitmap at all? */
341 if (psoColor
|| psoMask
)
343 /* Get the size of the new pointer */
346 sizel
.cx
= psoColor
->sizlBitmap
.cx
;
347 sizel
.cy
= psoColor
->sizlBitmap
.cy
;
351 sizel
.cx
= psoMask
->sizlBitmap
.cx
;
352 sizel
.cy
= psoMask
->sizlBitmap
.cy
/ 2;
357 rectl
.right
= sizel
.cx
;
358 rectl
.bottom
= sizel
.cy
;
360 /* Calculate lDelta for our surfaces. */
361 lDelta
= WIDTH_BYTES_ALIGN32(sizel
.cx
,
362 BitsPerFormat(pso
->iBitmapFormat
));
364 /* Create a bitmap for saving the pixels under the cursor. */
365 hbmSave
= EngCreateBitmap(sizel
,
368 BMF_TOPDOWN
| BMF_NOZEROINIT
,
370 psurfSave
= SURFACE_ShareLockSurface(hbmSave
);
371 if (!psurfSave
) goto failure
;
376 /* Color bitmap must have the same format as the dest surface */
377 if (psoColor
->iBitmapFormat
!= pso
->iBitmapFormat
)
379 /* It's OK if we have an alpha bitmap */
380 if(!(fl
& SPS_ALPHA
))
382 DPRINT1("Screen surface and cursor color bitmap format don't match!.\n");
387 /* Create a bitmap to copy the color bitmap to */
388 hbmColor
= EngCreateBitmap(psoColor
->sizlBitmap
,
391 BMF_TOPDOWN
| BMF_NOZEROINIT
,
393 psurfColor
= SURFACE_ShareLockSurface(hbmColor
);
394 if (!psurfColor
) goto failure
;
396 /* Now copy the given bitmap */
397 rectl
.bottom
= psoColor
->sizlBitmap
.cy
;
398 IntEngCopyBits(&psurfColor
->SurfObj
,
406 /* Create a mask surface */
412 /* Create a bitmap for the mask */
413 hbmMask
= EngCreateBitmap(psoMask
->sizlBitmap
,
416 BMF_TOPDOWN
| BMF_NOZEROINIT
,
418 psurfMask
= SURFACE_ShareLockSurface(hbmMask
);
419 if (!psurfMask
) goto failure
;
421 /* Initialize an EXLATEOBJ */
422 ppal
= PALETTE_ShareLockPalette(ppdev
->devinfo
.hpalDefault
);
423 EXLATEOBJ_vInitialize(&exlo
,
430 /* Copy the mask bitmap */
431 rectl
.bottom
= psoMask
->sizlBitmap
.cy
;
432 IntEngCopyBits(&psurfMask
->SurfObj
,
440 EXLATEOBJ_vCleanup(&exlo
);
441 if (ppal
) PALETTE_ShareUnlockPalette(ppal
);
444 /* Hide mouse pointer */
445 IntHideMousePointer(ppdev
, pso
);
447 /* Free old color bitmap */
450 EngDeleteSurface(pgp
->psurfColor
->BaseObject
.hHmgr
);
451 SURFACE_ShareUnlockSurface(pgp
->psurfColor
);
452 pgp
->psurfColor
= NULL
;
455 /* Free old mask bitmap */
458 EngDeleteSurface(pgp
->psurfMask
->BaseObject
.hHmgr
);
459 SURFACE_ShareUnlockSurface(pgp
->psurfMask
);
460 pgp
->psurfMask
= NULL
;
463 /* Free old save bitmap */
466 EngDeleteSurface(pgp
->psurfSave
->BaseObject
.hHmgr
);
467 SURFACE_ShareUnlockSurface(pgp
->psurfSave
);
468 pgp
->psurfSave
= NULL
;
471 /* See if we are being asked to hide the pointer. */
472 if (psoMask
== NULL
&& psoColor
== NULL
)
475 return SPS_ACCEPT_NOEXCLUDE
;
478 /* Now set the new cursor */
479 pgp
->psurfColor
= psurfColor
;
480 pgp
->psurfMask
= psurfMask
;
481 pgp
->psurfSave
= psurfSave
;
482 pgp
->HotSpot
.x
= xHot
;
483 pgp
->HotSpot
.y
= yHot
;
489 ppdev
->ptlPointer
.x
= x
;
490 ppdev
->ptlPointer
.y
= y
;
492 IntShowMousePointer(ppdev
, pso
);
496 prcl
->left
= x
- pgp
->HotSpot
.x
;
497 prcl
->top
= y
- pgp
->HotSpot
.x
;
498 prcl
->right
= prcl
->left
+ pgp
->Size
.cx
;
499 prcl
->bottom
= prcl
->top
+ pgp
->Size
.cy
;
502 else if (prcl
!= NULL
)
504 prcl
->left
= prcl
->top
= prcl
->right
= prcl
->bottom
= -1;
507 return SPS_ACCEPT_NOEXCLUDE
;
510 /* Cleanup surfaces */
511 if (hbmMask
) EngDeleteSurface((HSURF
)hbmMask
);
512 if (psurfMask
) SURFACE_ShareUnlockSurface(psurfMask
);
513 if (hbmColor
) EngDeleteSurface((HSURF
)hbmColor
);
514 if (psurfColor
) SURFACE_ShareUnlockSurface(psurfColor
);
515 if (hbmSave
) EngDeleteSurface((HSURF
)hbmSave
);
516 if (psurfSave
) SURFACE_ShareUnlockSurface(psurfSave
);
540 pgp
= &ppdev
->Pointer
;
542 IntHideMousePointer(ppdev
, pso
);
544 ppdev
->ptlPointer
.x
= x
;
545 ppdev
->ptlPointer
.y
= y
;
549 IntShowMousePointer(ppdev
, pso
);
552 prcl
->left
= x
- pgp
->HotSpot
.x
;
553 prcl
->top
= y
- pgp
->HotSpot
.y
;
554 prcl
->right
= prcl
->left
+ pgp
->Size
.cx
;
555 prcl
->bottom
= prcl
->top
+ pgp
->Size
.cy
;
558 else if (prcl
!= NULL
)
560 prcl
->left
= prcl
->top
= prcl
->right
= prcl
->bottom
= -1;
565 IntEngSetPointerShape(
568 IN SURFOBJ
*psoColor
,
577 ULONG ulResult
= SPS_DECLINE
;
578 PFN_DrvSetPointerShape pfnSetPointerShape
;
579 PPDEVOBJ ppdev
= GDIDEV(pso
);
581 pfnSetPointerShape
= GDIDEVFUNCS(pso
).SetPointerShape
;
583 if (pfnSetPointerShape
)
585 ulResult
= pfnSetPointerShape(pso
,
597 /* Check if the driver accepted it */
598 if (ulResult
== SPS_ACCEPT_NOEXCLUDE
)
600 /* Set MovePointer to the driver function */
601 ppdev
->pfnMovePointer
= GDIDEVFUNCS(pso
).MovePointer
;
605 /* Set software pointer */
606 ulResult
= EngSetPointerShape(pso
,
616 /* Set MovePointer to the eng function */
617 ppdev
->pfnMovePointer
= EngMovePointer
;
636 PSURFACE psurf
, psurfMask
, psurfColor
;
640 pdc
= DC_LockDc(hdc
);
643 DPRINT1("Failed to lock the DC.\n");
647 ASSERT(pdc
->dctype
== DCTYPE_DIRECT
);
648 EngAcquireSemaphore(pdc
->ppdev
->hsemDevLock
);
649 /* We're not sure DC surface is the good one */
650 psurf
= pdc
->ppdev
->pSurface
;
653 DPRINT1("DC has no surface.\n");
654 EngReleaseSemaphore(pdc
->ppdev
->hsemDevLock
);
659 /* Lock the mask bitmap */
661 psurfMask
= SURFACE_ShareLockSurface(hbmMask
);
664 //ASSERT(fl & SPS_ALPHA);
668 /* Check for color bitmap */
671 /* We have one, lock it */
672 psurfColor
= SURFACE_ShareLockSurface(hbmColor
);
676 /* Create an XLATEOBJ, no mono support */
677 EXLATEOBJ_vInitialize(&exlo
, psurfColor
->ppal
, psurf
->ppal
, 0, 0, 0);
683 /* We must have a valid surface in case of alpha bitmap */
684 ASSERT(((fl
& SPS_ALPHA
) && psurfColor
) || !(fl
& SPS_ALPHA
));
686 /* Call the driver or eng function */
687 ulResult
= IntEngSetPointerShape(&psurf
->SurfObj
,
688 psurfMask
? &psurfMask
->SurfObj
: NULL
,
689 psurfColor
? &psurfColor
->SurfObj
: NULL
,
690 psurfColor
? &exlo
.xlo
: NULL
,
695 &pdc
->ppdev
->Pointer
.Exclude
,
701 EXLATEOBJ_vCleanup(&exlo
);
702 SURFACE_ShareUnlockSurface(psurfColor
);
706 SURFACE_ShareUnlockSurface(psurfMask
);
708 EngReleaseSemaphore(pdc
->ppdev
->hsemDevLock
);
728 pdc
= DC_LockDc(hdc
);
731 DPRINT1("Failed to lock the DC.\n");
734 ASSERT(pdc
->dctype
== DCTYPE_DIRECT
);
736 /* Acquire PDEV lock */
737 EngAcquireSemaphore(pdc
->ppdev
->hsemDevLock
);
739 /* Check if we need to move it */
740 if(pdc
->ppdev
->SafetyRemoveLevel
== 0)
742 /* Store the cursor exclude position in the PDEV */
743 prcl
= &pdc
->ppdev
->Pointer
.Exclude
;
745 /* Call Eng/Drv function */
746 pdc
->ppdev
->pfnMovePointer(&pdc
->ppdev
->pSurface
->SurfObj
, x
, y
, prcl
);
749 /* Release PDEV lock */
750 EngReleaseSemaphore(pdc
->ppdev
->hsemDevLock
);