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