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 IntEngBitBlt(psoDest
,
236 &pgp
->psurfMask
->SurfObj
,
241 (POINTL
*)&rclPointer
,
245 ROP4_FROM_INDEX(R3_OPINDEX_SRCAND
));
247 IntEngBitBlt(psoDest
,
248 &pgp
->psurfColor
->SurfObj
,
253 (POINTL
*)&rclPointer
,
257 ROP4_FROM_INDEX(R3_OPINDEX_SRCINVERT
));
261 IntEngBitBlt(psoDest
,
262 &pgp
->psurfMask
->SurfObj
,
267 (POINTL
*)&rclPointer
,
271 ROP4_FROM_INDEX(R3_OPINDEX_SRCAND
));
273 rclPointer
.top
+= pgp
->Size
.cy
;
275 IntEngBitBlt(psoDest
,
276 &pgp
->psurfMask
->SurfObj
,
281 (POINTL
*)&rclPointer
,
285 ROP4_FROM_INDEX(R3_OPINDEX_SRCINVERT
));
296 IN SURFOBJ
*psoColor
,
308 HBITMAP hbmSave
= NULL
, hbmColor
= NULL
, hbmMask
= NULL
;
309 PSURFACE psurfSave
= NULL
, psurfColor
= NULL
, psurfMask
= NULL
;
311 SIZEL sizel
= {0, 0};
316 pgp
= &ppdev
->Pointer
;
318 /* Do we have any bitmap at all? */
319 if (psoColor
|| psoMask
)
321 /* Get the size of the new pointer */
324 sizel
.cx
= psoColor
->sizlBitmap
.cx
;
325 sizel
.cy
= psoColor
->sizlBitmap
.cy
;
329 sizel
.cx
= psoMask
->sizlBitmap
.cx
;
330 sizel
.cy
= psoMask
->sizlBitmap
.cy
/ 2;
335 rectl
.right
= sizel
.cx
;
336 rectl
.bottom
= sizel
.cy
;
338 /* Calculate lDelta for our surfaces. */
339 lDelta
= WIDTH_BYTES_ALIGN32(sizel
.cx
,
340 BitsPerFormat(pso
->iBitmapFormat
));
342 /* Create a bitmap for saving the pixels under the cursor. */
343 hbmSave
= EngCreateBitmap(sizel
,
346 BMF_TOPDOWN
| BMF_NOZEROINIT
,
348 psurfSave
= SURFACE_ShareLockSurface(hbmSave
);
349 if (!psurfSave
) goto failure
;
354 /* Color bitmap must have the same format as the dest surface */
355 if (psoColor
->iBitmapFormat
!= pso
->iBitmapFormat
) goto failure
;
357 /* Create a bitmap to copy the color bitmap to */
358 hbmColor
= EngCreateBitmap(psoColor
->sizlBitmap
,
361 BMF_TOPDOWN
| BMF_NOZEROINIT
,
363 psurfColor
= SURFACE_ShareLockSurface(hbmColor
);
364 if (!psurfColor
) goto failure
;
366 /* Now copy the given bitmap */
367 rectl
.bottom
= psoColor
->sizlBitmap
.cy
;
368 IntEngCopyBits(&psurfColor
->SurfObj
,
376 /* Create a mask surface */
382 /* Create a bitmap for the mask */
383 hbmMask
= EngCreateBitmap(psoMask
->sizlBitmap
,
386 BMF_TOPDOWN
| BMF_NOZEROINIT
,
388 psurfMask
= SURFACE_ShareLockSurface(hbmMask
);
389 if (!psurfMask
) goto failure
;
391 /* Initialize an EXLATEOBJ */
392 ppal
= PALETTE_ShareLockPalette(ppdev
->devinfo
.hpalDefault
);
393 EXLATEOBJ_vInitialize(&exlo
,
400 /* Copy the mask bitmap */
401 rectl
.bottom
= psoMask
->sizlBitmap
.cy
;
402 IntEngCopyBits(&psurfMask
->SurfObj
,
410 EXLATEOBJ_vCleanup(&exlo
);
411 if (ppal
) PALETTE_ShareUnlockPalette(ppal
);
414 /* Hide mouse pointer */
415 IntHideMousePointer(ppdev
, pso
);
417 /* Free old color bitmap */
420 EngDeleteSurface(pgp
->psurfColor
->BaseObject
.hHmgr
);
421 SURFACE_ShareUnlockSurface(pgp
->psurfColor
);
422 pgp
->psurfColor
= NULL
;
425 /* Free old mask bitmap */
428 EngDeleteSurface(pgp
->psurfMask
->BaseObject
.hHmgr
);
429 SURFACE_ShareUnlockSurface(pgp
->psurfMask
);
430 pgp
->psurfMask
= NULL
;
433 /* Free old save bitmap */
436 EngDeleteSurface(pgp
->psurfSave
->BaseObject
.hHmgr
);
437 SURFACE_ShareUnlockSurface(pgp
->psurfSave
);
438 pgp
->psurfSave
= NULL
;
441 /* See if we are being asked to hide the pointer. */
442 if (psoMask
== NULL
&& psoColor
== NULL
)
445 return SPS_ACCEPT_NOEXCLUDE
;
448 /* Now set the new cursor */
449 pgp
->psurfColor
= psurfColor
;
450 pgp
->psurfMask
= psurfMask
;
451 pgp
->psurfSave
= psurfSave
;
452 pgp
->HotSpot
.x
= xHot
;
453 pgp
->HotSpot
.y
= yHot
;
458 ppdev
->ptlPointer
.x
= x
;
459 ppdev
->ptlPointer
.y
= y
;
461 IntShowMousePointer(ppdev
, pso
);
465 prcl
->left
= x
- pgp
->HotSpot
.x
;
466 prcl
->top
= y
- pgp
->HotSpot
.x
;
467 prcl
->right
= prcl
->left
+ pgp
->Size
.cx
;
468 prcl
->bottom
= prcl
->top
+ pgp
->Size
.cy
;
471 else if (prcl
!= NULL
)
473 prcl
->left
= prcl
->top
= prcl
->right
= prcl
->bottom
= -1;
476 return SPS_ACCEPT_NOEXCLUDE
;
479 /* Cleanup surfaces */
480 if (hbmMask
) EngDeleteSurface((HSURF
)hbmMask
);
481 if (psurfMask
) SURFACE_ShareUnlockSurface(psurfMask
);
482 if (hbmColor
) EngDeleteSurface((HSURF
)hbmColor
);
483 if (psurfColor
) SURFACE_ShareUnlockSurface(psurfColor
);
484 if (hbmSave
) EngDeleteSurface((HSURF
)hbmSave
);
485 if (psurfSave
) SURFACE_ShareUnlockSurface(psurfSave
);
509 pgp
= &ppdev
->Pointer
;
511 IntHideMousePointer(ppdev
, pso
);
513 ppdev
->ptlPointer
.x
= x
;
514 ppdev
->ptlPointer
.y
= y
;
518 IntShowMousePointer(ppdev
, pso
);
521 prcl
->left
= x
- pgp
->HotSpot
.x
;
522 prcl
->top
= y
- pgp
->HotSpot
.y
;
523 prcl
->right
= prcl
->left
+ pgp
->Size
.cx
;
524 prcl
->bottom
= prcl
->top
+ pgp
->Size
.cy
;
527 else if (prcl
!= NULL
)
529 prcl
->left
= prcl
->top
= prcl
->right
= prcl
->bottom
= -1;
534 IntEngSetPointerShape(
537 IN SURFOBJ
*psoColor
,
546 ULONG ulResult
= SPS_DECLINE
;
547 PFN_DrvSetPointerShape pfnSetPointerShape
;
548 PPDEVOBJ ppdev
= GDIDEV(pso
);
550 pfnSetPointerShape
= GDIDEVFUNCS(pso
).SetPointerShape
;
552 if (pfnSetPointerShape
)
554 ulResult
= pfnSetPointerShape(pso
,
566 /* Check if the driver accepted it */
567 if (ulResult
== SPS_ACCEPT_NOEXCLUDE
)
569 /* Set MovePointer to the driver function */
570 ppdev
->pfnMovePointer
= GDIDEVFUNCS(pso
).MovePointer
;
574 /* Set software pointer */
575 ulResult
= EngSetPointerShape(pso
,
585 /* Set MovePointer to the eng function */
586 ppdev
->pfnMovePointer
= EngMovePointer
;
604 PSURFACE psurf
, psurfMask
, psurfColor
;
609 pdc
= DC_LockDc(hdc
);
612 DPRINT1("Failed to lock the DC.\n");
616 ASSERT(pdc
->dctype
== DCTYPE_DIRECT
);
617 EngAcquireSemaphore(pdc
->ppdev
->hsemDevLock
);
618 /* We're not sure DC surface is the good one */
619 psurf
= pdc
->ppdev
->pSurface
;
622 DPRINT1("DC has no surface.\n");
623 EngReleaseSemaphore(pdc
->ppdev
->hsemDevLock
);
628 /* Lock the mask bitmap */
630 psurfMask
= SURFACE_ShareLockSurface(hbmMask
);
634 /* Check for color bitmap */
637 /* We have one, lock it */
638 psurfColor
= SURFACE_ShareLockSurface(hbmColor
);
642 /* Create an XLATEOBJ, no mono support */
643 EXLATEOBJ_vInitialize(&exlo
, psurfColor
->ppal
, psurf
->ppal
, 0, 0, 0);
649 /* Call the driver or eng function */
650 ulResult
= IntEngSetPointerShape(&psurf
->SurfObj
,
651 psurfMask
? &psurfMask
->SurfObj
: NULL
,
652 psurfColor
? &psurfColor
->SurfObj
: NULL
,
653 psurfColor
? &exlo
.xlo
: NULL
,
658 &pdc
->ppdev
->Pointer
.Exclude
,
664 EXLATEOBJ_vCleanup(&exlo
);
665 SURFACE_ShareUnlockSurface(psurfColor
);
669 SURFACE_ShareUnlockSurface(psurfMask
);
671 EngReleaseSemaphore(pdc
->ppdev
->hsemDevLock
);
691 pdc
= DC_LockDc(hdc
);
694 DPRINT1("Failed to lock the DC.\n");
697 ASSERT(pdc
->dctype
== DCTYPE_DIRECT
);
699 /* Acquire PDEV lock */
700 EngAcquireSemaphore(pdc
->ppdev
->hsemDevLock
);
702 /* Check if we need to move it */
703 if(pdc
->ppdev
->SafetyRemoveLevel
== 0)
705 /* Store the cursor exclude position in the PDEV */
706 prcl
= &pdc
->ppdev
->Pointer
.Exclude
;
708 /* Call Eng/Drv function */
709 pdc
->ppdev
->pfnMovePointer(&pdc
->ppdev
->pSurface
->SurfObj
, x
, y
, prcl
);
712 /* Release PDEV lock */
713 EngReleaseSemaphore(pdc
->ppdev
->hsemDevLock
);