[CMAKE]
[reactos.git] / subsystems / win32 / win32k / ntuser / defwnd.c
1 /*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS kernel
4 * PURPOSE: Misc User funcs
5 * FILE: subsystem/win32/win32k/ntuser/defwnd.c
6 * PROGRAMER:
7 *
8 */
9
10 #include <win32k.h>
11
12 #define NDEBUG
13 #include <debug.h>
14
15 // Client Shutdown messages
16 #define MCS_SHUTDOWNTIMERS 1
17 #define MCS_QUERYENDSESSION 2
18 // Client Shutdown returns
19 #define MCSR_GOODFORSHUTDOWN 1
20 #define MCSR_SHUTDOWNFINISHED 2
21 #define MCSR_DONOTSHUTDOWN 3
22
23 /*
24 Based on CSRSS and described in pages 1115 - 1118 "Windows Internals, Fifth Edition".
25 Apparently CSRSS sends out messages to do this w/o going into win32k internals.
26 */
27 static
28 LRESULT FASTCALL
29 IntClientShutdown(
30 PWND pWindow,
31 WPARAM wParam,
32 LPARAM lParam
33 )
34 {
35 LPARAM lParams;
36 BOOL KillTimers;
37 INT i;
38 LRESULT lResult = MCSR_GOODFORSHUTDOWN;
39 HWND *List;
40
41 lParams = wParam & (ENDSESSION_LOGOFF|ENDSESSION_CRITICAL|ENDSESSION_CLOSEAPP);
42 KillTimers = wParam & MCS_SHUTDOWNTIMERS ? TRUE : FALSE;
43 /*
44 First, send end sessions to children.
45 */
46 List = IntWinListChildren(pWindow);
47
48 if (List)
49 {
50 for (i = 0; List[i]; i++)
51 {
52 PWND WndChild;
53
54 if (!(WndChild = UserGetWindowObject(List[i])))
55 continue;
56
57 if (wParam & MCS_QUERYENDSESSION)
58 {
59 if (!co_IntSendMessage(WndChild->head.h, WM_QUERYENDSESSION, 0, lParams))
60 {
61 lResult = MCSR_DONOTSHUTDOWN;
62 break;
63 }
64 }
65 else
66 {
67 co_IntSendMessage(WndChild->head.h, WM_ENDSESSION, KillTimers, lParams);
68 if (KillTimers)
69 {
70 DestroyTimersForWindow(WndChild->head.pti, WndChild);
71 }
72 lResult = MCSR_SHUTDOWNFINISHED;
73 }
74 }
75 ExFreePool(List);
76 }
77 if (List && (lResult == MCSR_DONOTSHUTDOWN)) return lResult;
78 /*
79 Send to the caller.
80 */
81 if (wParam & MCS_QUERYENDSESSION)
82 {
83 if (!co_IntSendMessage(pWindow->head.h, WM_QUERYENDSESSION, 0, lParams))
84 {
85 lResult = MCSR_DONOTSHUTDOWN;
86 }
87 }
88 else
89 {
90 co_IntSendMessage(pWindow->head.h, WM_ENDSESSION, KillTimers, lParams);
91 if (KillTimers)
92 {
93 DestroyTimersForWindow(pWindow->head.pti, pWindow);
94 }
95 lResult = MCSR_SHUTDOWNFINISHED;
96 }
97 return lResult;
98 }
99
100 LRESULT FASTCALL
101 DefWndHandleSysCommand(PWND pWnd, WPARAM wParam, LPARAM lParam)
102 {
103 LRESULT lResult = 0;
104 BOOL Hook = FALSE;
105
106 if (ISITHOOKED(WH_CBT) || (pWnd->head.rpdesk->pDeskInfo->fsHooks & HOOKID_TO_FLAG(WH_CBT)))
107 {
108 Hook = TRUE;
109 lResult = co_HOOK_CallHooks(WH_CBT, HCBT_SYSCOMMAND, wParam, lParam);
110
111 if (lResult) return lResult;
112 }
113
114 switch (wParam & 0xfff0)
115 {
116 case SC_SCREENSAVE:
117 DPRINT1("Screensaver Called!\n");
118 break;
119
120 default:
121 // We do not support anything else here so we should return normal even when sending a hook.
122 return 0;
123 }
124
125 return(Hook ? 1 : 0); // Don't call us again from user space.
126 }
127
128 /*
129 Win32k counterpart of User DefWindowProc
130 */
131 LRESULT FASTCALL
132 IntDefWindowProc(
133 PWND Wnd,
134 UINT Msg,
135 WPARAM wParam,
136 LPARAM lParam,
137 BOOL Ansi)
138 {
139 LRESULT lResult = 0;
140
141 if (Msg > WM_USER) return 0;
142
143 switch (Msg)
144 {
145 case WM_SYSCOMMAND:
146 {
147 DPRINT1("hwnd %p WM_SYSCOMMAND %lx %lx\n", Wnd->head.h, wParam, lParam );
148 lResult = DefWndHandleSysCommand(Wnd, wParam, lParam);
149 break;
150 }
151 case WM_SHOWWINDOW:
152 {
153 if ((Wnd->style & WS_VISIBLE) && wParam) break;
154 if (!(Wnd->style & WS_VISIBLE) && !wParam) break;
155 if (!Wnd->spwndOwner) break;
156 if (LOWORD(lParam))
157 {
158 if (wParam)
159 {
160 if (!(Wnd->state & WNDS_HIDDENPOPUP)) break;
161 Wnd->state &= ~WNDS_HIDDENPOPUP;
162 }
163 else
164 Wnd->state |= WNDS_HIDDENPOPUP;
165
166 co_WinPosShowWindow(Wnd, wParam ? SW_SHOWNOACTIVATE : SW_HIDE);
167 }
168 }
169 break;
170 case WM_CLIENTSHUTDOWN:
171 return IntClientShutdown(Wnd, wParam, lParam);
172
173 case WM_GETHOTKEY:
174 return DefWndGetHotKey(UserHMGetHandle(Wnd));
175 case WM_SETHOTKEY:
176 return DefWndSetHotKey(Wnd, wParam);
177
178 /* ReactOS only. */
179 case WM_CBT:
180 {
181 switch (wParam)
182 {
183 case HCBT_MOVESIZE:
184 {
185 RECTL rt;
186
187 if (lParam)
188 {
189 _SEH2_TRY
190 {
191 ProbeForRead((PVOID)lParam,
192 sizeof(RECT),
193 1);
194
195 RtlCopyMemory(&rt,
196 (PVOID)lParam,
197 sizeof(RECT));
198 }
199 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
200 {
201 lResult = 1;
202 }
203 _SEH2_END;
204 }
205 if (!lResult)
206 lResult = co_HOOK_CallHooks(WH_CBT, HCBT_MOVESIZE, (WPARAM)Wnd->head.h, lParam ? (LPARAM)&rt : 0);
207 }
208 break;
209 }
210 break;
211 }
212 break;
213 }
214 return lResult;
215 }
216
217
218 /* EOF */