2 * PROJECT: ReactOS win32 subsystem
3 * PURPOSE: Mouse pointer functions
4 * FILE: subsystems/win32k/eng/mouse.c
5 * PROGRAMER: Casper S. Hornstrup (chorns@users.sourceforge.net)
6 * Timo Kreuzer (timo.kreuzer@reactos.org)
8 * 06-06-2001 CSH Created
10 /* INCLUDES ******************************************************************/
17 /* FUNCTIONS *****************************************************************/
28 // This function is obsolete for Windows 2000 and later.
29 // This function is still supported, but always returns FALSE.
30 // www.osr.com/ddk/graphics/gdifncs_4yav.htm
35 * FUNCTION: Notify the mouse driver that drawing is about to begin in
36 * a rectangle on a particular surface.
39 MouseSafetyOnDrawStart(
49 ASSERT(ppdev
!= NULL
);
50 ASSERT(ppdev
->pSurface
!= NULL
);
52 pgp
= &ppdev
->Pointer
;
54 if (pgp
->Exclude
.right
== -1)
59 ppdev
->SafetyRemoveCount
++;
61 if (ppdev
->SafetyRemoveLevel
!= 0)
66 if (HazardX1
> HazardX2
)
72 if (HazardY1
> HazardY2
)
79 if (pgp
->Exclude
.right
>= HazardX1
80 && pgp
->Exclude
.left
<= HazardX2
81 && pgp
->Exclude
.bottom
>= HazardY1
82 && pgp
->Exclude
.top
<= HazardY2
)
84 ppdev
->SafetyRemoveLevel
= ppdev
->SafetyRemoveCount
;
85 ppdev
->pfnMovePointer(&ppdev
->pSurface
->SurfObj
, -1, -1, NULL
);
92 * FUNCTION: Notify the mouse driver that drawing has finished on a surface.
100 ASSERT(ppdev
!= NULL
);
101 ASSERT(ppdev
->pSurface
!= NULL
);
103 pgp
= &ppdev
->Pointer
;
105 if (pgp
->Exclude
.right
== -1)
110 if (--ppdev
->SafetyRemoveCount
>= ppdev
->SafetyRemoveLevel
)
115 ppdev
->pfnMovePointer(&ppdev
->pSurface
->SurfObj
,
120 ppdev
->SafetyRemoveLevel
= 0;
125 /* SOFTWARE MOUSE POINTER IMPLEMENTATION **************************************/
141 pgp
= &ppdev
->Pointer
;
148 pgp
->Enabled
= FALSE
;
152 DPRINT1("No SaveSurface!\n");
156 /* Calculate cursor coordinates */
157 pt
.x
= ppdev
->ptlPointer
.x
- pgp
->HotSpot
.x
;
158 pt
.y
= ppdev
->ptlPointer
.y
- pgp
->HotSpot
.y
;
160 rclDest
.left
= max(pt
.x
, 0);
161 rclDest
.top
= max(pt
.y
, 0);
162 rclDest
.right
= min(pt
.x
+ pgp
->Size
.cx
, psoDest
->sizlBitmap
.cx
);
163 rclDest
.bottom
= min(pt
.y
+ pgp
->Size
.cy
, psoDest
->sizlBitmap
.cy
);
165 ptlSave
.x
= rclDest
.left
- pt
.x
;
166 ptlSave
.y
= rclDest
.top
- pt
.y
;
168 IntEngBitBlt(psoDest
,
169 &pgp
->psurfSave
->SurfObj
,
178 ROP4_FROM_INDEX(R3_OPINDEX_SRCCOPY
));
183 IntShowMousePointer(PDEVOBJ
*ppdev
, SURFOBJ
*psoDest
)
187 RECTL rclSurf
, rclPointer
;
192 pgp
= &ppdev
->Pointer
;
201 /* Check if we have any mouse pointer */
202 if (!pgp
->psurfSave
) return;
204 /* Calculate pointer coordinates */
205 pt
.x
= ppdev
->ptlPointer
.x
- pgp
->HotSpot
.x
;
206 pt
.y
= ppdev
->ptlPointer
.y
- pgp
->HotSpot
.y
;
208 /* Calculate the rect on the surface */
209 rclSurf
.left
= max(pt
.x
, 0);
210 rclSurf
.top
= max(pt
.y
, 0);
211 rclSurf
.right
= min(pt
.x
+ pgp
->Size
.cx
, psoDest
->sizlBitmap
.cx
);
212 rclSurf
.bottom
= min(pt
.y
+ pgp
->Size
.cy
, psoDest
->sizlBitmap
.cy
);
214 /* Calculate the rect in the pointer bitmap */
215 rclPointer
.left
= rclSurf
.left
- pt
.x
;
216 rclPointer
.top
= rclSurf
.top
- pt
.y
;
217 rclPointer
.right
= min(pgp
->Size
.cx
, psoDest
->sizlBitmap
.cx
- pt
.x
);
218 rclPointer
.bottom
= min(pgp
->Size
.cy
, psoDest
->sizlBitmap
.cy
- pt
.y
);
220 /* Copy the pixels under the cursor to temporary surface. */
221 IntEngBitBlt(&pgp
->psurfSave
->SurfObj
,
231 ROP4_FROM_INDEX(R3_OPINDEX_SRCCOPY
));
233 /* Blt the pointer on the screen. */
236 IntEngBitBlt(psoDest
,
237 &pgp
->psurfMask
->SurfObj
,
242 (POINTL
*)&rclPointer
,
246 ROP4_FROM_INDEX(R3_OPINDEX_SRCAND
));
248 IntEngBitBlt(psoDest
,
249 &pgp
->psurfColor
->SurfObj
,
254 (POINTL
*)&rclPointer
,
258 ROP4_FROM_INDEX(R3_OPINDEX_SRCINVERT
));
262 IntEngBitBlt(psoDest
,
263 &pgp
->psurfMask
->SurfObj
,
268 (POINTL
*)&rclPointer
,
272 ROP4_FROM_INDEX(R3_OPINDEX_SRCAND
));
274 rclPointer
.top
+= pgp
->Size
.cy
;
276 IntEngBitBlt(psoDest
,
277 &pgp
->psurfMask
->SurfObj
,
282 (POINTL
*)&rclPointer
,
286 ROP4_FROM_INDEX(R3_OPINDEX_SRCINVERT
));
297 IN SURFOBJ
*psoColor
,
309 HBITMAP hbmSave
= NULL
, hbmColor
= NULL
, hbmMask
= NULL
;
310 PSURFACE psurfSave
= NULL
, psurfColor
= NULL
, psurfMask
= NULL
;
312 SIZEL sizel
= {0, 0};
317 pgp
= &ppdev
->Pointer
;
319 /* Do we have any bitmap at all? */
320 if (psoColor
|| psoMask
)
322 /* Get the size of the new pointer */
325 sizel
.cx
= psoColor
->sizlBitmap
.cx
;
326 sizel
.cy
= psoColor
->sizlBitmap
.cy
;
330 sizel
.cx
= psoMask
->sizlBitmap
.cx
;
331 sizel
.cy
= psoMask
->sizlBitmap
.cy
/ 2;
336 rectl
.right
= sizel
.cx
;
337 rectl
.bottom
= sizel
.cy
;
339 /* Calculate lDelta for our surfaces. */
340 lDelta
= WIDTH_BYTES_ALIGN32(sizel
.cx
,
341 BitsPerFormat(pso
->iBitmapFormat
));
343 /* Create a bitmap for saving the pixels under the cursor. */
344 hbmSave
= EngCreateBitmap(sizel
,
347 BMF_TOPDOWN
| BMF_NOZEROINIT
,
349 psurfSave
= SURFACE_ShareLockSurface(hbmSave
);
350 if (!psurfSave
) goto failure
;
355 /* Color bitmap must have the same format as the dest surface */
356 if (psoColor
->iBitmapFormat
!= pso
->iBitmapFormat
) goto failure
;
358 /* Create a bitmap to copy the color bitmap to */
359 hbmColor
= EngCreateBitmap(psoColor
->sizlBitmap
,
362 BMF_TOPDOWN
| BMF_NOZEROINIT
,
364 psurfColor
= SURFACE_ShareLockSurface(hbmColor
);
365 if (!psurfColor
) goto failure
;
367 /* Now copy the given bitmap */
368 rectl
.bottom
= psoColor
->sizlBitmap
.cy
;
369 IntEngCopyBits(&psurfColor
->SurfObj
,
377 /* Create a mask surface */
383 /* Create a bitmap for the mask */
384 hbmMask
= EngCreateBitmap(psoMask
->sizlBitmap
,
387 BMF_TOPDOWN
| BMF_NOZEROINIT
,
389 psurfMask
= SURFACE_ShareLockSurface(hbmMask
);
390 if (!psurfMask
) goto failure
;
392 /* Initialize an EXLATEOBJ */
393 ppal
= PALETTE_ShareLockPalette(ppdev
->devinfo
.hpalDefault
);
394 EXLATEOBJ_vInitialize(&exlo
,
401 /* Copy the mask bitmap */
402 rectl
.bottom
= psoMask
->sizlBitmap
.cy
;
403 IntEngCopyBits(&psurfMask
->SurfObj
,
411 EXLATEOBJ_vCleanup(&exlo
);
412 if (ppal
) PALETTE_ShareUnlockPalette(ppal
);
415 /* Hide mouse pointer */
416 IntHideMousePointer(ppdev
, pso
);
418 /* Free old color bitmap */
421 EngDeleteSurface(pgp
->psurfColor
->BaseObject
.hHmgr
);
422 SURFACE_ShareUnlockSurface(pgp
->psurfColor
);
423 pgp
->psurfColor
= NULL
;
426 /* Free old mask bitmap */
429 EngDeleteSurface(pgp
->psurfMask
->BaseObject
.hHmgr
);
430 SURFACE_ShareUnlockSurface(pgp
->psurfMask
);
431 pgp
->psurfMask
= NULL
;
434 /* Free old save bitmap */
437 EngDeleteSurface(pgp
->psurfSave
->BaseObject
.hHmgr
);
438 SURFACE_ShareUnlockSurface(pgp
->psurfSave
);
439 pgp
->psurfSave
= NULL
;
442 /* See if we are being asked to hide the pointer. */
443 if (psoMask
== NULL
&& psoColor
== NULL
)
446 return SPS_ACCEPT_NOEXCLUDE
;
449 /* Now set the new cursor */
450 pgp
->psurfColor
= psurfColor
;
451 pgp
->psurfMask
= psurfMask
;
452 pgp
->psurfSave
= psurfSave
;
453 pgp
->HotSpot
.x
= xHot
;
454 pgp
->HotSpot
.y
= yHot
;
459 ppdev
->ptlPointer
.x
= x
;
460 ppdev
->ptlPointer
.y
= y
;
462 IntShowMousePointer(ppdev
, pso
);
466 prcl
->left
= x
- pgp
->HotSpot
.x
;
467 prcl
->top
= y
- pgp
->HotSpot
.x
;
468 prcl
->right
= prcl
->left
+ pgp
->Size
.cx
;
469 prcl
->bottom
= prcl
->top
+ pgp
->Size
.cy
;
472 else if (prcl
!= NULL
)
474 prcl
->left
= prcl
->top
= prcl
->right
= prcl
->bottom
= -1;
477 return SPS_ACCEPT_NOEXCLUDE
;
480 /* Cleanup surfaces */
481 if (hbmMask
) EngDeleteSurface(hbmMask
);
482 if (psurfMask
) SURFACE_ShareUnlockSurface(psurfMask
);
483 if (hbmColor
) EngDeleteSurface(hbmColor
);
484 if (psurfColor
) SURFACE_ShareUnlockSurface(psurfColor
);
485 if (hbmSave
) EngDeleteSurface(hbmSave
);
486 if (psurfSave
) SURFACE_ShareUnlockSurface(psurfSave
);
510 pgp
= &ppdev
->Pointer
;
512 IntHideMousePointer(ppdev
, pso
);
514 ppdev
->ptlPointer
.x
= x
;
515 ppdev
->ptlPointer
.y
= y
;
519 IntShowMousePointer(ppdev
, pso
);
522 prcl
->left
= x
- pgp
->HotSpot
.x
;
523 prcl
->top
= y
- pgp
->HotSpot
.y
;
524 prcl
->right
= prcl
->left
+ pgp
->Size
.cx
;
525 prcl
->bottom
= prcl
->top
+ pgp
->Size
.cy
;
528 else if (prcl
!= NULL
)
530 prcl
->left
= prcl
->top
= prcl
->right
= prcl
->bottom
= -1;
535 IntEngSetPointerShape(
538 IN SURFOBJ
*psoColor
,
547 ULONG ulResult
= SPS_DECLINE
;
548 PFN_DrvSetPointerShape pfnSetPointerShape
;
549 PPDEVOBJ ppdev
= GDIDEV(pso
);
551 pfnSetPointerShape
= GDIDEVFUNCS(pso
).SetPointerShape
;
553 if (pfnSetPointerShape
)
555 ulResult
= pfnSetPointerShape(pso
,
567 /* Check if the driver accepted it */
568 if (ulResult
== SPS_ACCEPT_NOEXCLUDE
)
570 /* Set MovePointer to the driver function */
571 ppdev
->pfnMovePointer
= GDIDEVFUNCS(pso
).MovePointer
;
575 /* Set software pointer */
576 ulResult
= EngSetPointerShape(pso
,
586 /* Set MovePointer to the eng function */
587 ppdev
->pfnMovePointer
= EngMovePointer
;
605 PSURFACE psurf
, psurfMask
, psurfColor
;
610 pdc
= DC_LockDc(hdc
);
613 DPRINT1("Failed to lock the DC.\n");
617 ASSERT(pdc
->dctype
== DCTYPE_DIRECT
);
618 EngAcquireSemaphore(pdc
->ppdev
->hsemDevLock
);
619 /* We're not sure DC surface is the good one */
620 psurf
= pdc
->ppdev
->pSurface
;
623 DPRINT1("DC has no surface.\n");
624 EngReleaseSemaphore(pdc
->ppdev
->hsemDevLock
);
629 /* Lock the mask bitmap */
631 psurfMask
= SURFACE_ShareLockSurface(hbmMask
);
635 /* Check for color bitmap */
638 /* We have one, lock it */
639 psurfColor
= SURFACE_ShareLockSurface(hbmColor
);
643 /* Create an XLATEOBJ, no mono support */
644 EXLATEOBJ_vInitialize(&exlo
, psurfColor
->ppal
, psurf
->ppal
, 0, 0, 0);
650 /* Call the driver or eng function */
651 ulResult
= IntEngSetPointerShape(&psurf
->SurfObj
,
652 psurfMask
? &psurfMask
->SurfObj
: NULL
,
653 psurfColor
? &psurfColor
->SurfObj
: NULL
,
654 psurfColor
? &exlo
.xlo
: NULL
,
659 &pdc
->ppdev
->Pointer
.Exclude
,
665 EXLATEOBJ_vCleanup(&exlo
);
666 SURFACE_ShareUnlockSurface(psurfColor
);
670 SURFACE_ShareUnlockSurface(psurfMask
);
672 EngReleaseSemaphore(pdc
->ppdev
->hsemDevLock
);
692 pdc
= DC_LockDc(hdc
);
695 DPRINT1("Failed to lock the DC.\n");
698 ASSERT(pdc
->dctype
== DCTYPE_DIRECT
);
700 /* Acquire PDEV lock */
701 EngAcquireSemaphore(pdc
->ppdev
->hsemDevLock
);
703 /* Check if we need to move it */
704 if(pdc
->ppdev
->SafetyRemoveLevel
== 0)
706 /* Store the cursor exclude position in the PDEV */
707 prcl
= &pdc
->ppdev
->Pointer
.Exclude
;
709 /* Call Eng/Drv function */
710 pdc
->ppdev
->pfnMovePointer(&pdc
->ppdev
->pSurface
->SurfObj
, x
, y
, prcl
);
713 /* Release PDEV lock */
714 EngReleaseSemaphore(pdc
->ppdev
->hsemDevLock
);