| | |
| | | |
| | | namespace QWK { |
| | | |
| | | AbstractWindowContext::~AbstractWindowContext() = default; |
| | | AbstractWindowContext::~AbstractWindowContext() { |
| | | delete m_delegate; |
| | | } |
| | | |
| | | void AbstractWindowContext::setupWindow(QWindow *window) { |
| | | Q_ASSERT(window); |
| | |
| | | } else { |
| | | m_hitTestVisibleRects.removeAll(rect); |
| | | } |
| | | hitTestVisibleShapeDirty = true; |
| | | return true; |
| | | } |
| | | |
| | |
| | | // ? |
| | | } |
| | | |
| | | QRegion AbstractWindowContext::hitTestShape() const { |
| | | if (hitTestVisibleShapeDirty) { |
| | | hitTestVisibleShape = {}; |
| | | for (const auto &rect : m_hitTestVisibleRects) { |
| | | hitTestVisibleShape += rect; |
| | | } |
| | | hitTestVisibleShapeDirty = false; |
| | | } |
| | | return hitTestVisibleShape; |
| | | } |
| | | |
| | | } |
| | |
| | | #ifndef ABSTRACTWINDOWCONTEXT_P_H |
| | | #define ABSTRACTWINDOWCONTEXT_P_H |
| | | |
| | | #include <array> |
| | | |
| | | #include <QtCore/QSet> |
| | | #include <QtGui/QWindow> |
| | | #include <QtGui/QPolygon> |
| | |
| | | |
| | | class QWK_CORE_EXPORT AbstractWindowContext : public QObject { |
| | | Q_OBJECT |
| | | Q_DISABLE_COPY(AbstractWindowContext) |
| | | |
| | | public: |
| | | inline AbstractWindowContext(QWindow *window, WindowItemDelegatePtr delegate) |
| | | : m_windowHandle(window), m_delegate(std::move(delegate)) |
| | | { |
| | | inline AbstractWindowContext(QWindow *window, WindowItemDelegate *delegate) |
| | | : m_windowHandle(window), m_delegate(delegate) { |
| | | } |
| | | ~AbstractWindowContext() override; |
| | | |
| | |
| | | |
| | | void showSystemMenu(const QPoint &pos); |
| | | |
| | | QRegion hitTestShape() const; |
| | | |
| | | protected: |
| | | QWindow *m_windowHandle; |
| | | WindowItemDelegatePtr m_delegate; |
| | | WindowItemDelegate *m_delegate; |
| | | |
| | | QSet<QObject *> m_hitTestVisibleItems; |
| | | QList<QRect> m_hitTestVisibleRects; |
| | |
| | | QObject *m_titleBar{}; |
| | | std::array<QObject *, CoreWindowAgent::NumSystemButton> m_systemButtons{}; |
| | | |
| | | // Cached shape |
| | | mutable bool hitTestVisibleShapeDirty{}; |
| | | mutable QPolygon hitTestVisibleShape; |
| | | mutable QRegion hitTestVisibleShape; |
| | | }; |
| | | |
| | | inline QWindow *AbstractWindowContext::window() const { |
| | |
| | | inline QObject *AbstractWindowContext::titleBar() const { |
| | | return m_titleBar; |
| | | } |
| | | |
| | | using WindowContextPtr = std::shared_ptr<AbstractWindowContext>; |
| | | |
| | | } |
| | | |
| | |
| | | #endif |
| | | } |
| | | |
| | | QtWindowContext::QtWindowContext(QWindow *window, WindowItemDelegatePtr delegate) |
| | | QtWindowContext::QtWindowContext(QWindow *window, WindowItemDelegate *delegate) |
| | | : AbstractWindowContext(window, delegate) { |
| | | } |
| | | |
| | |
| | | |
| | | class QWK_CORE_EXPORT QtWindowContext : public AbstractWindowContext { |
| | | Q_OBJECT |
| | | Q_DISABLE_COPY(QtWindowContext) |
| | | |
| | | public: |
| | | QtWindowContext(QWindow *window, WindowItemDelegatePtr delegate); |
| | | QtWindowContext(QWindow *window, WindowItemDelegate *delegate); |
| | | ~QtWindowContext(); |
| | | |
| | | public: |
| | |
| | | return ::CallWindowProcW(g_qtWindowProc, hWnd, message, wParam, lParam); |
| | | } |
| | | |
| | | Win32WindowContext::Win32WindowContext(QWindow *window, WindowItemDelegatePtr delegate) |
| | | : AbstractWindowContext(window, std::move(delegate)), windowId(0) { |
| | | Win32WindowContext::Win32WindowContext(QWindow *window, WindowItemDelegate *delegate) |
| | | : AbstractWindowContext(window, delegate), windowId(0) { |
| | | } |
| | | |
| | | Win32WindowContext::~Win32WindowContext() { |
| | |
| | | // TODO: Implement |
| | | // ... |
| | | |
| | | Q_UNUSED(windowId) |
| | | |
| | | return false; // Not handled |
| | | } |
| | | |
| | |
| | | |
| | | class QWK_CORE_EXPORT Win32WindowContext : public AbstractWindowContext { |
| | | Q_OBJECT |
| | | Q_DISABLE_COPY(Win32WindowContext) |
| | | |
| | | public: |
| | | Win32WindowContext(QWindow *window, WindowItemDelegatePtr delegate); |
| | | Win32WindowContext(QWindow *window, WindowItemDelegate *delegate); |
| | | ~Win32WindowContext() override; |
| | | |
| | | public: |
| | |
| | | |
| | | namespace QWK { |
| | | |
| | | CoreWindowAgentPrivate::CoreWindowAgentPrivate() : q_ptr(nullptr), eventHandler(nullptr) { |
| | | CoreWindowAgentPrivate::CoreWindowAgentPrivate() : eventHandler(nullptr) { |
| | | } |
| | | |
| | | CoreWindowAgentPrivate::~CoreWindowAgentPrivate() = default; |
| | | CoreWindowAgentPrivate::~CoreWindowAgentPrivate() { |
| | | delete eventHandler; |
| | | } |
| | | |
| | | void CoreWindowAgentPrivate::init() { |
| | | } |
| | | |
| | | bool CoreWindowAgentPrivate::setup(QWindow *window, const WindowItemDelegatePtr &delegate) { |
| | | bool CoreWindowAgentPrivate::setup(QWindow *window, WindowItemDelegate *delegate) { |
| | | Q_ASSERT(window); |
| | | if (!window) { |
| | | return false; |
| | | } |
| | | |
| | | auto handler = |
| | | #ifdef Q_OS_WINDOWS |
| | | std::make_shared<Win32WindowContext>(window, delegate) |
| | | new Win32WindowContext(window, delegate) |
| | | #else |
| | | std::make_shared<QtWindowContext>(window, delegate) |
| | | new QtWindowContext(window, delegate) |
| | | #endif |
| | | ; |
| | | |
| | | if (!handler->setup()) { |
| | | delete handler; |
| | | return false; |
| | | } |
| | | eventHandler = handler; |
| | |
| | | |
| | | class QWK_CORE_EXPORT CoreWindowAgent : public QObject { |
| | | Q_OBJECT |
| | | Q_DISABLE_COPY(CoreWindowAgent) |
| | | Q_DECLARE_PRIVATE(CoreWindowAgent) |
| | | |
| | | public: |
| | | ~CoreWindowAgent() override; |
| | | |
| | |
| | | namespace QWK { |
| | | |
| | | class QWK_CORE_EXPORT CoreWindowAgentPrivate { |
| | | Q_DISABLE_COPY(CoreWindowAgentPrivate) |
| | | Q_DECLARE_PUBLIC(CoreWindowAgent) |
| | | |
| | | public: |
| | | CoreWindowAgentPrivate(); |
| | | virtual ~CoreWindowAgentPrivate(); |
| | |
| | | |
| | | CoreWindowAgent *q_ptr; // no need to initialize |
| | | |
| | | bool setup(QWindow *window, const WindowItemDelegatePtr &delegate); |
| | | bool setup(QWindow *window, WindowItemDelegate *delegate); |
| | | |
| | | WindowContextPtr eventHandler; |
| | | AbstractWindowContext *eventHandler; |
| | | |
| | | Q_DISABLE_COPY_MOVE(CoreWindowAgentPrivate) |
| | | }; |
| | | |
| | | } |
| | |
| | | #ifndef WINDOWITEMDELEGATE_H |
| | | #define WINDOWITEMDELEGATE_H |
| | | |
| | | #include <memory> |
| | | |
| | | #include <QtCore/QObject> |
| | | #include <QtGui/QWindow> |
| | | |
| | |
| | | namespace QWK { |
| | | |
| | | class WindowItemDelegate { |
| | | Q_DISABLE_COPY(WindowItemDelegate) |
| | | |
| | | public: |
| | | WindowItemDelegate() = default; |
| | | virtual ~WindowItemDelegate() = default; |
| | |
| | | |
| | | virtual bool isEnabled(QObject *obj) const = 0; |
| | | virtual bool isVisible(QObject *obj) const = 0; |
| | | }; |
| | | |
| | | using WindowItemDelegatePtr = std::shared_ptr<WindowItemDelegate>; |
| | | private: |
| | | Q_DISABLE_COPY_MOVE(WindowItemDelegate) |
| | | }; |
| | | |
| | | } |
| | | |
| | |
| | | namespace QWK { |
| | | |
| | | class QWK_QUICK_EXPORT QuickItemDelegate : public WindowItemDelegate { |
| | | Q_DISABLE_COPY(QuickItemDelegate) |
| | | |
| | | public: |
| | | QuickItemDelegate(); |
| | | ~QuickItemDelegate() override; |
| | |
| | | return false; |
| | | } |
| | | |
| | | if (!d->setup(window, std::make_shared<QuickItemDelegate>())) { |
| | | if (!d->setup(window, new QuickItemDelegate())) { |
| | | return true; |
| | | } |
| | | d->host = window; |
| | |
| | | |
| | | class QWK_QUICK_EXPORT QuickWindowAgent : public CoreWindowAgent { |
| | | Q_OBJECT |
| | | Q_DISABLE_COPY(QuickWindowAgent) |
| | | Q_DECLARE_PRIVATE(QuickWindowAgent) |
| | | |
| | | public: |
| | | explicit QuickWindowAgent(QObject *parent = nullptr); |
| | | ~QuickWindowAgent() override; |
| | |
| | | namespace QWK { |
| | | |
| | | class QuickWindowAgentPrivate : public CoreWindowAgentPrivate { |
| | | Q_DISABLE_COPY(QuickWindowAgentPrivate) |
| | | Q_DECLARE_PUBLIC(QuickWindowAgent) |
| | | |
| | | public: |
| | | QuickWindowAgentPrivate(); |
| | | ~QuickWindowAgentPrivate() override; |
| | |
| | | namespace QWK { |
| | | |
| | | class QWK_WIDGETS_EXPORT WidgetItemDelegate : public WindowItemDelegate { |
| | | Q_DISABLE_COPY(WidgetItemDelegate) |
| | | |
| | | public: |
| | | WidgetItemDelegate(); |
| | | ~WidgetItemDelegate() override; |
| | |
| | | } |
| | | |
| | | std::ignore = w->winId(); // Make sure the window handle is created |
| | | if (!d->setup(w->windowHandle(), std::make_shared<WidgetItemDelegate>())) { |
| | | if (!d->setup(w->windowHandle(), new WidgetItemDelegate())) { |
| | | return false; |
| | | } |
| | | d->host = w; |
| | |
| | | |
| | | class QWK_WIDGETS_EXPORT WidgetWindowAgent : public CoreWindowAgent { |
| | | Q_OBJECT |
| | | Q_DISABLE_COPY(WidgetWindowAgent) |
| | | Q_DECLARE_PRIVATE(WidgetWindowAgent) |
| | | |
| | | public: |
| | | explicit WidgetWindowAgent(QObject *parent = nullptr); |
| | | ~WidgetWindowAgent() override; |
| | |
| | | namespace QWK { |
| | | |
| | | class WidgetWindowAgentPrivate : public CoreWindowAgentPrivate { |
| | | Q_DISABLE_COPY(WidgetWindowAgentPrivate) |
| | | Q_DECLARE_PUBLIC(WidgetWindowAgent) |
| | | |
| | | public: |
| | | WidgetWindowAgentPrivate(); |
| | | ~WidgetWindowAgentPrivate(); |