573a98abf08fe0a353159812f7d4604bf0d19fca
[reactos.git] / reactos / subsystems / win32 / win32k / include / 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 PVOID 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 extern PDESKTOP InputDesktop;
43 extern HDESK InputDesktopHandle;
44 extern PCLS DesktopWindowClass;
45 extern HDC ScreenDeviceContext;
46 extern BOOL g_PaintDesktopVersion;
47
48 typedef struct _SHELL_HOOK_WINDOW
49 {
50 LIST_ENTRY ListEntry;
51 HWND hWnd;
52 } SHELL_HOOK_WINDOW, *PSHELL_HOOK_WINDOW;
53
54 INIT_FUNCTION
55 NTSTATUS
56 NTAPI
57 InitDesktopImpl(VOID);
58
59 NTSTATUS FASTCALL
60 CleanupDesktopImpl(VOID);
61
62 NTSTATUS
63 APIENTRY
64 IntDesktopObjectParse(IN PVOID ParseObject,
65 IN PVOID ObjectType,
66 IN OUT PACCESS_STATE AccessState,
67 IN KPROCESSOR_MODE AccessMode,
68 IN ULONG Attributes,
69 IN OUT PUNICODE_STRING CompleteName,
70 IN OUT PUNICODE_STRING RemainingName,
71 IN OUT PVOID Context OPTIONAL,
72 IN PSECURITY_QUALITY_OF_SERVICE SecurityQos OPTIONAL,
73 OUT PVOID *Object);
74
75 VOID APIENTRY
76 IntDesktopObjectDelete(PWIN32_DELETEMETHOD_PARAMETERS Parameters);
77
78 NTSTATUS NTAPI
79 IntDesktopOkToClose(PWIN32_OKAYTOCLOSEMETHOD_PARAMETERS Parameters);
80
81 HDC FASTCALL
82 IntGetScreenDC(VOID);
83
84 HWND FASTCALL
85 IntGetDesktopWindow (VOID);
86
87 PWND FASTCALL
88 UserGetDesktopWindow(VOID);
89
90 HWND FASTCALL
91 IntGetCurrentThreadDesktopWindow(VOID);
92
93 PUSER_MESSAGE_QUEUE FASTCALL
94 IntGetFocusMessageQueue(VOID);
95
96 VOID FASTCALL
97 IntSetFocusMessageQueue(PUSER_MESSAGE_QUEUE NewQueue);
98
99 PDESKTOP FASTCALL
100 IntGetActiveDesktop(VOID);
101
102 NTSTATUS FASTCALL
103 co_IntShowDesktop(PDESKTOP Desktop, ULONG Width, ULONG Height);
104
105 NTSTATUS FASTCALL
106 IntHideDesktop(PDESKTOP Desktop);
107
108 BOOL IntSetThreadDesktop(IN HDESK hDesktop,
109 IN BOOL FreeOnFailure);
110
111 NTSTATUS FASTCALL
112 IntValidateDesktopHandle(
113 HDESK Desktop,
114 KPROCESSOR_MODE AccessMode,
115 ACCESS_MASK DesiredAccess,
116 PDESKTOP *Object);
117
118 NTSTATUS FASTCALL
119 IntParseDesktopPath(PEPROCESS Process,
120 PUNICODE_STRING DesktopPath,
121 HWINSTA *hWinSta,
122 HDESK *hDesktop);
123
124 BOOL FASTCALL IntDesktopUpdatePerUserSettings(BOOL bEnable);
125 VOID APIENTRY UserRedrawDesktop(VOID);
126 BOOL IntRegisterShellHookWindow(HWND hWnd);
127 BOOL IntDeRegisterShellHookWindow(HWND hWnd);
128 VOID co_IntShellHookNotify(WPARAM Message, LPARAM lParam);
129 HDC FASTCALL UserGetDesktopDC(ULONG,BOOL,BOOL);
130
131 #define IntIsActiveDesktop(Desktop) \
132 ((Desktop)->rpwinstaParent->ActiveDesktop == (Desktop))
133
134 #define GET_DESKTOP_NAME(d) \
135 OBJECT_HEADER_TO_NAME_INFO(OBJECT_TO_OBJECT_HEADER(d)) ? \
136 &(OBJECT_HEADER_TO_NAME_INFO(OBJECT_TO_OBJECT_HEADER(d))->Name) : \
137 NULL
138
139 HWND FASTCALL IntGetMessageWindow(VOID);
140
141 static __inline PVOID
142 DesktopHeapAlloc(IN PDESKTOP Desktop,
143 IN SIZE_T Bytes)
144 {
145 return RtlAllocateHeap(Desktop->pheapDesktop,
146 HEAP_NO_SERIALIZE,
147 Bytes);
148 }
149
150 static __inline BOOL
151 DesktopHeapFree(IN PDESKTOP Desktop,
152 IN PVOID lpMem)
153 {
154 return RtlFreeHeap(Desktop->pheapDesktop,
155 HEAP_NO_SERIALIZE,
156 lpMem);
157 }
158
159 static __inline PVOID
160 DesktopHeapReAlloc(IN PDESKTOP Desktop,
161 IN PVOID lpMem,
162 IN SIZE_T Bytes)
163 {
164 #if 0
165 /* NOTE: ntoskrnl doesn't export RtlReAllocateHeap... */
166 return RtlReAllocateHeap(Desktop->pheapDesktop,
167 HEAP_NO_SERIALIZE,
168 lpMem,
169 Bytes);
170 #else
171 SIZE_T PrevSize;
172 PVOID pNew;
173
174 PrevSize = RtlSizeHeap(Desktop->pheapDesktop,
175 HEAP_NO_SERIALIZE,
176 lpMem);
177
178 if (PrevSize == Bytes)
179 return lpMem;
180
181 pNew = RtlAllocateHeap(Desktop->pheapDesktop,
182 HEAP_NO_SERIALIZE,
183 Bytes);
184 if (pNew != NULL)
185 {
186 if (PrevSize < Bytes)
187 Bytes = PrevSize;
188
189 RtlCopyMemory(pNew,
190 lpMem,
191 Bytes);
192
193 RtlFreeHeap(Desktop->pheapDesktop,
194 HEAP_NO_SERIALIZE,
195 lpMem);
196 }
197
198 return pNew;
199 #endif
200 }
201
202 static __inline ULONG_PTR
203 DesktopHeapGetUserDelta(VOID)
204 {
205 PW32HEAP_USER_MAPPING Mapping;
206 PTHREADINFO pti;
207 PPROCESSINFO W32Process;
208 PWIN32HEAP pheapDesktop;
209 ULONG_PTR Delta = 0;
210
211 pti = PsGetCurrentThreadWin32Thread();
212 if (!pti->rpdesk)
213 return 0;
214
215 pheapDesktop = pti->rpdesk->pheapDesktop;
216
217 W32Process = PsGetCurrentProcessWin32Process();
218 Mapping = W32Process->HeapMappings.Next;
219 while (Mapping != NULL)
220 {
221 if (Mapping->KernelMapping == (PVOID)pheapDesktop)
222 {
223 Delta = (ULONG_PTR)Mapping->KernelMapping - (ULONG_PTR)Mapping->UserMapping;
224 break;
225 }
226
227 Mapping = Mapping->Next;
228 }
229
230 return Delta;
231 }
232
233 static __inline PVOID
234 DesktopHeapAddressToUser(PVOID lpMem)
235 {
236 PW32HEAP_USER_MAPPING Mapping;
237 PPROCESSINFO W32Process;
238
239 W32Process = PsGetCurrentProcessWin32Process();
240 Mapping = W32Process->HeapMappings.Next;
241 while (Mapping != NULL)
242 {
243 if ((ULONG_PTR)lpMem >= (ULONG_PTR)Mapping->KernelMapping &&
244 (ULONG_PTR)lpMem < (ULONG_PTR)Mapping->KernelMapping + Mapping->Limit)
245 {
246 return (PVOID)(((ULONG_PTR)lpMem - (ULONG_PTR)Mapping->KernelMapping) +
247 (ULONG_PTR)Mapping->UserMapping);
248 }
249
250 Mapping = Mapping->Next;
251 }
252
253 return NULL;
254 }
255
256 /* EOF */