QWindowKit  1.5.1.0
Cross-platform window customization framework
Loading...
Searching...
No Matches
win32windowcontext_p.h
1// Copyright (C) 2023-present Stdware Collections (https://www.github.com/stdware)
2// Copyright (C) 2021-2023 wangwenx190 (Yuhang Zhao)
3// SPDX-License-Identifier: Apache-2.0
4
5#ifndef WIN32WINDOWCONTEXT_P_H
6#define WIN32WINDOWCONTEXT_P_H
7
8//
9// W A R N I N G !!!
10// -----------------
11//
12// This file is not part of the QWindowKit API. It is used purely as an
13// implementation detail. This header file may change from version to
14// version without notice, or may even be removed.
15//
16
17#include <QWKCore/qwindowkit_windows.h>
18#include <QWKCore/private/abstractwindowcontext_p.h>
19
20namespace QWK {
21
22 class Win32WindowContext : public AbstractWindowContext {
23 Q_OBJECT
24 public:
25 Win32WindowContext();
26 ~Win32WindowContext() override;
27
28 enum WindowPart {
29 Outside,
30 ClientArea,
31 ChromeButton,
32 ResizeBorder,
33 FixedBorder,
34 TitleBar,
35 };
36 Q_ENUM(WindowPart)
37
38 QString key() const override;
39 void virtual_hook(int id, void *data) override;
40
41 QVariant windowAttribute(const QString &key) const override;
42
43 protected:
44 void winIdChanged(WId winId, WId oldWinId) override;
45 bool windowAttributeChanged(const QString &key, const QVariant &attribute,
46 const QVariant &oldAttribute) override;
47
48 public:
49 bool windowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam, LRESULT *result);
50
51 bool systemMenuHandler(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam,
52 LRESULT *result);
53
54 // In order to perfectly apply Windows 11 Snap Layout into the Qt window, we need to
55 // intercept and emulate most of the mouse events, so that the processing logic
56 // is quite complex. Simultaneously, in order to make the handling code of other
57 // Windows messages clearer, we have separated them into this function.
58 bool snapLayoutHandler(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam,
59 LRESULT *result);
60
61 bool customWindowHandler(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam,
62 LRESULT *result);
63
64 bool nonClientCalcSizeHandler(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam,
65 LRESULT *result);
66
67 protected:
68 // The last hit test result, helpful to handle WM_MOUSEMOVE and WM_NCMOUSELEAVE.
69 WindowPart lastHitTestResult = WindowPart::Outside;
70 int lastHitTestResultRaw = HTNOWHERE;
71
72 // Whether the last mouse leave message is blocked, mainly for handling the unexpected
73 // WM_MOUSELEAVE.
74 bool mouseLeaveBlocked = false;
75
76 // For emulating traditional icon button behavior
77 uint64_t iconButtonClickTime = 0;
78 int iconButtonClickLevel = 0;
79
80 // Attributes
81 bool noSystemMenu = false;
82
83 // Native HWNDs can be recreated while the logical QWindow stays alive. Keep the last
84 // stable native frame rect so we can prevent Qt's recreate path from applying a stale
85 // client-to-frame offset.
86 RECT frameRectBeforeWinIdChange{};
87 bool hasFrameRectBeforeWinIdChange = false;
88 RECT pendingFrameRectAfterWinIdChange{};
89 bool hasPendingFrameRectAfterWinIdChange = false;
90 bool restoringFrameRectAfterWinIdChange = false;
91 };
92
93}
94
95#endif // WIN32WINDOWCONTEXT_P_H
QWindowKit namespace.
Definition abstractwindowcontext.cpp:13