Synchronize with trunk's revision r57659.
[reactos.git] / 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 // Index offset for Desktop data. Should these be global?
43 #define DT_GWL_PROCESSID 0
44 #define DT_GWL_THREADID 4
45
46 #define DESKTOP_READ STANDARD_RIGHTS_READ | \
47 DESKTOP_ENUMERATE | \
48 DESKTOP_READOBJECTS
49
50 #define DESKTOP_WRITE STANDARD_RIGHTS_WRITE | \
51 DESKTOP_CREATEMENU | \
52 DESKTOP_CREATEWINDOW | \
53 DESKTOP_HOOKCONTROL | \
54 DESKTOP_JOURNALPLAYBACK | \
55 DESKTOP_JOURNALRECORD | \
56 DESKTOP_WRITEOBJECTS
57
58 #define DESKTOP_EXECUTE STANDARD_RIGHTS_EXECUTE | \
59 DESKTOP_SWITCHDESKTOP
60
61 #define DESKTOP_ALL_ACCESS STANDARD_RIGHTS_REQUIRED | \
62 DESKTOP_CREATEMENU | \
63 DESKTOP_CREATEWINDOW | \
64 DESKTOP_ENUMERATE | \
65 DESKTOP_HOOKCONTROL | \
66 DESKTOP_JOURNALPLAYBACK | \
67 DESKTOP_JOURNALRECORD | \
68 DESKTOP_READOBJECTS | \
69 DESKTOP_SWITCHDESKTOP | \
70 DESKTOP_WRITEOBJECTS
71
72 extern PDESKTOP InputDesktop;
73 extern PCLS DesktopWindowClass;
74 extern HDC ScreenDeviceContext;
75 extern PTHREADINFO gptiDesktopThread;
76
77 typedef struct _SHELL_HOOK_WINDOW
78 {
79 LIST_ENTRY ListEntry;
80 HWND hWnd;
81 } SHELL_HOOK_WINDOW, *PSHELL_HOOK_WINDOW;
82
83 INIT_FUNCTION
84 NTSTATUS
85 NTAPI
86 InitDesktopImpl(VOID);
87
88 NTSTATUS
89 APIENTRY
90 IntDesktopObjectParse(IN PVOID ParseObject,
91 IN PVOID ObjectType,
92 IN OUT PACCESS_STATE AccessState,
93 IN KPROCESSOR_MODE AccessMode,
94 IN ULONG Attributes,
95 IN OUT PUNICODE_STRING CompleteName,
96 IN OUT PUNICODE_STRING RemainingName,
97 IN OUT PVOID Context OPTIONAL,
98 IN PSECURITY_QUALITY_OF_SERVICE SecurityQos OPTIONAL,
99 OUT PVOID *Object);
100
101 VOID APIENTRY
102 IntDesktopObjectDelete(PWIN32_DELETEMETHOD_PARAMETERS Parameters);
103
104 NTSTATUS NTAPI
105 IntDesktopOkToClose(PWIN32_OKAYTOCLOSEMETHOD_PARAMETERS Parameters);
106
107 NTSTATUS NTAPI
108 IntDesktopObjectOpen(PWIN32_OPENMETHOD_PARAMETERS Parameters);
109
110 NTSTATUS NTAPI
111 IntDesktopObjectClose(PWIN32_CLOSEMETHOD_PARAMETERS Parameters);
112
113 HDC FASTCALL
114 IntGetScreenDC(VOID);
115
116 HWND FASTCALL
117 IntGetDesktopWindow (VOID);
118
119 PWND FASTCALL
120 UserGetDesktopWindow(VOID);
121
122 HWND FASTCALL
123 IntGetCurrentThreadDesktopWindow(VOID);
124
125 PUSER_MESSAGE_QUEUE FASTCALL
126 IntGetFocusMessageQueue(VOID);
127
128 VOID FASTCALL
129 IntSetFocusMessageQueue(PUSER_MESSAGE_QUEUE NewQueue);
130
131 PDESKTOP FASTCALL
132 IntGetActiveDesktop(VOID);
133
134 NTSTATUS FASTCALL
135 co_IntShowDesktop(PDESKTOP Desktop, ULONG Width, ULONG Height);
136
137 NTSTATUS FASTCALL
138 IntHideDesktop(PDESKTOP Desktop);
139
140 BOOL IntSetThreadDesktop(IN HDESK hDesktop,
141 IN BOOL FreeOnFailure);
142
143 NTSTATUS FASTCALL
144 IntValidateDesktopHandle(
145 HDESK Desktop,
146 KPROCESSOR_MODE AccessMode,
147 ACCESS_MASK DesiredAccess,
148 PDESKTOP *Object);
149
150 NTSTATUS FASTCALL
151 IntParseDesktopPath(PEPROCESS Process,
152 PUNICODE_STRING DesktopPath,
153 HWINSTA *hWinSta,
154 HDESK *hDesktop);
155
156 VOID APIENTRY UserRedrawDesktop(VOID);
157 BOOL IntRegisterShellHookWindow(HWND hWnd);
158 BOOL IntDeRegisterShellHookWindow(HWND hWnd);
159 VOID co_IntShellHookNotify(WPARAM Message, WPARAM wParam, LPARAM lParam);
160 HDC FASTCALL UserGetDesktopDC(ULONG,BOOL,BOOL);
161
162 #define IntIsActiveDesktop(Desktop) \
163 ((Desktop)->rpwinstaParent->ActiveDesktop == (Desktop))
164
165 #define GET_DESKTOP_NAME(d) \
166 OBJECT_HEADER_TO_NAME_INFO(OBJECT_TO_OBJECT_HEADER(d)) ? \
167 &(OBJECT_HEADER_TO_NAME_INFO(OBJECT_TO_OBJECT_HEADER(d))->Name) : \
168 NULL
169
170 HWND FASTCALL IntGetMessageWindow(VOID);
171 PWND FASTCALL UserGetMessageWindow(VOID);
172
173 static __inline PVOID
174 DesktopHeapAlloc(IN PDESKTOP Desktop,
175 IN SIZE_T Bytes)
176 {
177 return RtlAllocateHeap(Desktop->pheapDesktop,
178 HEAP_NO_SERIALIZE,
179 Bytes);
180 }
181
182 static __inline BOOL
183 DesktopHeapFree(IN PDESKTOP Desktop,
184 IN PVOID lpMem)
185 {
186 return RtlFreeHeap(Desktop->pheapDesktop,
187 HEAP_NO_SERIALIZE,
188 lpMem);
189 }
190
191 static __inline PVOID
192 DesktopHeapReAlloc(IN PDESKTOP Desktop,
193 IN PVOID lpMem,
194 IN SIZE_T Bytes)
195 {
196 #if 0
197 /* NOTE: ntoskrnl doesn't export RtlReAllocateHeap... */
198 return RtlReAllocateHeap(Desktop->pheapDesktop,
199 HEAP_NO_SERIALIZE,
200 lpMem,
201 Bytes);
202 #else
203 SIZE_T PrevSize;
204 PVOID pNew;
205
206 PrevSize = RtlSizeHeap(Desktop->pheapDesktop,
207 HEAP_NO_SERIALIZE,
208 lpMem);
209
210 if (PrevSize == Bytes)
211 return lpMem;
212
213 pNew = RtlAllocateHeap(Desktop->pheapDesktop,
214 HEAP_NO_SERIALIZE,
215 Bytes);
216 if (pNew != NULL)
217 {
218 if (PrevSize < Bytes)
219 Bytes = PrevSize;
220
221 RtlCopyMemory(pNew,
222 lpMem,
223 Bytes);
224
225 RtlFreeHeap(Desktop->pheapDesktop,
226 HEAP_NO_SERIALIZE,
227 lpMem);
228 }
229
230 return pNew;
231 #endif
232 }
233
234 static __inline ULONG_PTR
235 DesktopHeapGetUserDelta(VOID)
236 {
237 PW32HEAP_USER_MAPPING Mapping;
238 PTHREADINFO pti;
239 PPROCESSINFO W32Process;
240 PWIN32HEAP pheapDesktop;
241 ULONG_PTR Delta = 0;
242
243 pti = PsGetCurrentThreadWin32Thread();
244 if (!pti->rpdesk)
245 return 0;
246
247 pheapDesktop = pti->rpdesk->pheapDesktop;
248
249 W32Process = PsGetCurrentProcessWin32Process();
250 Mapping = W32Process->HeapMappings.Next;
251 while (Mapping != NULL)
252 {
253 if (Mapping->KernelMapping == (PVOID)pheapDesktop)
254 {
255 Delta = (ULONG_PTR)Mapping->KernelMapping - (ULONG_PTR)Mapping->UserMapping;
256 break;
257 }
258
259 Mapping = Mapping->Next;
260 }
261
262 return Delta;
263 }
264
265 static __inline PVOID
266 DesktopHeapAddressToUser(PVOID lpMem)
267 {
268 PW32HEAP_USER_MAPPING Mapping;
269 PPROCESSINFO W32Process;
270
271 W32Process = PsGetCurrentProcessWin32Process();
272 Mapping = W32Process->HeapMappings.Next;
273 while (Mapping != NULL)
274 {
275 if ((ULONG_PTR)lpMem >= (ULONG_PTR)Mapping->KernelMapping &&
276 (ULONG_PTR)lpMem < (ULONG_PTR)Mapping->KernelMapping + Mapping->Limit)
277 {
278 return (PVOID)(((ULONG_PTR)lpMem - (ULONG_PTR)Mapping->KernelMapping) +
279 (ULONG_PTR)Mapping->UserMapping);
280 }
281
282 Mapping = Mapping->Next;
283 }
284
285 return NULL;
286 }
287
288 PWND FASTCALL IntGetThreadDesktopWindow(PTHREADINFO);
289 PWND FASTCALL co_GetDesktopWindow(PWND);
290 BOOL FASTCALL IntPaintDesktop(HDC);
291 BOOL FASTCALL DesktopWindowProc(PWND, UINT, WPARAM, LPARAM, LRESULT *);
292 BOOL FASTCALL UserMessageWindowProc(PWND pwnd, UINT Msg, WPARAM wParam, LPARAM lParam, LRESULT *lResult);
293 VOID NTAPI DesktopThreadMain();
294 /* EOF */