QWindowKit  1.5.1.0
Cross-platform window customization framework
Loading...
Searching...
No Matches
abstractwindowcontext_p.h
1// Copyright (C) 2021-2023 wangwenx190 (Yuhang Zhao)
2// Copyright (C) 2023-present Stdware Collections (https://www.github.com/stdware)
3// SPDX-License-Identifier: Apache-2.0
4
5#ifndef ABSTRACTWINDOWCONTEXT_P_H
6#define ABSTRACTWINDOWCONTEXT_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 <array>
18#include <list>
19#include <memory>
20#include <utility>
21
22#include <QtCore/QSet>
23#include <QtCore/QPointer>
24#include <QtGui/QRegion>
25#include <QtGui/QWindow>
26
27#include <QWKCore/windowagentbase.h>
28#include <QWKCore/private/nativeeventfilter_p.h>
29#include <QWKCore/private/sharedeventfilter_p.h>
30#include <QWKCore/private/windowitemdelegate_p.h>
31#include <QWKCore/private/winidchangeeventfilter_p.h>
32
33namespace QWK {
34
35 class QWK_CORE_EXPORT AbstractWindowContext : public QObject,
36 public NativeEventDispatcher,
37 public SharedEventDispatcher {
38 Q_OBJECT
39 public:
40 AbstractWindowContext();
41 ~AbstractWindowContext() override;
42
43 public:
44 void setup(QObject *host, WindowItemDelegate *delegate);
45
46 inline QObject *host() const;
47 inline QWindow *window() const;
48 inline WId windowId() const;
49 inline WindowItemDelegate *delegate() const;
50
51 inline bool isHitTestVisible(const QObject *obj) const;
52 bool setHitTestVisible(QObject *obj, bool visible);
53
54 inline QObject *systemButton(WindowAgentBase::SystemButton button) const;
55 bool setSystemButton(WindowAgentBase::SystemButton button, QObject *obj);
56
57 inline QObject *titleBar() const;
58 bool setTitleBar(QObject *obj);
59
60#ifdef Q_OS_MAC
61 inline ScreenRectCallback systemButtonAreaCallback() const;
62 void setSystemButtonAreaCallback(const ScreenRectCallback &callback);
63#endif
64
65 bool isInSystemButtons(const QPoint &pos, WindowAgentBase::SystemButton *button) const;
66 bool isInTitleBarDraggableArea(const QPoint &pos) const;
67
68 inline bool isHostWidthFixed() const;
69 inline bool isHostHeightFixed() const;
70 inline bool isHostSizeFixed() const;
71
72 virtual QString key() const;
73
74 enum WindowContextHook {
75 CentralizeHook = 1,
76 RaiseWindowHook,
77 ShowSystemMenuHook,
78 DefaultColorsHook,
79 DrawWindows10BorderHook_Emulated, // Only works on Windows 10, emulated workaround
80 DrawWindows10BorderHook_Native, // Only works on Windows 10, native workaround
81 SystemButtonAreaChangedHook, // Only works on Mac
82 };
83 virtual void virtual_hook(int id, void *data);
84
85 void showSystemMenu(const QPoint &pos);
86 void notifyWinIdChange();
87
88 virtual QVariant windowAttribute(const QString &key) const;
89 virtual bool setWindowAttribute(const QString &key, const QVariant &attribute);
90
91 protected:
92 bool eventFilter(QObject *obj, QEvent *event) override;
93
94 protected:
95 virtual void winIdChanged(WId winId, WId oldWinId) = 0;
96 virtual bool windowAttributeChanged(const QString &key, const QVariant &attribute,
97 const QVariant &oldAttribute);
98
99 protected:
100 QObject *m_host{};
101 std::unique_ptr<WindowItemDelegate> m_delegate;
102 QPointer<QWindow> m_windowHandle;
103 WId m_windowId{};
104
105 QVector<QPointer<QObject>> m_hitTestVisibleItems;
106#ifdef Q_OS_MAC
107 ScreenRectCallback m_systemButtonAreaCallback;
108#endif
109
110 QPointer<QObject> m_titleBar{};
111 std::array<QPointer<QObject>, WindowAgentBase::Close + 1> m_systemButtons{};
112
113 std::list<std::pair<QString, QVariant>> m_windowAttributesOrder;
114 QHash<QString, decltype(m_windowAttributesOrder)::iterator> m_windowAttributes;
115
116 std::unique_ptr<WinIdChangeEventFilter> m_winIdChangeEventFilter;
117
118 void removeSystemButtonsAndHitTestItems();
119 };
120
121 inline QObject *AbstractWindowContext::host() const {
122 return m_host;
123 }
124
125 inline QWindow *AbstractWindowContext::window() const {
126 return m_windowHandle;
127 }
128
129 inline WId AbstractWindowContext::windowId() const {
130 return m_windowId;
131 }
132
133 inline WindowItemDelegate *AbstractWindowContext::delegate() const {
134 return m_delegate.get();
135 }
136
137 inline bool AbstractWindowContext::isHitTestVisible(const QObject *obj) const {
138 return m_hitTestVisibleItems.contains(const_cast<QObject *>(obj));
139 }
140
141 inline QObject *
142 AbstractWindowContext::systemButton(WindowAgentBase::SystemButton button) const {
143 return m_systemButtons[button];
144 }
145
146 inline QObject *AbstractWindowContext::titleBar() const {
147 return m_titleBar;
148 }
149
150#ifdef Q_OS_MAC
151 inline ScreenRectCallback AbstractWindowContext::systemButtonAreaCallback() const {
152 return m_systemButtonAreaCallback;
153 }
154#endif
155
156 inline bool AbstractWindowContext::isHostWidthFixed() const {
157 return m_windowHandle
158 ? ((m_windowHandle->flags() & Qt::MSWindowsFixedSizeDialogHint) ||
159 m_windowHandle->minimumWidth() == m_windowHandle->maximumWidth())
160 : false;
161 }
162
163 inline bool AbstractWindowContext::isHostHeightFixed() const {
164 return m_windowHandle
165 ? ((m_windowHandle->flags() & Qt::MSWindowsFixedSizeDialogHint) ||
166 m_windowHandle->minimumHeight() == m_windowHandle->maximumHeight())
167 : false;
168 }
169
170 inline bool AbstractWindowContext::isHostSizeFixed() const {
171 return m_windowHandle ? ((m_windowHandle->flags() & Qt::MSWindowsFixedSizeDialogHint) ||
172 m_windowHandle->minimumSize() == m_windowHandle->maximumSize())
173 : false;
174 }
175
176}
177
178#endif // ABSTRACTWINDOWCONTEXT_P_H
QWindowKit namespace.
Definition abstractwindowcontext.cpp:13