| | |
| | | |
| | | namespace QWK { |
| | | |
| | | AbstractWindowContext::AbstractWindowContext(QObject *host, WindowItemDelegate *delegate) |
| | | AbstractWindowContext::AbstractWindowContext(const QObject *host, const WindowItemDelegate *delegate) |
| | | : m_host(host), m_delegate(delegate), m_windowHandle(delegate->hostWindow(host)) { |
| | | } |
| | | |
| | |
| | | class QWK_CORE_EXPORT AbstractWindowContext : public QObject { |
| | | Q_OBJECT |
| | | public: |
| | | AbstractWindowContext(QObject *host, WindowItemDelegate *delegate); |
| | | AbstractWindowContext(const QObject *host, const WindowItemDelegate *delegate); |
| | | ~AbstractWindowContext() override; |
| | | |
| | | public: |
| | | virtual bool setup() = 0; |
| | | |
| | | inline QObject *host() const; |
| | | inline const QObject *host() const; |
| | | inline QWindow *window() const; |
| | | |
| | | inline bool isHitTestVisible(const QObject *obj) const; |
| | |
| | | bool isInTitleBarDraggableArea(const QPoint &pos) const; |
| | | |
| | | protected: |
| | | QObject *m_host; |
| | | std::unique_ptr<WindowItemDelegate> m_delegate; |
| | | const QObject *m_host; |
| | | const WindowItemDelegate *m_delegate; |
| | | QWindow *m_windowHandle; |
| | | |
| | | QSet<const QObject *> m_hitTestVisibleItems; |
| | |
| | | mutable QRegion hitTestVisibleShape; |
| | | }; |
| | | |
| | | inline QObject *AbstractWindowContext::host() const { |
| | | inline const QObject *AbstractWindowContext::host() const { |
| | | return m_host; |
| | | } |
| | | |
| | |
| | | static WindowsNativeEventFilter *instance; |
| | | |
| | | static inline void install() { |
| | | if (instance) { |
| | | return; |
| | | } |
| | | instance = new WindowsNativeEventFilter(); |
| | | installNativeEventFilter(instance); |
| | | } |
| | | |
| | | static inline void uninstall() { |
| | | if (!instance) { |
| | | return; |
| | | } |
| | | removeNativeEventFilter(instance); |
| | | delete instance; |
| | | instance = nullptr; |
| | |
| | | return ::CallWindowProcW(g_qtWindowProc, hWnd, message, wParam, lParam); |
| | | } |
| | | |
| | | Win32WindowContext::Win32WindowContext(QObject *host, WindowItemDelegate *delegate) |
| | | Win32WindowContext::Win32WindowContext(const QObject *host, const WindowItemDelegate *delegate) |
| | | : AbstractWindowContext(host, delegate) { |
| | | } |
| | | |
| | |
| | | ::SetWindowLongPtrW(hWnd, GWLP_WNDPROC, reinterpret_cast<LONG_PTR>(QWKHookedWndProc)); |
| | | |
| | | // Install global native event filter |
| | | if (!WindowsNativeEventFilter::instance) { |
| | | WindowsNativeEventFilter::install(); |
| | | } |
| | | WindowsNativeEventFilter::install(); |
| | | |
| | | // Cache window ID |
| | | windowId = winId; |
| | |
| | | class QWK_CORE_EXPORT Win32WindowContext : public AbstractWindowContext { |
| | | Q_OBJECT |
| | | public: |
| | | Win32WindowContext(QObject *host, WindowItemDelegate *delegate); |
| | | Win32WindowContext(const QObject *host, const WindowItemDelegate *delegate); |
| | | ~Win32WindowContext() override; |
| | | |
| | | enum WindowPart { |
| | |
| | | CoreWindowAgentPrivate::CoreWindowAgentPrivate() : q_ptr(nullptr), context(nullptr) { |
| | | } |
| | | |
| | | CoreWindowAgentPrivate::~CoreWindowAgentPrivate() = default; |
| | | CoreWindowAgentPrivate::~CoreWindowAgentPrivate() { |
| | | if (context) { |
| | | delete context; |
| | | context = nullptr; |
| | | } |
| | | } |
| | | |
| | | void CoreWindowAgentPrivate::init() { |
| | | } |
| | | |
| | | bool CoreWindowAgentPrivate::setup(QObject *host, WindowItemDelegate *delegate) { |
| | | bool CoreWindowAgentPrivate::setup(const QObject *host, const WindowItemDelegate *delegate) { |
| | | auto ctx = |
| | | #ifdef Q_OS_WINDOWS |
| | | std::make_unique<Win32WindowContext>(host, delegate) |
| | | new Win32WindowContext(host, delegate) |
| | | #else |
| | | std::make_unique<QtWindowContext>(host, window, delegate) |
| | | new QtWindowContext(host, window, delegate) |
| | | #endif |
| | | ; |
| | | if (!ctx->setup()) { |
| | | delete ctx; |
| | | ctx = nullptr; |
| | | return false; |
| | | } |
| | | context = std::move(ctx); |
| | | context = ctx; |
| | | return true; |
| | | } |
| | | |
| | |
| | | |
| | | CoreWindowAgent *q_ptr; // no need to initialize |
| | | |
| | | bool setup(QObject *host, WindowItemDelegate *delegate); |
| | | bool setup(const QObject *host, const WindowItemDelegate *delegate); |
| | | |
| | | std::unique_ptr<AbstractWindowContext> context; |
| | | AbstractWindowContext *context; |
| | | |
| | | private: |
| | | Q_DISABLE_COPY_MOVE(CoreWindowAgentPrivate) |
| | | }; |
| | | |