[CMAKE]
[reactos.git] / subsystems / win32 / win32k / include / desktop.h
1 #pragma once
2
3 #include "msgqueue.h"
4 #include "window.h"
5
6 typedef struct _DESKTOP
7 {
8 PDESKTOPINFO pDeskInfo;
9 LIST_ENTRY ListEntry;
10 /* Pointer to the associated window station. */
11 struct _WINSTATION_OBJECT *rpwinstaParent;
12 DWORD dwDTFlags;
13 PWND spwndForeground;
14 PWND spwndTray;
15 PWND spwndMessage;
16 PWND spwndTooltip;
17 PSECTION_OBJECT hsectionDesktop;
18 PWIN32HEAP pheapDesktop;
19 ULONG_PTR ulHeapSize;
20 LIST_ENTRY PtiList;
21 /* use for tracking mouse moves. */
22 PWND spwndTrack;
23 DWORD htEx;
24 RECT rcMouseHover;
25 DWORD dwMouseHoverTime;
26
27 /* ReactOS */
28 /* Pointer to the active queue. */
29 PVOID ActiveMessageQueue;
30 /* Handle of the desktop window. */
31 HWND DesktopWindow;
32 /* Thread blocking input */
33 PVOID BlockInputThread;
34 LIST_ENTRY ShellHookWindows;
35 } DESKTOP, *PDESKTOP;
36
37 // Desktop flags
38 #define DF_TME_HOVER 0x00000400
39 #define DF_TME_LEAVE 0x00000800
40 #define DF_DESTROYED 0x00008000
41 #define DF_DESKWNDDESTROYED 0x00010000
42 #define DF_DYING 0x00020000
43
44
45 extern PDESKTOP InputDesktop;
46 extern HDESK InputDesktopHandle;
47 extern PCLS DesktopWindowClass;
48 extern HDC ScreenDeviceContext;
49 extern BOOL g_PaintDesktopVersion;
50
51 typedef struct _SHELL_HOOK_WINDOW
52 {
53 LIST_ENTRY ListEntry;
54 HWND hWnd;
55 } SHELL_HOOK_WINDOW, *PSHELL_HOOK_WINDOW;
56
57 INIT_FUNCTION
58 NTSTATUS
59 NTAPI
60 InitDesktopImpl(VOID);
61
62 NTSTATUS FASTCALL
63 CleanupDesktopImpl(VOID);
64
65 NTSTATUS
66 APIENTRY
67 IntDesktopObjectParse(IN PVOID ParseObject,
68 IN PVOID ObjectType,
69 IN OUT PACCESS_STATE AccessState,
70 IN KPROCESSOR_MODE AccessMode,
71 IN ULONG Attributes,
72 IN OUT PUNICODE_STRING CompleteName,
73 IN OUT PUNICODE_STRING RemainingName,
74 IN OUT PVOID Context OPTIONAL,
75 IN PSECURITY_QUALITY_OF_SERVICE SecurityQos OPTIONAL,
76 OUT PVOID *Object);
77
78 VOID APIENTRY
79 IntDesktopObjectDelete(PWIN32_DELETEMETHOD_PARAMETERS Parameters);
80
81 NTSTATUS NTAPI
82 IntDesktopOkToClose(PWIN32_OKAYTOCLOSEMETHOD_PARAMETERS Parameters);
83
84 LRESULT CALLBACK
85 IntDesktopWindowProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
86
87 HDC FASTCALL
88 IntGetScreenDC(VOID);
89
90 HWND FASTCALL
91 IntGetDesktopWindow (VOID);
92
93 PWND FASTCALL
94 UserGetDesktopWindow(VOID);
95
96 HWND FASTCALL
97 IntGetCurrentThreadDesktopWindow(VOID);
98
99 PUSER_MESSAGE_QUEUE FASTCALL
100 IntGetFocusMessageQueue(VOID);
101
102 VOID FASTCALL
103 IntSetFocusMessageQueue(PUSER_MESSAGE_QUEUE NewQueue);
104
105 PDESKTOP FASTCALL
106 IntGetActiveDesktop(VOID);
107
108 NTSTATUS FASTCALL
109 co_IntShowDesktop(PDESKTOP Desktop, ULONG Width, ULONG Height);
110
111 NTSTATUS FASTCALL
112 IntHideDesktop(PDESKTOP Desktop);
113
114 HDESK FASTCALL
115 IntGetDesktopObjectHandle(PDESKTOP DesktopObject);
116
117 BOOL IntSetThreadDesktop(IN HDESK hDesktop,
118 IN BOOL FreeOnFailure);
119
120 NTSTATUS FASTCALL
121 IntValidateDesktopHandle(
122 HDESK Desktop,
123 KPROCESSOR_MODE AccessMode,
124 ACCESS_MASK DesiredAccess,
125 PDESKTOP *Object);
126 NTSTATUS FASTCALL
127 IntParseDesktopPath(PEPROCESS Process,
128 PUNICODE_STRING DesktopPath,
129 HWINSTA *hWinSta,
130 HDESK *hDesktop);
131 BOOL FASTCALL IntDesktopUpdatePerUserSettings(BOOL bEnable);
132 VOID APIENTRY UserRedrawDesktop(VOID);
133 BOOL IntRegisterShellHookWindow(HWND hWnd);
134 BOOL IntDeRegisterShellHookWindow(HWND hWnd);
135 VOID co_IntShellHookNotify(WPARAM Message, LPARAM lParam);
136 HDC FASTCALL UserGetDesktopDC(ULONG,BOOL,BOOL);
137 BOOL FASTCALL IntPaintDesktop(HDC hDC);
138
139 #define IntIsActiveDesktop(Desktop) \
140 ((Desktop)->rpwinstaParent->ActiveDesktop == (Desktop))
141
142 #define GET_DESKTOP_NAME(d) \
143 OBJECT_HEADER_TO_NAME_INFO(OBJECT_TO_OBJECT_HEADER(d)) ? \
144 &(OBJECT_HEADER_TO_NAME_INFO(OBJECT_TO_OBJECT_HEADER(d))->Name) : \
145 NULL
146
147 HWND FASTCALL IntGetMessageWindow(VOID);
148
149 static __inline PVOID
150 DesktopHeapAlloc(IN PDESKTOP Desktop,
151 IN SIZE_T Bytes)
152 {
153 return RtlAllocateHeap(Desktop->pheapDesktop,
154 HEAP_NO_SERIALIZE,
155 Bytes);
156 }
157
158 static __inline BOOL
159 DesktopHeapFree(IN PDESKTOP Desktop,
160 IN PVOID lpMem)
161 {
162 return RtlFreeHeap(Desktop->pheapDesktop,
163 HEAP_NO_SERIALIZE,
164 lpMem);
165 }
166
167 static __inline PVOID
168 DesktopHeapReAlloc(IN PDESKTOP Desktop,
169 IN PVOID lpMem,
170 IN SIZE_T Bytes)
171 {
172 #if 0
173 /* NOTE: ntoskrnl doesn't export RtlReAllocateHeap... */
174 return RtlReAllocateHeap(Desktop->pheapDesktop,
175 HEAP_NO_SERIALIZE,
176 lpMem,
177 Bytes);
178 #else
179 SIZE_T PrevSize;
180 PVOID pNew;
181
182 PrevSize = RtlSizeHeap(Desktop->pheapDesktop,
183 HEAP_NO_SERIALIZE,
184 lpMem);
185
186 if (PrevSize == Bytes)
187 return lpMem;
188
189 pNew = RtlAllocateHeap(Desktop->pheapDesktop,
190 HEAP_NO_SERIALIZE,
191 Bytes);
192 if (pNew != NULL)
193 {
194 if (PrevSize < Bytes)
195 Bytes = PrevSize;
196
197 RtlCopyMemory(pNew,
198 lpMem,
199 Bytes);
200
201 RtlFreeHeap(Desktop->pheapDesktop,
202 HEAP_NO_SERIALIZE,
203 lpMem);
204 }
205
206 return pNew;
207 #endif
208 }
209
210 static __inline ULONG_PTR
211 DesktopHeapGetUserDelta(VOID)
212 {
213 PW32HEAP_USER_MAPPING Mapping;
214 PTHREADINFO pti;
215 PPROCESSINFO W32Process;
216 PWIN32HEAP pheapDesktop;
217 ULONG_PTR Delta = 0;
218
219 pti = PsGetCurrentThreadWin32Thread();
220 if (!pti->rpdesk)
221 return 0;
222
223 pheapDesktop = pti->rpdesk->pheapDesktop;
224
225 W32Process = PsGetCurrentProcessWin32Process();
226 Mapping = W32Process->HeapMappings.Next;
227 while (Mapping != NULL)
228 {
229 if (Mapping->KernelMapping == (PVOID)pheapDesktop)
230 {
231 Delta = (ULONG_PTR)Mapping->KernelMapping - (ULONG_PTR)Mapping->UserMapping;
232 break;
233 }
234
235 Mapping = Mapping->Next;
236 }
237
238 return Delta;
239 }
240
241 static __inline PVOID
242 DesktopHeapAddressToUser(PVOID lpMem)
243 {
244 PW32HEAP_USER_MAPPING Mapping;
245 PPROCESSINFO W32Process;
246
247 W32Process = PsGetCurrentProcessWin32Process();
248 Mapping = W32Process->HeapMappings.Next;
249 while (Mapping != NULL)
250 {
251 if ((ULONG_PTR)lpMem >= (ULONG_PTR)Mapping->KernelMapping &&
252 (ULONG_PTR)lpMem < (ULONG_PTR)Mapping->KernelMapping + Mapping->Limit)
253 {
254 return (PVOID)(((ULONG_PTR)lpMem - (ULONG_PTR)Mapping->KernelMapping) +
255 (ULONG_PTR)Mapping->UserMapping);
256 }
257
258 Mapping = Mapping->Next;
259 }
260
261 return NULL;
262 }
263
264 /* EOF */