Compile with new layout
[reactos.git] / reactos / subsys / win32k / eng / mouse.c
1 #include <ddk/ntddk.h>
2 #include <win32k/dc.h>
3 #include "../../drivers/input/include/mouse.h"
4 #include "objects.h"
5
6 BOOLEAN SafetySwitch = FALSE, SafetySwitch2 = FALSE, MouseEnabled = FALSE;
7 LONG mouse_x, mouse_y;
8 UINT mouse_width = 0, mouse_height = 0;
9
10 INT MouseSafetyOnDrawStart(PSURFOBJ SurfObj, PSURFGDI SurfGDI, LONG HazardX1, LONG HazardY1, LONG HazardX2, LONG HazardY2)
11 {
12 RECTL MouseRect;
13 LONG tmp;
14
15 if(SurfObj == NULL) return 0;
16
17 if((SurfObj->iType != STYPE_DEVICE) || (MouseEnabled == FALSE)) return 0;
18
19 if(HazardX1 > HazardX2) { tmp = HazardX2; HazardX2 = HazardX1; HazardX1 = tmp; }
20 if(HazardY1 > HazardY2) { tmp = HazardY2; HazardY2 = HazardY1; HazardY1 = tmp; }
21
22 if( (mouse_x + mouse_width >= HazardX1) && (mouse_x <= HazardX2) &&
23 (mouse_y + mouse_height >= HazardY1) && (mouse_y <= HazardY2) )
24 {
25 SurfGDI->MovePointer(SurfObj, -1, -1, &MouseRect);
26 SafetySwitch = TRUE;
27 }
28
29 // Mouse is not allowed to move if GDI is busy drawing
30 SafetySwitch2 = TRUE;
31
32 return 1;
33 }
34
35 INT MouseSafetyOnDrawEnd(PSURFOBJ SurfObj, PSURFGDI SurfGDI)
36 {
37 RECTL MouseRect;
38
39 if(SurfObj == NULL) return 0;
40
41 if((SurfObj->iType != STYPE_DEVICE) || (MouseEnabled == FALSE)) return 0;
42
43 if(SafetySwitch == TRUE)
44 {
45 SurfGDI->MovePointer(SurfObj, mouse_x, mouse_y, &MouseRect);
46 SafetySwitch = FALSE;
47 }
48
49 SafetySwitch2 = FALSE;
50
51 return 1;
52 }
53
54 VOID MouseGDICallBack(PMOUSE_INPUT_DATA Data, ULONG InputCount)
55 {
56 ULONG i;
57 LONG mouse_cx = 0, mouse_cy = 0;
58 /* HDC hDC = RetrieveDisplayHDC();
59 PDC dc = DC_HandleToPtr(hDC);
60 PSURFOBJ SurfObj = (PSURFOBJ)AccessUserObject(dc->Surface);
61 PSURFGDI SurfGDI = (PSURFGDI)AccessInternalObject(dc->Surface);
62 RECTL MouseRect; */
63
64 PDEVICE_OBJECT ClassDeviceObject = NULL;
65 PFILE_OBJECT FileObject = NULL;
66 NTSTATUS status;
67 UNICODE_STRING ClassName;
68 IO_STATUS_BLOCK ioStatus;
69 KEVENT event;
70 PIRP irp;
71
72 // Compile the total mouse movement change
73 for (i=0; i<InputCount; i++)
74 {
75 mouse_cx += Data[i].LastX;
76 mouse_cy += Data[i].LastY;
77 }
78
79 if((mouse_cx != 0) || (mouse_cy != 0))
80 {
81 mouse_x += mouse_cx;
82 mouse_y += mouse_cy;
83
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;
88
89 if((SafetySwitch == FALSE) && (SafetySwitch2 == FALSE)) ;
90 /* SurfGDI->MovePointer(SurfObj, mouse_x, mouse_y, &MouseRect); */
91 }
92 }
93
94 NTSTATUS ConnectMouseClassDriver()
95 {
96 PDEVICE_OBJECT ClassDeviceObject = NULL;
97 PFILE_OBJECT FileObject = NULL;
98 NTSTATUS status;
99 UNICODE_STRING ClassName;
100 IO_STATUS_BLOCK ioStatus;
101 KEVENT event;
102 PIRP irp;
103 GDI_INFORMATION GDIInformation;
104
105 RtlInitUnicodeString(&ClassName, L"\\Device\\MouseClass");
106
107 status = IoGetDeviceObjectPointer(&ClassName, FILE_READ_ATTRIBUTES, &FileObject, &ClassDeviceObject);
108
109 if(status != STATUS_SUCCESS)
110 {
111 DbgPrint("Win32k: Could not connect to mouse class driver\n");
112 return status;
113 }
114
115 // Connect our callback to the class driver
116
117 KeInitializeEvent(&event, NotificationEvent, FALSE);
118
119 GDIInformation.CallBack = MouseGDICallBack;
120
121 irp = IoBuildDeviceIoControlRequest(IOCTL_INTERNAL_MOUSE_CONNECT,
122 ClassDeviceObject, &GDIInformation, sizeof(CLASS_INFORMATION), NULL, 0, TRUE, &event, &ioStatus);
123
124 status = IoCallDriver(ClassDeviceObject, irp);
125
126 if (status == STATUS_PENDING) {
127 KeWaitForSingleObject(&event, Suspended, KernelMode, FALSE, NULL);
128 } else {
129 ioStatus.Status = status;
130 }
131
132 return ioStatus.Status;
133 }
134 /*
135 void TestMouse()
136 {
137 HDC hDC = RetrieveDisplayHDC();
138 PDC dc = DC_HandleToPtr(hDC);
139 PSURFOBJ SurfObj = (PSURFOBJ)AccessUserObject(dc->Surface);
140 PSURFGDI SurfGDI = (PSURFGDI)AccessInternalObject(dc->Surface);
141 BOOL txt;
142 int i;
143
144 BRUSHOBJ Brush;
145 HBITMAP hMouseSurf;
146 PSURFOBJ MouseSurf;
147 SIZEL MouseSize;
148 POINTL ZeroPoint;
149 RECTL MouseRect;
150
151 // Draw a test mouse cursor
152 mouse_width = 16;
153 mouse_height = 16;
154
155 // Draw transparent colored rectangle
156 Brush.iSolidColor = 5;
157 for (i = 0; i < 17; i++)
158 EngLineTo(SurfObj, NULL, &Brush, 0, i, 17, i, NULL, 0);
159
160 // Draw white interior
161 Brush.iSolidColor = 15;
162 for (i = 1; i < 16; i++)
163 EngLineTo(SurfObj, NULL, &Brush, 0, i-1, 16-i, i-1, NULL, 0);
164
165 // Draw black outline
166 Brush.iSolidColor = 0;
167 EngLineTo(SurfObj, NULL, &Brush, 0, 0, 15, 0, NULL, 0);
168 EngLineTo(SurfObj, NULL, &Brush, 0, 16, 15, 0, NULL, 0);
169 EngLineTo(SurfObj, NULL, &Brush, 0, 15, 0, 0, NULL, 0);
170
171 // Create the bitmap for the mouse cursor data
172 MouseSize.cx = 16;
173 MouseSize.cy = 16;
174 hMouseSurf = EngCreateBitmap(MouseSize, 16, BMF_4BPP, 0, NULL);
175 MouseSurf = (PSURFOBJ)AccessUserObject(hMouseSurf);
176
177 // Capture the cursor we drew in the mouse cursor buffer
178 ZeroPoint.x = 0;
179 ZeroPoint.y = 0;
180 MouseRect.top = 0;
181 MouseRect.left = 0;
182 MouseRect.bottom = 16;
183 MouseRect.right = 16;
184 EngBitBlt(MouseSurf, SurfObj, NULL, NULL, NULL, &MouseRect, &ZeroPoint, NULL, NULL, NULL, 0);
185 SurfGDI->SetPointerShape(SurfObj, MouseSurf, NULL, NULL, 0, 0, 50, 50, &MouseRect, 0);
186
187 // Connect the mouse class driver to the GDI
188 mouse_x = 50;
189 mouse_y = 50;
190 ConnectMouseClassDriver();
191 MouseEnabled = TRUE;
192 }
193 */