From 573488a6fec17a9fc71e4d8b0a4741c107ab4ef8 Mon Sep 17 00:00:00 2001
From: Sine Striker <trueful@163.com>
Date: 周一, 11 12月 2023 16:35:29 +0800
Subject: [PATCH] Add virtual hook

---
 src/core/contexts/win32windowcontext.cpp |   43 ++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 38 insertions(+), 5 deletions(-)

diff --git a/src/core/contexts/win32windowcontext.cpp b/src/core/contexts/win32windowcontext.cpp
index 9cf1ecc..2168e44 100644
--- a/src/core/contexts/win32windowcontext.cpp
+++ b/src/core/contexts/win32windowcontext.cpp
@@ -5,6 +5,7 @@
 #include <QtCore/QHash>
 #include <QtCore/QScopeGuard>
 #include <QtGui/QGuiApplication>
+#include <QtGui/QPainter>
 
 #include <QtCore/private/qsystemlibrary_p.h>
 #include <QtGui/private/qhighdpiscaling_p.h>
@@ -669,10 +670,42 @@
         }
     }
 
-    void Win32WindowContext::showSystemMenu(const QPoint &pos) {
-        auto winId = m_windowHandle->winId();
-        auto hWnd = reinterpret_cast<HWND>(winId);
-        showSystemMenu2(hWnd, {pos.x(), pos.y()}, false, m_delegate->isHostSizeFixed(m_host));
+    QString Win32WindowContext::key() const {
+        return "win32";
+    }
+
+    void Win32WindowContext::virtual_hook(int id, void *data) {
+        switch (id) {
+            case ShowSystemMenuHook: {
+                const auto &pos = *reinterpret_cast<const QPoint *>(data);
+                auto winId = m_windowHandle->winId();
+                auto hWnd = reinterpret_cast<HWND>(winId);
+                showSystemMenu2(hWnd, {pos.x(), pos.y()}, false,
+                                m_delegate->isHostSizeFixed(m_host));
+                return;
+            }
+            case NeedsDrawBordersHook: {
+                auto &result = *reinterpret_cast<bool *>(data);
+                result = isWin10OrGreater() && !isWin11OrGreater();
+                return;
+            }
+            case DrawBordersHook: {
+                auto a = reinterpret_cast<void **>(data);
+                auto &painter = *reinterpret_cast<QPainter *>(a[0]);
+                auto &rect = *reinterpret_cast<const QRect *>(a[1]);
+                auto &region = *reinterpret_cast<const QRegion *>(a[2]);
+
+                qDebug() << "paint" << &painter << rect << region;
+
+                // TODO: Draw border
+                // ...
+
+                break;
+            }
+            default:
+                break;
+        }
+        AbstractWindowContext::virtual_hook(id, data);
     }
 
     bool Win32WindowContext::setupHost() {
@@ -742,7 +775,7 @@
         return false; // Not handled
     }
 
-    static constexpr const auto kMessageTag = WPARAM(0x97CCEA99);
+    static constexpr const auto kMessageTag = WPARAM(0xF1C9ADD4);
 
     static inline constexpr bool isTaggedMessage(WPARAM wParam) {
         return (wParam == kMessageTag);

--
Gitblit v1.9.1