3 #include "..\..\services\input\include\mouse.h"
6 BOOLEAN SafetySwitch
= FALSE
, SafetySwitch2
= FALSE
, MouseEnabled
= FALSE
;
8 UINT mouse_width
= 0, mouse_height
= 0;
10 INT
MouseSafetyOnDrawStart(PSURFOBJ SurfObj
, PSURFGDI SurfGDI
, LONG HazardX1
, LONG HazardY1
, LONG HazardX2
, LONG HazardY2
)
15 if(SurfObj
== NULL
) return 0;
17 if((SurfObj
->iType
!= STYPE_DEVICE
) || (MouseEnabled
== FALSE
)) return 0;
19 if(HazardX1
> HazardX2
) { tmp
= HazardX2
; HazardX2
= HazardX1
; HazardX1
= tmp
; }
20 if(HazardY1
> HazardY2
) { tmp
= HazardY2
; HazardY2
= HazardY1
; HazardY1
= tmp
; }
22 if( (mouse_x
+ mouse_width
>= HazardX1
) && (mouse_x
<= HazardX2
) &&
23 (mouse_y
+ mouse_height
>= HazardY1
) && (mouse_y
<= HazardY2
) )
25 SurfGDI
->MovePointer(SurfObj
, -1, -1, &MouseRect
);
29 // Mouse is not allowed to move if GDI is busy drawing
35 INT
MouseSafetyOnDrawEnd(PSURFOBJ SurfObj
, PSURFGDI SurfGDI
)
39 if(SurfObj
== NULL
) return 0;
41 if((SurfObj
->iType
!= STYPE_DEVICE
) || (MouseEnabled
== FALSE
)) return 0;
43 if(SafetySwitch
== TRUE
)
45 SurfGDI
->MovePointer(SurfObj
, mouse_x
, mouse_y
, &MouseRect
);
49 SafetySwitch2
= FALSE
;
54 VOID
MouseGDICallBack(PMOUSE_INPUT_DATA Data
, ULONG InputCount
)
57 LONG mouse_cx
= 0, mouse_cy
= 0;
58 HDC hDC
= RetrieveDisplayHDC();
59 PDC dc
= DC_HandleToPtr(hDC
);
60 PSURFOBJ SurfObj
= AccessUserObject(dc
->Surface
);
61 PSURFGDI SurfGDI
= AccessInternalObject(dc
->Surface
);
64 PDEVICE_OBJECT ClassDeviceObject
= NULL
;
65 PFILE_OBJECT FileObject
= NULL
;
67 UNICODE_STRING ClassName
;
68 IO_STATUS_BLOCK ioStatus
;
72 // Compile the total mouse movement change
73 for (i
=0; i
<InputCount
; i
++)
75 mouse_cx
+= Data
[i
].LastX
;
76 mouse_cy
+= Data
[i
].LastY
;
79 if((mouse_cx
!= 0) || (mouse_cy
!= 0))
84 if(mouse_x
< 0) mouse_x
= 0;
85 if(mouse_y
< 0) mouse_y
= 0;
86 if(mouse_x
> 620) mouse_x
= 620;
87 if(mouse_y
> 460) mouse_y
= 460;
89 if((SafetySwitch
== FALSE
) && (SafetySwitch2
== FALSE
))
90 SurfGDI
->MovePointer(SurfObj
, mouse_x
, mouse_y
, &MouseRect
);
94 NTSTATUS
ConnectMouseClassDriver()
96 PDEVICE_OBJECT ClassDeviceObject
= NULL
;
97 PFILE_OBJECT FileObject
= NULL
;
99 UNICODE_STRING ClassName
;
100 IO_STATUS_BLOCK ioStatus
;
103 GDI_INFORMATION GDIInformation
;
105 RtlInitUnicodeString(&ClassName
, L
"\\Device\\MouseClass");
107 status
= IoGetDeviceObjectPointer(&ClassName
, FILE_READ_ATTRIBUTES
, &FileObject
, &ClassDeviceObject
);
109 if(status
!= STATUS_SUCCESS
)
111 DbgPrint("Win32k: Could not connect to mouse class driver\n");
115 // Connect our callback to the class driver
117 KeInitializeEvent(&event
, NotificationEvent
, FALSE
);
119 GDIInformation
.CallBack
= MouseGDICallBack
;
121 irp
= IoBuildDeviceIoControlRequest(IOCTL_INTERNAL_MOUSE_CONNECT
,
122 ClassDeviceObject
, &GDIInformation
, sizeof(CLASS_INFORMATION
), NULL
, 0, TRUE
, &event
, &ioStatus
);
124 status
= IoCallDriver(ClassDeviceObject
, irp
);
126 if (status
== STATUS_PENDING
) {
127 KeWaitForSingleObject(&event
, Suspended
, KernelMode
, FALSE
, NULL
);
129 ioStatus
.Status
= status
;
132 return ioStatus
.Status
;
137 HDC hDC
= RetrieveDisplayHDC(RetrieveDisplayHDC());
138 PDC dc
= DC_HandleToPtr(hDC
);
139 PSURFOBJ SurfObj
= AccessUserObject(dc
->Surface
);
140 PSURFGDI SurfGDI
= AccessInternalObject(dc
->Surface
);
151 // Draw a test mouse cursor
152 /* Brush.iSolidColor = 1;
153 EngLineTo(SurfObj, NULL, &Brush, 0, 0, 15, 0, NULL, 0);
154 EngLineTo(SurfObj, NULL, &Brush, 0, 0, 0, 15, NULL, 0);
155 EngLineTo(SurfObj, NULL, &Brush, 0, 15, 15, 0, NULL, 0);
156 Brush.iSolidColor = 15;
157 EngLineTo(SurfObj, NULL, &Brush, 1, 1, 13, 1, NULL, 0);
158 EngLineTo(SurfObj, NULL, &Brush, 1, 1, 1, 13, NULL, 0);
159 EngLineTo(SurfObj, NULL, &Brush, 1, 13, 13, 1, NULL, 0); */
164 // Draw transparent colored rectangle
165 Brush
.iSolidColor
= 5;
166 for (i
= 0; i
< 17; i
++)
167 EngLineTo(SurfObj
, NULL
, &Brush
, 0, i
, 17, i
, NULL
, 0);
169 // Draw white interior
170 Brush
.iSolidColor
= 15;
171 for (i
= 1; i
< 16; i
++)
172 EngLineTo(SurfObj
, NULL
, &Brush
, 0, i
-1, 16-i
, i
-1, NULL
, 0);
174 // Draw black outline
175 Brush
.iSolidColor
= 0;
176 EngLineTo(SurfObj
, NULL
, &Brush
, 0, 0, 15, 0, NULL
, 0);
177 EngLineTo(SurfObj
, NULL
, &Brush
, 0, 16, 15, 0, NULL
, 0);
178 EngLineTo(SurfObj
, NULL
, &Brush
, 0, 15, 0, 0, NULL
, 0);
180 // Create the bitmap for the mouse cursor data
183 hMouseSurf
= EngCreateBitmap(MouseSize
, 16, BMF_4BPP
, 0, NULL
);
184 MouseSurf
= AccessUserObject(hMouseSurf
);
186 // Capture the cursor we drew in the mouse cursor buffer
191 MouseRect
.bottom
= 16;
192 MouseRect
.right
= 16;
193 EngBitBlt(MouseSurf
, SurfObj
, NULL
, NULL
, NULL
, &MouseRect
, &ZeroPoint
, NULL
, NULL
, NULL
, 0);
194 SurfGDI
->SetPointerShape(SurfObj
, MouseSurf
, NULL
, NULL
, 0, 0, 50, 50, &MouseRect
, 0);
196 // Connect the mouse class driver to the GDI
199 ConnectMouseClassDriver();