Misc. user fixes.
[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 = W32kGetScreenDC();
59 PDC dc;
60 PSURFOBJ SurfObj;
61 PSURFGDI SurfGDI;
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 if (hDC == 0)
73 {
74 return;
75 }
76
77 dc = DC_HandleToPtr(hDC);
78 SurfObj = (PSURFOBJ)AccessUserObject(dc->Surface);
79 SurfGDI = (PSURFGDI)AccessInternalObject(dc->Surface);
80
81 // Compile the total mouse movement change
82 for (i=0; i<InputCount; i++)
83 {
84 mouse_cx += Data[i].LastX;
85 mouse_cy += Data[i].LastY;
86 }
87
88 if((mouse_cx != 0) || (mouse_cy != 0))
89 {
90 mouse_x += mouse_cx;
91 mouse_y += mouse_cy;
92
93 if(mouse_x < 0) mouse_x = 0;
94 if(mouse_y < 0) mouse_y = 0;
95 if(mouse_x > 620) mouse_x = 620;
96 if(mouse_y > 460) mouse_y = 460;
97
98 if((SafetySwitch == FALSE) && (SafetySwitch2 == FALSE)) ;
99 SurfGDI->MovePointer(SurfObj, mouse_x, mouse_y, &MouseRect);
100 }
101 }
102
103 VOID EnableMouse(HDC hDisplayDC)
104 {
105 PDC dc = DC_HandleToPtr(hDisplayDC);
106 PSURFOBJ SurfObj = (PSURFOBJ)AccessUserObject(dc->Surface);
107 PSURFGDI SurfGDI = (PSURFGDI)AccessInternalObject(dc->Surface);
108 BOOL txt;
109 int i;
110
111 BRUSHOBJ Brush;
112 HBITMAP hMouseSurf;
113 PSURFOBJ MouseSurf;
114 SIZEL MouseSize;
115 POINTL ZeroPoint;
116 RECTL MouseRect;
117
118 // Draw a test mouse cursor
119 mouse_width = 16;
120 mouse_height = 16;
121
122 // Draw transparent colored rectangle
123 Brush.iSolidColor = 5;
124 for (i = 0; i < 17; i++)
125 EngLineTo(SurfObj, NULL, &Brush, 0, i, 17, i, NULL, 0);
126
127 // Draw white interior
128 Brush.iSolidColor = 15;
129 for (i = 1; i < 16; i++)
130 EngLineTo(SurfObj, NULL, &Brush, 0, i-1, 16-i, i-1, NULL, 0);
131
132 // Draw black outline
133 Brush.iSolidColor = 0;
134 EngLineTo(SurfObj, NULL, &Brush, 0, 0, 15, 0, NULL, 0);
135 EngLineTo(SurfObj, NULL, &Brush, 0, 16, 15, 0, NULL, 0);
136 EngLineTo(SurfObj, NULL, &Brush, 0, 15, 0, 0, NULL, 0);
137
138 // Create the bitmap for the mouse cursor data
139 MouseSize.cx = 16;
140 MouseSize.cy = 16;
141 hMouseSurf = EngCreateBitmap(MouseSize, 16, BMF_4BPP, 0, NULL);
142 MouseSurf = (PSURFOBJ)AccessUserObject(hMouseSurf);
143
144 // Capture the cursor we drew in the mouse cursor buffer
145 ZeroPoint.x = 0;
146 ZeroPoint.y = 0;
147 MouseRect.top = 0;
148 MouseRect.left = 0;
149 MouseRect.bottom = 16;
150 MouseRect.right = 16;
151 EngBitBlt(MouseSurf, SurfObj, NULL, NULL, NULL, &MouseRect, &ZeroPoint, NULL, NULL, NULL, 0);
152 SurfGDI->SetPointerShape(SurfObj, MouseSurf, NULL, NULL, 0, 0, 50, 50, &MouseRect, 0);
153
154 mouse_x = 320;
155 mouse_y = 240;
156 MouseEnabled = TRUE;
157 }
158