QtCanpool 3.3.0
载入中...
搜索中...
未找到
windowcontext_p.h
浏览该文件的文档.
1
5#ifndef WINDOWCONTEXT_P_H
6#define WINDOWCONTEXT_P_H
7
8//
9// W A R N I N G !!!
10// -----------------
11//
12// This file is not part of the QxWindow 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 "qxwindow_global.h"
18#include "windowevent_p.h"
20#include "windowagentbase.h"
21#include <QtCore/QPointer>
22#include <QtCore/QSet>
23#include <QtGui/QRegion>
24#include <QtGui/QWindow>
25#include <array>
26#include <memory>
27
29
31{
32 Q_OBJECT
33public:
35 ~WindowContext() override;
36public:
37 void setup(QObject *host, WindowItemDelegate *delegate);
38
39 inline QObject *host() const;
40 inline QWindow *window() const;
41 inline WindowItemDelegate *delegate() const;
42
43 inline bool isHitTestVisible(const QObject *obj) const;
44 bool setHitTestVisible(const QObject *obj, bool visible);
45
46 inline QObject *systemButton(WindowAgentBase::SystemButton button) const;
47 bool setSystemButton(WindowAgentBase::SystemButton button, QObject *obj);
48 void removeSystemButton(WindowAgentBase::SystemButton button);
49
50 inline QObject *titleBar() const;
51 bool setTitleBar(QObject *obj);
52
53#ifdef Q_OS_MAC
54 inline ScreenRectCallback systemButtonAreaCallback() const;
55 void setSystemButtonAreaCallback(const ScreenRectCallback &callback);
56#endif
57
58 bool isInSystemButtons(const QPoint &pos, WindowAgentBase::SystemButton *button) const;
59 bool isInTitleBarDraggableArea(const QPoint &pos) const;
60
61 bool isCaptionClassName(const char *name) const;
62 void addCaptionClassName(const QString &name);
63
64 virtual QString key() const;
65
67 CentralizeHook = 1,
71 DrawWindows10BorderHook, // Only works on Windows 10, emulated workaround
72 DrawWindows10BorderHook2, // Only works on Windows 10, native workaround
73 SystemButtonAreaChangedHook, // Only works on Mac
74 };
75 virtual void virtual_hook(int id, void *data);
76
77 void showSystemMenu(const QPoint &pos);
78 void notifyWinIdChange();
79
80 virtual QVariant windowAttribute(const QString &key) const;
81 virtual bool setWindowAttribute(const QString &key, const QVariant &attribute);
82protected:
83 virtual void winIdChanged() = 0;
84 virtual bool windowAttributeChanged(const QString &key, const QVariant &attribute, const QVariant &oldAttribute);
85protected:
86 QObject *m_host{};
87 std::unique_ptr<WindowItemDelegate> m_delegate;
88 QWindow *m_windowHandle{};
89
90 QSet<const QObject *> m_hitTestVisibleItems;
91 QList<QString> m_captionClassNameList;
92#ifdef Q_OS_MAC
94#endif
95
96 QObject *m_titleBar{};
97 std::array<QObject *, WindowAgentBase::Close + 1> m_systemButtons{};
98
99 QVariantHash m_windowAttributes;
100
101 std::unique_ptr<QObject> m_windowEventFilter;
102 std::unique_ptr<QObject> m_winIdChangeEventFilter;
103};
104
105inline QObject *WindowContext::host() const
106{
107 return m_host;
108}
109
110inline QWindow *WindowContext::window() const
111{
112 return m_windowHandle;
113}
114
115inline WindowItemDelegate *WindowContext::delegate() const
116{
117 return m_delegate.get();
118}
119
120inline bool WindowContext::isHitTestVisible(const QObject *obj) const
121{
122 return m_hitTestVisibleItems.contains(obj);
123}
124
125inline QObject *WindowContext::systemButton(WindowAgentBase::SystemButton button) const
126{
127 return m_systemButtons[button];
128}
129
130inline QObject *WindowContext::titleBar() const
131{
132 return m_titleBar;
133}
134
135#ifdef Q_OS_MAC
136inline ScreenRectCallback WindowContext::systemButtonAreaCallback() const
137{
138 return m_systemButtonAreaCallback;
139}
140#endif
141
143
144// _MSC_VER: 1929 - use 5.15.2/msvc2019_64/bin/qmake to build qxwindow failure on vs2022
145#if ((_MSC_VER == 1929) || defined(Q_OS_WINDOWS)) && defined(QX_WINDOW_NATIVE)
146
147#include "windowkit_win.h"
148
150
151class WindowContextWin : public WindowContext
152{
153 Q_OBJECT
154public:
155 WindowContextWin();
156 ~WindowContextWin() override;
157
158 enum WindowPart {
159 Outside,
160 ClientArea,
161 ChromeButton,
162 ResizeBorder,
163 FixedBorder,
164 TitleBar,
165 };
166
167 QString key() const override;
168 void virtual_hook(int id, void *data) override;
169
170 QVariant windowAttribute(const QString &key) const override;
171protected:
172 void winIdChanged() override;
173 bool windowAttributeChanged(const QString &key, const QVariant &attribute, const QVariant &oldAttribute) override;
174public:
175 bool windowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam, LRESULT *result);
176
177 bool systemMenuHandler(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam, LRESULT *result);
178
179 // In order to perfectly apply Windows 11 Snap Layout into the Qt window, we need to
180 // intercept and emulate most of the mouse events, so that the processing logic
181 // is quite complex. Simultaneously, in order to make the handling code of other
182 // Windows messages clearer, we have separated them into this function.
183 bool snapLayoutHandler(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam, LRESULT *result);
184
185 bool customWindowHandler(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam, LRESULT *result);
186
187 bool nonClientCalcSizeHandler(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam, LRESULT *result);
188protected:
189 WId windowId = 0;
190
191 // The last hit test result, helpful to handle WM_MOUSEMOVE and WM_NCMOUSELEAVE.
192 WindowPart lastHitTestResult = WindowPart::Outside;
193
194 // Whether the last mouse leave message is blocked, mainly for handling the unexpected
195 // WM_MOUSELEAVE.
196 bool mouseLeaveBlocked = false;
197
198 bool initialCentered = false;
199};
200
202
203#elif defined(Q_OS_MAC) && defined(QX_WINDOW_NATIVE)
204
206
207class WindowContextCocoa : public WindowContext
208{
209 Q_OBJECT
210public:
211 WindowContextCocoa();
212 ~WindowContextCocoa() override;
213
214 QString key() const override;
215 void virtual_hook(int id, void *data) override;
216
217 QVariant windowAttribute(const QString &key) const override;
218protected:
219 void winIdChanged() override;
220 bool windowAttributeChanged(const QString &key, const QVariant &attribute, const QVariant &oldAttribute) override;
221protected:
222 WId windowId = 0;
223
224 std::unique_ptr<WindowSharedEventFilter> cocoaWindowEventFilter;
225};
226
228
229#else
231
233{
234 Q_OBJECT
235public:
238
239 QString key() const override;
240 void virtual_hook(int id, void *data) override;
241protected:
242 void winIdChanged() override;
243protected:
244 std::unique_ptr<WindowSharedEventFilter> qtWindowEventFilter;
245};
246
248
249#endif
250
251#endif // WINDOWCONTEXT_P_H
std::unique_ptr< WindowSharedEventFilter > qtWindowEventFilter
virtual QVariant windowAttribute(const QString &key) const
std::unique_ptr< QObject > m_winIdChangeEventFilter
std::unique_ptr< QObject > m_windowEventFilter
virtual bool windowAttributeChanged(const QString &key, const QVariant &attribute, const QVariant &oldAttribute)
QSet< const QObject * > m_hitTestVisibleItems
ScreenRectCallback m_systemButtonAreaCallback
QVariantHash m_windowAttributes
virtual void virtual_hook(int id, void *data)
virtual QString key() const
virtual void winIdChanged()=0
std::unique_ptr< WindowItemDelegate > m_delegate
QList< QString > m_captionClassNameList
std::function< QRect(const QSize &)> ScreenRectCallback
const char * name
Definition qxtheme.cpp:25
QColor window
QColor button
#define QX_WINDOW_END_NAMESPACE
#define QX_WINDOW_BEGIN_NAMESPACE