Sine Striker
2024-07-28 e9d163b1a811ee4f02e898bc7c2e6336d88e4a7f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
// Copyright (C) 2023-2024 Stdware Collections (https://www.github.com/stdware)
// Copyright (C) 2021-2023 wangwenx190 (Yuhang Zhao)
// SPDX-License-Identifier: Apache-2.0
 
#ifndef ABSTRACTWINDOWCONTEXT_P_H
#define ABSTRACTWINDOWCONTEXT_P_H
 
//
//  W A R N I N G !!!
//  -----------------
//
// This file is not part of the QWindowKit API. It is used purely as an
// implementation detail. This header file may change from version to
// version without notice, or may even be removed.
//
 
#include <array>
#include <memory>
 
#include <QtCore/QSet>
#include <QtCore/QPointer>
#include <QtGui/QRegion>
#include <QtGui/QWindow>
 
#include <QWKCore/windowagentbase.h>
#include <QWKCore/private/nativeeventfilter_p.h>
#include <QWKCore/private/sharedeventfilter_p.h>
#include <QWKCore/private/windowitemdelegate_p.h>
#include <QWKCore/private/winidchangeeventfilter_p.h>
 
namespace QWK {
 
    class QWK_CORE_EXPORT AbstractWindowContext : public QObject,
                                                  public NativeEventDispatcher,
                                                  public SharedEventDispatcher {
        Q_OBJECT
    public:
        AbstractWindowContext();
        ~AbstractWindowContext() override;
 
    public:
        void setup(QObject *host, WindowItemDelegate *delegate);
 
        inline QObject *host() const;
        inline QWindow *window() const;
        inline WId windowId() const;
        inline WindowItemDelegate *delegate() const;
 
        inline bool isHitTestVisible(const QObject *obj) const;
        bool setHitTestVisible(QObject *obj, bool visible);
 
        inline QObject *systemButton(WindowAgentBase::SystemButton button) const;
        bool setSystemButton(WindowAgentBase::SystemButton button, QObject *obj);
 
        inline QObject *titleBar() const;
        bool setTitleBar(QObject *obj);
 
#ifdef Q_OS_MAC
        inline ScreenRectCallback systemButtonAreaCallback() const;
        void setSystemButtonAreaCallback(const ScreenRectCallback &callback);
#endif
 
        bool isInSystemButtons(const QPoint &pos, WindowAgentBase::SystemButton *button) const;
        bool isInTitleBarDraggableArea(const QPoint &pos) const;
 
        inline bool isHostWidthFixed() const {
            return m_windowHandle
                       ? ((m_windowHandle->flags() & Qt::MSWindowsFixedSizeDialogHint) ||
                          m_windowHandle->minimumWidth() == m_windowHandle->maximumWidth())
                       : false;
        }
        inline bool isHostHeightFixed() const {
            return m_windowHandle
                       ? ((m_windowHandle->flags() & Qt::MSWindowsFixedSizeDialogHint) ||
                          m_windowHandle->minimumHeight() == m_windowHandle->maximumHeight())
                       : false;
        }
        inline bool isHostSizeFixed() const {
            return m_windowHandle ? ((m_windowHandle->flags() & Qt::MSWindowsFixedSizeDialogHint) ||
                                     m_windowHandle->minimumSize() == m_windowHandle->maximumSize())
                                  : false;
        }
 
        virtual QString key() const;
 
        enum WindowContextHook {
            CentralizeHook = 1,
            RaiseWindowHook,
            ShowSystemMenuHook,
            DefaultColorsHook,
            DrawWindows10BorderHook,     // Only works on Windows 10, emulated workaround
            DrawWindows10BorderHook2,    // Only works on Windows 10, native workaround
            SystemButtonAreaChangedHook, // Only works on Mac
        };
        virtual void virtual_hook(int id, void *data);
 
        void showSystemMenu(const QPoint &pos);
        void notifyWinIdChange();
 
        virtual QVariant windowAttribute(const QString &key) const;
        virtual bool setWindowAttribute(const QString &key, const QVariant &attribute);
 
    protected:
        bool eventFilter(QObject *obj, QEvent *event) override;
 
    protected:
        virtual void winIdChanged(WId winId, WId oldWinId) = 0;
        virtual bool windowAttributeChanged(const QString &key, const QVariant &attribute,
                                            const QVariant &oldAttribute);
 
    protected:
        QObject *m_host{};
        std::unique_ptr<WindowItemDelegate> m_delegate;
        QPointer<QWindow> m_windowHandle;
        WId m_windowId{};
 
        QSet<const QObject *> m_hitTestVisibleItems;
#ifdef Q_OS_MAC
        ScreenRectCallback m_systemButtonAreaCallback;
#endif
 
        QObject *m_titleBar{};
        std::array<QObject *, WindowAgentBase::Close + 1> m_systemButtons{};
 
        QVariantHash m_windowAttributes;
        std::unique_ptr<WinIdChangeEventFilter> m_winIdChangeEventFilter;
        
        void removeSystemButtonsAndHitTestItems();
 
    private:
        void _q_titleBarDistroyed(QObject *obj);
        void _q_hitTestVisibleItemDestroyed(QObject *obj);
        void _q_systemButtonDestroyed(QObject *obj);
    };
 
    inline QObject *AbstractWindowContext::host() const {
        return m_host;
    }
 
    inline QWindow *AbstractWindowContext::window() const {
        return m_windowHandle;
    }
 
    inline WId AbstractWindowContext::windowId() const {
        return m_windowId;
    }
 
    inline WindowItemDelegate *AbstractWindowContext::delegate() const {
        return m_delegate.get();
    }
 
    inline bool AbstractWindowContext::isHitTestVisible(const QObject *obj) const {
        return m_hitTestVisibleItems.contains(obj);
    }
 
    inline QObject *
        AbstractWindowContext::systemButton(WindowAgentBase::SystemButton button) const {
        return m_systemButtons[button];
    }
 
    inline QObject *AbstractWindowContext::titleBar() const {
        return m_titleBar;
    }
 
#ifdef Q_OS_MAC
    inline ScreenRectCallback AbstractWindowContext::systemButtonAreaCallback() const {
        return m_systemButtonAreaCallback;
    }
#endif
 
}
 
#endif // ABSTRACTWINDOWCONTEXT_P_H