1 /****************************************************************************
2 **
3 ** Copyright (C) 2013 Samuel Gaist <samuel.gaist@edeltech.ch>
4 ** Copyright (C) 2016 The Qt Company Ltd.
5 ** Contact: https://www.qt.io/licensing/
6 **
7 ** This file is part of the plugins of the Qt Toolkit.
8 **
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** Commercial License Usage
11 ** Licensees holding valid commercial Qt licenses may use this file in
12 ** accordance with the commercial license agreement provided with the
13 ** Software or, alternatively, in accordance with the terms contained in
14 ** a written agreement between you and The Qt Company. For licensing terms
15 ** and conditions see https://www.qt.io/terms-conditions. For further
16 ** information use the contact form at https://www.qt.io/contact-us.
17 **
18 ** GNU Lesser General Public License Usage
19 ** Alternatively, this file may be used under the terms of the GNU Lesser
20 ** General Public License version 3 as published by the Free Software
21 ** Foundation and appearing in the file LICENSE.LGPL3 included in the
22 ** packaging of this file. Please review the following information to
23 ** ensure the GNU Lesser General Public License version 3 requirements
24 ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
25 **
26 ** GNU General Public License Usage
27 ** Alternatively, this file may be used under the terms of the GNU
28 ** General Public License version 2.0 or (at your option) the GNU General
29 ** Public license version 3 or any later version approved by the KDE Free
30 ** Qt Foundation. The licenses are as published by the Free Software
31 ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
32 ** included in the packaging of this file. Please review the following
33 ** information to ensure the GNU General Public License requirements will
34 ** be met: https://www.gnu.org/licenses/gpl-2.0.html and
35 ** https://www.gnu.org/licenses/gpl-3.0.html.
36 **
37 ** $QT_END_LICENSE$
38 **
39 ****************************************************************************/
40
41 #ifndef QTWINDOWSGLOBAL_H
42 #define QTWINDOWSGLOBAL_H
43
44 #include <QtCore/qt_windows.h>
45 #include <QtCore/qnamespace.h>
46
47 #ifndef WM_DWMCOMPOSITIONCHANGED // MinGW.
48 # define WM_DWMCOMPOSITIONCHANGED 0x31E
49 #endif
50
51 #ifndef WM_TOUCH
52 # define WM_TOUCH 0x0240
53 #endif
54
55 #ifndef WM_GESTURE
56 # define WM_GESTURE 0x0119
57 #endif
58
59 #ifndef WM_DPICHANGED
60 # define WM_DPICHANGED 0x02E0
61 #endif
62
63 // WM_POINTER support from Windows 8 onwards (WINVER >= 0x0602)
64 #ifndef WM_POINTERUPDATE
65 # define WM_NCPOINTERUPDATE 0x0241
66 # define WM_NCPOINTERDOWN 0x0242
67 # define WM_NCPOINTERUP 0x0243
68 # define WM_POINTERUPDATE 0x0245
69 # define WM_POINTERDOWN 0x0246
70 # define WM_POINTERUP 0x0247
71 # define WM_POINTERENTER 0x0249
72 # define WM_POINTERLEAVE 0x024A
73 # define WM_POINTERACTIVATE 0x024B
74 # define WM_POINTERCAPTURECHANGED 0x024C
75 # define WM_POINTERWHEEL 0x024E
76 # define WM_POINTERHWHEEL 0x024F
77 #endif // WM_POINTERUPDATE
78
79 QT_BEGIN_NAMESPACE
80
81 namespace QtWindows
82 {
83
84 enum
85 {
86 WindowEventFlag = 0x10000,
87 MouseEventFlag = 0x20000,
88 NonClientEventFlag = 0x40000,
89 InputMethodEventFlag = 0x80000,
90 KeyEventFlag = 0x100000,
91 KeyDownEventFlag = 0x200000,
92 TouchEventFlag = 0x400000,
93 ClipboardEventFlag = 0x800000,
94 ApplicationEventFlag = 0x1000000,
95 ThemingEventFlag = 0x2000000,
96 GenericEventFlag = 0x4000000, // Misc
97 PointerEventFlag = 0x8000000,
98 };
99
100 enum WindowsEventType // Simplify event types
101 {
102 ExposeEvent = WindowEventFlag + 1,
103 ActivateWindowEvent = WindowEventFlag + 2,
104 DeactivateWindowEvent = WindowEventFlag + 3,
105 MouseActivateWindowEvent = WindowEventFlag + 4,
106 LeaveEvent = WindowEventFlag + 5,
107 CloseEvent = WindowEventFlag + 6,
108 ShowEvent = WindowEventFlag + 7,
109 ShowEventOnParentRestoring = WindowEventFlag + 20,
110 HideEvent = WindowEventFlag + 8,
111 DestroyEvent = WindowEventFlag + 9,
112 GeometryChangingEvent = WindowEventFlag + 10,
113 MoveEvent = WindowEventFlag + 11,
114 ResizeEvent = WindowEventFlag + 12,
115 QuerySizeHints = WindowEventFlag + 15,
116 CalculateSize = WindowEventFlag + 16,
117 FocusInEvent = WindowEventFlag + 17,
118 FocusOutEvent = WindowEventFlag + 18,
119 WhatsThisEvent = WindowEventFlag + 19,
120 DpiChangedEvent = WindowEventFlag + 21,
121 EnterSizeMoveEvent = WindowEventFlag + 22,
122 ExitSizeMoveEvent = WindowEventFlag + 23,
123 PointerActivateWindowEvent = WindowEventFlag + 24,
124 MouseEvent = MouseEventFlag + 1,
125 MouseWheelEvent = MouseEventFlag + 2,
126 CursorEvent = MouseEventFlag + 3,
127 TouchEvent = TouchEventFlag + 1,
128 PointerEvent = PointerEventFlag + 1,
129 NonClientMouseEvent = NonClientEventFlag + MouseEventFlag + 1,
130 NonClientHitTest = NonClientEventFlag + 2,
131 NonClientCreate = NonClientEventFlag + 3,
132 NonClientPointerEvent = NonClientEventFlag + PointerEventFlag + 4,
133 KeyEvent = KeyEventFlag + 1,
134 KeyDownEvent = KeyEventFlag + KeyDownEventFlag + 1,
135 KeyboardLayoutChangeEvent = KeyEventFlag + 2,
136 InputMethodKeyEvent = InputMethodEventFlag + KeyEventFlag + 1,
137 InputMethodKeyDownEvent = InputMethodEventFlag + KeyEventFlag + KeyDownEventFlag + 1,
138 ClipboardEvent = ClipboardEventFlag + 1,
139 ActivateApplicationEvent = ApplicationEventFlag + 1,
140 DeactivateApplicationEvent = ApplicationEventFlag + 2,
141 AccessibleObjectFromWindowRequest = ApplicationEventFlag + 3,
142 QueryEndSessionApplicationEvent = ApplicationEventFlag + 4,
143 EndSessionApplicationEvent = ApplicationEventFlag + 5,
144 AppCommandEvent = ApplicationEventFlag + 6,
145 DeviceChangeEvent = ApplicationEventFlag + 7,
146 MenuAboutToShowEvent = ApplicationEventFlag + 8,
147 AcceleratorCommandEvent = ApplicationEventFlag + 9,
148 MenuCommandEvent = ApplicationEventFlag + 10,
149 InputMethodStartCompositionEvent = InputMethodEventFlag + 1,
150 InputMethodCompositionEvent = InputMethodEventFlag + 2,
151 InputMethodEndCompositionEvent = InputMethodEventFlag + 3,
152 InputMethodOpenCandidateWindowEvent = InputMethodEventFlag + 4,
153 InputMethodCloseCandidateWindowEvent = InputMethodEventFlag + 5,
154 InputMethodRequest = InputMethodEventFlag + 6,
155 ThemeChanged = ThemingEventFlag + 1,
156 CompositionSettingsChanged = ThemingEventFlag + 2,
157 DisplayChangedEvent = 437,
158 SettingChangedEvent = DisplayChangedEvent + 1,
159 ScrollEvent = GenericEventFlag + 1,
160 ContextMenu = 123,
161 GestureEvent = 124,
162 UnknownEvent = 542
163 };
164
165 // Matches Process_DPI_Awareness (Windows 8.1 onwards), used for SetProcessDpiAwareness()
166 enum ProcessDpiAwareness
167 {
168 ProcessDpiUnaware,
169 ProcessSystemDpiAware,
170 ProcessPerMonitorDpiAware
171 };
172
173 } // namespace QtWindows
174
windowsEventType(UINT message,WPARAM wParamIn,LPARAM lParamIn)175 inline QtWindows::WindowsEventType windowsEventType(UINT message, WPARAM wParamIn, LPARAM lParamIn)
176 {
177 switch (message) {
178 case WM_PAINT:
179 case WM_ERASEBKGND:
180 return QtWindows::ExposeEvent;
181 case WM_CLOSE:
182 return QtWindows::CloseEvent;
183 case WM_DESTROY:
184 return QtWindows::DestroyEvent;
185 case WM_ACTIVATEAPP:
186 return (int)wParamIn ?
187 QtWindows::ActivateApplicationEvent : QtWindows::DeactivateApplicationEvent;
188 case WM_MOUSEACTIVATE:
189 return QtWindows::MouseActivateWindowEvent;
190 case WM_POINTERACTIVATE:
191 return QtWindows::PointerActivateWindowEvent;
192 case WM_ACTIVATE:
193 return LOWORD(wParamIn) == WA_INACTIVE ?
194 QtWindows::DeactivateWindowEvent : QtWindows::ActivateWindowEvent;
195 case WM_SETCURSOR:
196 return QtWindows::CursorEvent;
197 case WM_MOUSELEAVE:
198 return QtWindows::MouseEvent;
199 case WM_HSCROLL:
200 return QtWindows::ScrollEvent;
201 case WM_MOUSEWHEEL:
202 case WM_MOUSEHWHEEL:
203 return QtWindows::MouseWheelEvent;
204 case WM_WINDOWPOSCHANGING:
205 return QtWindows::GeometryChangingEvent;
206 case WM_MOVE:
207 return QtWindows::MoveEvent;
208 case WM_SHOWWINDOW:
209 if (wParamIn)
210 return lParamIn == SW_PARENTOPENING ? QtWindows::ShowEventOnParentRestoring : QtWindows::ShowEvent;
211 return QtWindows::HideEvent;
212 case WM_SIZE:
213 return QtWindows::ResizeEvent;
214 case WM_NCCREATE:
215 return QtWindows::NonClientCreate;
216 case WM_NCCALCSIZE:
217 return QtWindows::CalculateSize;
218 case WM_NCHITTEST:
219 return QtWindows::NonClientHitTest;
220 case WM_GETMINMAXINFO:
221 return QtWindows::QuerySizeHints;
222 case WM_KEYDOWN: // keyboard event
223 case WM_SYSKEYDOWN:
224 return QtWindows::KeyDownEvent;
225 case WM_KEYUP:
226 case WM_SYSKEYUP:
227 case WM_CHAR:
228 return QtWindows::KeyEvent;
229 case WM_IME_CHAR:
230 return QtWindows::InputMethodKeyEvent;
231 case WM_IME_KEYDOWN:
232 return QtWindows::InputMethodKeyDownEvent;
233 #ifdef WM_INPUTLANGCHANGE
234 case WM_INPUTLANGCHANGE:
235 return QtWindows::KeyboardLayoutChangeEvent;
236 #endif // WM_INPUTLANGCHANGE
237 case WM_TOUCH:
238 return QtWindows::TouchEvent;
239 case WM_CHANGECBCHAIN:
240 case WM_DRAWCLIPBOARD:
241 case WM_RENDERFORMAT:
242 case WM_RENDERALLFORMATS:
243 case WM_DESTROYCLIPBOARD:
244 return QtWindows::ClipboardEvent;
245 case WM_IME_STARTCOMPOSITION:
246 return QtWindows::InputMethodStartCompositionEvent;
247 case WM_IME_ENDCOMPOSITION:
248 return QtWindows::InputMethodEndCompositionEvent;
249 case WM_IME_COMPOSITION:
250 return QtWindows::InputMethodCompositionEvent;
251 case WM_IME_REQUEST:
252 return QtWindows::InputMethodRequest;
253 case WM_IME_NOTIFY:
254 switch (int(wParamIn)) {
255 case IMN_OPENCANDIDATE:
256 return QtWindows::InputMethodOpenCandidateWindowEvent;
257 case IMN_CLOSECANDIDATE:
258 return QtWindows::InputMethodCloseCandidateWindowEvent;
259 default:
260 break;
261 }
262 break;
263 case WM_GETOBJECT:
264 return QtWindows::AccessibleObjectFromWindowRequest;
265 case WM_SETFOCUS:
266 return QtWindows::FocusInEvent;
267 case WM_KILLFOCUS:
268 return QtWindows::FocusOutEvent;
269 // Among other things, WM_SETTINGCHANGE happens when the taskbar is moved
270 // and therefore the "working area" changes.
271 // http://msdn.microsoft.com/en-us/library/ms695534(v=vs.85).aspx
272 case WM_SETTINGCHANGE:
273 return QtWindows::SettingChangedEvent;
274 case WM_DISPLAYCHANGE:
275 return QtWindows::DisplayChangedEvent;
276 case WM_THEMECHANGED:
277 #ifdef WM_SYSCOLORCHANGE // Windows 7: Handle color change as theme change (QTBUG-34170).
278 case WM_SYSCOLORCHANGE:
279 #endif
280 return QtWindows::ThemeChanged;
281 case WM_DWMCOMPOSITIONCHANGED:
282 return QtWindows::CompositionSettingsChanged;
283 #ifndef QT_NO_CONTEXTMENU
284 case WM_CONTEXTMENU:
285 return QtWindows::ContextMenu;
286 #endif
287 case WM_SYSCOMMAND:
288 if ((wParamIn & 0xfff0) == SC_CONTEXTHELP)
289 return QtWindows::WhatsThisEvent;
290 break;
291 case WM_QUERYENDSESSION:
292 return QtWindows::QueryEndSessionApplicationEvent;
293 case WM_ENDSESSION:
294 return QtWindows::EndSessionApplicationEvent;
295 #if defined(WM_APPCOMMAND)
296 case WM_APPCOMMAND:
297 return QtWindows::AppCommandEvent;
298 #endif
299 case WM_GESTURE:
300 return QtWindows::GestureEvent;
301 case WM_DEVICECHANGE:
302 return QtWindows::DeviceChangeEvent;
303 case WM_INITMENU:
304 case WM_INITMENUPOPUP:
305 return QtWindows::MenuAboutToShowEvent;
306 case WM_COMMAND:
307 return HIWORD(wParamIn) ? QtWindows::AcceleratorCommandEvent : QtWindows::MenuCommandEvent;
308 case WM_DPICHANGED:
309 return QtWindows::DpiChangedEvent;
310 case WM_ENTERSIZEMOVE:
311 return QtWindows::EnterSizeMoveEvent;
312 case WM_EXITSIZEMOVE:
313 return QtWindows::ExitSizeMoveEvent;
314 default:
315 break;
316 }
317 if (message >= WM_NCMOUSEMOVE && message <= WM_NCMBUTTONDBLCLK)
318 return QtWindows::NonClientMouseEvent; //
319 if ((message >= WM_MOUSEFIRST && message <= WM_MOUSELAST)
320 || (message >= WM_XBUTTONDOWN && message <= WM_XBUTTONDBLCLK))
321 return QtWindows::MouseEvent;
322 if (message >= WM_NCPOINTERUPDATE && message <= WM_NCPOINTERUP)
323 return QtWindows::NonClientPointerEvent;
324 if (message >= WM_POINTERUPDATE && message <= WM_POINTERHWHEEL)
325 return QtWindows::PointerEvent;
326 return QtWindows::UnknownEvent;
327 }
328
329 QT_END_NAMESPACE
330
331 #endif // QTWINDOWSGLOBAL_H
332