Warning: That file was not part of the compilation database. It may have many parsing errors.

1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the plugins of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or (at your option) the GNU General
28** Public license version 3 or any later version approved by the KDE Free
29** Qt Foundation. The licenses are as published by the Free Software
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31** included in the packaging of this file. Please review the following
32** information to ensure the GNU General Public License requirements will
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34** https://www.gnu.org/licenses/gpl-3.0.html.
35**
36** $QT_END_LICENSE$
37**
38****************************************************************************/
39
40#ifndef QWINDOWSWINDOW_H
41#define QWINDOWSWINDOW_H
42
43#include <QtCore/qt_windows.h>
44#include <QtCore/qpointer.h>
45#include "qwindowscursor.h"
46
47#include <qpa/qplatformwindow.h>
48#include <QtPlatformHeaders/qwindowswindowfunctions.h>
49
50#if QT_CONFIG(vulkan)
51#include "qwindowsvulkaninstance.h"
52#endif
53
54QT_BEGIN_NAMESPACE
55
56class QWindowsOleDropTarget;
57class QWindowsMenuBar;
58class QDebug;
59
60struct QWindowsGeometryHint
61{
62 static QMargins frameOnPrimaryScreen(DWORD style, DWORD exStyle);
63 static QMargins frameOnPrimaryScreen(HWND hwnd);
64 static QMargins frame(DWORD style, DWORD exStyle, qreal dpi);
65 static QMargins frame(HWND hwnd, DWORD style, DWORD exStyle);
66 static QMargins frame(const QWindow *w, const QRect &geometry,
67 DWORD style, DWORD exStyle);
68 static bool handleCalculateSize(const QMargins &customMargins, const MSG &msg, LRESULT *result);
69 static void applyToMinMaxInfo(const QWindow *w, const QMargins &margins,
70 MINMAXINFO *mmi);
71 static void frameSizeConstraints(const QWindow *w, const QMargins &margins,
72 QSize *minimumSize, QSize *maximumSize);
73 static inline QPoint mapToGlobal(HWND hwnd, const QPoint &);
74 static inline QPoint mapToGlobal(const QWindow *w, const QPoint &);
75 static inline QPoint mapFromGlobal(const HWND hwnd, const QPoint &);
76 static inline QPoint mapFromGlobal(const QWindow *w, const QPoint &);
77
78 static bool positionIncludesFrame(const QWindow *w);
79};
80
81struct QWindowCreationContext
82{
83 explicit QWindowCreationContext(const QWindow *w,
84 const QRect &geometryIn, const QRect &geometry,
85 const QMargins &customMargins,
86 DWORD style, DWORD exStyle);
87 void applyToMinMaxInfo(MINMAXINFO *mmi) const;
88
89 const QWindow *window;
90 QRect requestedGeometryIn; // QWindow scaled
91 QRect requestedGeometry; // after QPlatformWindow::initialGeometry()
92 QPoint obtainedPos;
93 QSize obtainedSize;
94 QMargins margins;
95 QMargins customMargins; // User-defined, additional frame for WM_NCCALCSIZE
96 int frameX = CW_USEDEFAULT; // Passed on to CreateWindowEx(), including frame.
97 int frameY = CW_USEDEFAULT;
98 int frameWidth = CW_USEDEFAULT;
99 int frameHeight = CW_USEDEFAULT;
100 int menuHeight = 0;
101};
102
103struct QWindowsWindowData
104{
105 Qt::WindowFlags flags;
106 QRect geometry;
107 QMargins fullFrameMargins; // Do not use directly for windows, see FrameDirty.
108 QMargins customMargins; // User-defined, additional frame for NCCALCSIZE
109 HWND hwnd = nullptr;
110 bool embedded = false;
111 bool hasFrame = false;
112
113 static QWindowsWindowData create(const QWindow *w,
114 const QWindowsWindowData &parameters,
115 const QString &title);
116};
117
118class QWindowsBaseWindow : public QPlatformWindow
119{
120 Q_DISABLE_COPY_MOVE(QWindowsBaseWindow)
121public:
122 explicit QWindowsBaseWindow(QWindow *window) : QPlatformWindow(window) {}
123
124 WId winId() const override { return WId(handle()); }
125 QRect geometry() const override { return geometry_sys(); }
126 QMargins frameMargins() const override { return fullFrameMargins(); }
127 QPoint mapToGlobal(const QPoint &pos) const override;
128 QPoint mapFromGlobal(const QPoint &pos) const override;
129 virtual QMargins fullFrameMargins() const { return frameMargins_sys(); }
130
131 using QPlatformWindow::screenForGeometry;
132
133 virtual HWND handle() const = 0;
134 virtual bool isTopLevel() const { return isTopLevel_sys(); }
135
136 unsigned style() const { return GetWindowLongPtr(handle(), GWL_STYLE); }
137 unsigned exStyle() const { return GetWindowLongPtr(handle(), GWL_EXSTYLE); }
138 static bool isRtlLayout(HWND hwnd);
139
140 static QWindowsBaseWindow *baseWindowOf(const QWindow *w);
141 static HWND handleOf(const QWindow *w);
142
143protected:
144 HWND parentHwnd() const { return GetAncestor(handle(), GA_PARENT); }
145 bool isTopLevel_sys() const;
146 QRect frameGeometry_sys() const;
147 QRect geometry_sys() const;
148 void setGeometry_sys(const QRect &rect) const;
149 QMargins frameMargins_sys() const;
150 void hide_sys();
151 void raise_sys();
152 void lower_sys();
153 void setWindowTitle_sys(const QString &title);
154};
155
156class QWindowsDesktopWindow : public QWindowsBaseWindow
157{
158public:
159 explicit QWindowsDesktopWindow(QWindow *window)
160 : QWindowsBaseWindow(window), m_hwnd(GetDesktopWindow()) {}
161
162 QMargins frameMargins() const override { return QMargins(); }
163 bool isTopLevel() const override { return true; }
164
165protected:
166 HWND handle() const override { return m_hwnd; }
167
168private:
169 const HWND m_hwnd;
170};
171
172class QWindowsForeignWindow : public QWindowsBaseWindow
173{
174public:
175 explicit QWindowsForeignWindow(QWindow *window, HWND hwnd);
176
177 void setParent(const QPlatformWindow *window) override;
178 void setGeometry(const QRect &rect) override { setGeometry_sys(rect); }
179 void setVisible(bool visible) override;
180 void raise() override { raise_sys(); }
181 void lower() override { lower_sys(); }
182 void setWindowTitle(const QString &title) override { setWindowTitle_sys(title); }
183 bool isForeignWindow() const override { return true; }
184
185protected:
186 HWND handle() const override { return m_hwnd; }
187
188private:
189 const HWND m_hwnd;
190 DWORD m_topLevelStyle;
191};
192
193class QWindowsWindow : public QWindowsBaseWindow
194{
195public:
196 enum Flags
197 {
198 AutoMouseCapture = 0x1, //! Automatic mouse capture on button press.
199 WithinSetParent = 0x2,
200 WithinSetGeometry = 0x8,
201 OpenGLSurface = 0x10,
202 OpenGL_ES2 = 0x20,
203 OpenGLDoubleBuffered = 0x40,
204 OpenGlPixelFormatInitialized = 0x80,
205 BlockedByModal = 0x100,
206 SizeGripOperation = 0x200,
207 FrameStrutEventsEnabled = 0x400,
208 SynchronousGeometryChangeEvent = 0x800,
209 WithinSetStyle = 0x1000,
210 WithinDestroy = 0x2000,
211 TouchRegistered = 0x4000,
212 AlertState = 0x8000,
213 Exposed = 0x10000,
214 WithinCreate = 0x20000,
215 WithinMaximize = 0x40000,
216 MaximizeToFullScreen = 0x80000,
217 Compositing = 0x100000,
218 HasBorderInFullScreen = 0x200000,
219 WithinDpiChanged = 0x400000,
220 VulkanSurface = 0x800000,
221 ResizeMoveActive = 0x1000000,
222 DisableNonClientScaling = 0x2000000
223 };
224
225 QWindowsWindow(QWindow *window, const QWindowsWindowData &data);
226 ~QWindowsWindow() override;
227
228 void initialize() override;
229
230 using QPlatformWindow::screenForGeometry;
231
232 QSurfaceFormat format() const override { return m_format; }
233 void setGeometry(const QRect &rect) override;
234 QRect geometry() const override { return m_data.geometry; }
235 QRect normalGeometry() const override;
236
237 void setVisible(bool visible) override;
238 bool isVisible() const;
239 bool isExposed() const override { return testFlag(Exposed); }
240 bool isActive() const override;
241 bool isAncestorOf(const QPlatformWindow *child) const override;
242 bool isEmbedded() const override;
243 QPoint mapToGlobal(const QPoint &pos) const override;
244 QPoint mapFromGlobal(const QPoint &pos) const override;
245
246 void setWindowFlags(Qt::WindowFlags flags) override;
247 void setWindowState(Qt::WindowStates state) override;
248
249 void setParent(const QPlatformWindow *window) override;
250
251 void setWindowTitle(const QString &title) override;
252 void raise() override { raise_sys(); }
253 void lower() override { lower_sys(); }
254
255 bool windowEvent(QEvent *event) override;
256
257 void propagateSizeHints() override;
258 static bool handleGeometryChangingMessage(MSG *message, const QWindow *qWindow, const QMargins &marginsDp);
259 bool handleGeometryChanging(MSG *message) const;
260 QMargins frameMargins() const override;
261 QMargins fullFrameMargins() const override;
262 void setFullFrameMargins(const QMargins &newMargins);
263 void updateFullFrameMargins();
264
265 void setOpacity(qreal level) override;
266 void setMask(const QRegion &region) override;
267 qreal opacity() const { return m_opacity; }
268 void requestActivateWindow() override;
269
270 bool setKeyboardGrabEnabled(bool grab) override;
271 bool setMouseGrabEnabled(bool grab) override;
272 inline bool hasMouseCapture() const { return GetCapture() == m_data.hwnd; }
273
274 bool startSystemResize(const QPoint &pos, Qt::Corner corner) override;
275 bool startSystemMove(const QPoint &pos) override;
276
277 void setFrameStrutEventsEnabled(bool enabled) override;
278 bool frameStrutEventsEnabled() const override { return testFlag(FrameStrutEventsEnabled); }
279
280 // QWindowsBaseWindow overrides
281 HWND handle() const override { return m_data.hwnd; }
282 bool isTopLevel() const override;
283
284 QWindowsMenuBar *menuBar() const;
285 void setMenuBar(QWindowsMenuBar *mb);
286
287 QMargins customMargins() const { return m_data.customMargins; }
288 void setCustomMargins(const QMargins &m);
289
290 void setStyle(unsigned s) const;
291 void setExStyle(unsigned s) const;
292
293 bool handleWmPaint(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
294
295 void handleMoved();
296 void handleResized(int wParam);
297 void handleHidden();
298 void handleCompositionSettingsChanged();
299
300 static void displayChanged();
301 static void settingsChanged();
302 static QScreen *forcedScreenForGLWindow(const QWindow *w);
303 static QWindowsWindow *windowsWindowOf(const QWindow *w);
304 static QWindow *topLevelOf(QWindow *w);
305 static inline void *userDataOf(HWND hwnd);
306 static inline void setUserDataOf(HWND hwnd, void *ud);
307
308 static bool setWindowLayered(HWND hwnd, Qt::WindowFlags flags, bool hasAlpha, qreal opacity);
309 bool isLayered() const;
310
311 HDC getDC();
312 void releaseDC();
313 void getSizeHints(MINMAXINFO *mmi) const;
314 bool handleNonClientHitTest(const QPoint &globalPos, LRESULT *result) const;
315
316#ifndef QT_NO_CURSOR
317 CursorHandlePtr cursor() const { return m_cursor; }
318#endif
319 void setCursor(const CursorHandlePtr &c);
320 void applyCursor();
321
322 inline bool testFlag(unsigned f) const { return (m_flags & f) != 0; }
323 inline void setFlag(unsigned f) const { m_flags |= f; }
324 inline void clearFlag(unsigned f) const { m_flags &= ~f; }
325
326 void setEnabled(bool enabled);
327 bool isEnabled() const;
328 void setWindowIcon(const QIcon &icon) override;
329
330 void *surface(void *nativeConfig, int *err);
331 void invalidateSurface() override;
332 void aboutToMakeCurrent();
333
334 void setAlertState(bool enabled) override;
335 bool isAlertState() const override { return testFlag(AlertState); }
336 void alertWindow(int durationMs = 0);
337 void stopAlertWindow();
338
339 enum ScreenChangeMode { FromGeometryChange, FromDpiChange };
340 void checkForScreenChanged(ScreenChangeMode mode = FromGeometryChange);
341
342 static void setTouchWindowTouchTypeStatic(QWindow *window, QWindowsWindowFunctions::TouchWindowTouchTypes touchTypes);
343 void registerTouchWindow(QWindowsWindowFunctions::TouchWindowTouchTypes touchTypes = QWindowsWindowFunctions::NormalTouch);
344 static void setHasBorderInFullScreenStatic(QWindow *window, bool border);
345 static void setHasBorderInFullScreenDefault(bool border);
346 void setHasBorderInFullScreen(bool border);
347 static QString formatWindowTitle(const QString &title);
348
349 static const char *embeddedNativeParentHandleProperty;
350 static const char *hasBorderInFullScreenProperty;
351
352private:
353 inline void show_sys() const;
354 inline QWindowsWindowData setWindowFlags_sys(Qt::WindowFlags wt, unsigned flags = 0) const;
355 inline bool isFullScreen_sys() const;
356 inline void setWindowState_sys(Qt::WindowStates newState);
357 inline void setParent_sys(const QPlatformWindow *parent);
358 inline void updateTransientParent() const;
359 void destroyWindow();
360 inline bool isDropSiteEnabled() const { return m_dropTarget != nullptr; }
361 void setDropSiteEnabled(bool enabled);
362 void updateDropSite(bool topLevel);
363 void handleGeometryChange();
364 void handleWindowStateChange(Qt::WindowStates state);
365 inline void destroyIcon();
366 void fireExpose(const QRegion &region, bool force=false);
367
368 mutable QWindowsWindowData m_data;
369 QPointer<QWindowsMenuBar> m_menuBar;
370 mutable unsigned m_flags = WithinCreate;
371 HDC m_hdc = nullptr;
372 Qt::WindowStates m_windowState = Qt::WindowNoState;
373 qreal m_opacity = 1;
374#ifndef QT_NO_CURSOR
375 CursorHandlePtr m_cursor;
376#endif
377 QWindowsOleDropTarget *m_dropTarget = nullptr;
378 unsigned m_savedStyle = 0;
379 QRect m_savedFrameGeometry;
380 const QSurfaceFormat m_format;
381 HICON m_iconSmall = nullptr;
382 HICON m_iconBig = nullptr;
383 void *m_surface = nullptr;
384
385 static bool m_screenForGLInitialized;
386
387#if QT_CONFIG(vulkan)
388 // note: intentionally not using void * in order to avoid breaking x86
389 VkSurfaceKHR m_vkSurface = VK_NULL_HANDLE;
390#endif
391 static bool m_borderInFullScreenDefault;
392};
393
394#ifndef QT_NO_DEBUG_STREAM
395QDebug operator<<(QDebug d, const RECT &r);
396QDebug operator<<(QDebug d, const POINT &);
397QDebug operator<<(QDebug d, const MINMAXINFO &i);
398QDebug operator<<(QDebug d, const NCCALCSIZE_PARAMS &p);
399QDebug operator<<(QDebug d, const WINDOWPLACEMENT &);
400QDebug operator<<(QDebug d, const WINDOWPOS &);
401QDebug operator<<(QDebug d, const GUID &guid);
402#endif // !QT_NO_DEBUG_STREAM
403
404static inline void clientToScreen(HWND hwnd, POINT *wP)
405{
406 if (QWindowsBaseWindow::isRtlLayout(hwnd)) {
407 RECT clientArea;
408 GetClientRect(hwnd, &clientArea);
409 wP->x = clientArea.right - wP->x;
410 }
411 ClientToScreen(hwnd, wP);
412}
413
414static inline void screenToClient(HWND hwnd, POINT *wP)
415{
416 ScreenToClient(hwnd, wP);
417 if (QWindowsBaseWindow::isRtlLayout(hwnd)) {
418 RECT clientArea;
419 GetClientRect(hwnd, &clientArea);
420 wP->x = clientArea.right - wP->x;
421 }
422}
423
424// ---------- QWindowsGeometryHint inline functions.
425QPoint QWindowsGeometryHint::mapToGlobal(HWND hwnd, const QPoint &qp)
426{
427 POINT p = { qp.x(), qp.y() };
428 clientToScreen(hwnd, &p);
429 return QPoint(p.x, p.y);
430}
431
432QPoint QWindowsGeometryHint::mapFromGlobal(const HWND hwnd, const QPoint &qp)
433{
434 POINT p = { qp.x(), qp.y() };
435 screenToClient(hwnd, &p);
436 return QPoint(p.x, p.y);
437}
438
439QPoint QWindowsGeometryHint::mapToGlobal(const QWindow *w, const QPoint &p)
440 { return QWindowsGeometryHint::mapToGlobal(QWindowsWindow::handleOf(w), p); }
441
442QPoint QWindowsGeometryHint::mapFromGlobal(const QWindow *w, const QPoint &p)
443 { return QWindowsGeometryHint::mapFromGlobal(QWindowsWindow::handleOf(w), p); }
444
445
446// ---------- QWindowsBaseWindow inline functions.
447
448inline QWindowsWindow *QWindowsWindow::windowsWindowOf(const QWindow *w)
449{
450 if (!w || !w->handle())
451 return nullptr;
452
453 const Qt::WindowType type = w->type();
454 if (type == Qt::Desktop || w->handle()->isForeignWindow())
455 return nullptr;
456
457 return static_cast<QWindowsWindow *>(w->handle());
458}
459
460void *QWindowsWindow::userDataOf(HWND hwnd)
461{
462 return reinterpret_cast<void *>(GetWindowLongPtr(hwnd, GWLP_USERDATA));
463}
464
465void QWindowsWindow::setUserDataOf(HWND hwnd, void *ud)
466{
467 SetWindowLongPtr(hwnd, GWLP_USERDATA, LONG_PTR(ud));
468}
469
470inline void QWindowsWindow::destroyIcon()
471{
472 if (m_iconBig) {
473 DestroyIcon(m_iconBig);
474 m_iconBig = nullptr;
475 }
476 if (m_iconSmall) {
477 DestroyIcon(m_iconSmall);
478 m_iconSmall = nullptr;
479 }
480}
481
482inline bool QWindowsWindow::isLayered() const
483{
484 return GetWindowLongPtr(m_data.hwnd, GWL_EXSTYLE) & WS_EX_LAYERED;
485}
486
487QT_END_NAMESPACE
488
489Q_DECLARE_METATYPE(QMargins)
490
491#endif // QWINDOWSWINDOW_H
492

Warning: That file was not part of the compilation database. It may have many parsing errors.