From 0d31eda795a5bbfd62f070b54f2409761a0eb87f Mon Sep 17 00:00:00 2001
From: SineStriker <trueful@163.com>
Date: 周五, 01 12月 2023 18:22:00 +0800
Subject: [PATCH] Add small implementations

---
 src/core/handler/win32windowcontext.cpp |   39 +++++++++++++++++--
 qmsetup                                 |    1 
 src/core/corewindowagent.h              |    1 
 src/core/handler/qtwindowcontext_p.h    |    3 +
 src/core/handler/qtwindowcontext.cpp    |   42 +++++++++++++++++++++
 5 files changed, 81 insertions(+), 5 deletions(-)

diff --git a/qmsetup b/qmsetup
new file mode 160000
index 0000000..f1c0099
--- /dev/null
+++ b/qmsetup
@@ -0,0 +1 @@
+Subproject commit f1c00991ef5a360ec2148dd125a8bb7c4d8a16a1
diff --git a/src/core/corewindowagent.h b/src/core/corewindowagent.h
index 56c9b99..831f8e1 100644
--- a/src/core/corewindowagent.h
+++ b/src/core/corewindowagent.h
@@ -24,6 +24,7 @@
             Close,
             NumSystemButton,
         };
+        Q_ENUM(SystemButton)
 
     public Q_SLOTS:
         void showSystemMenu(const QPoint &pos);
diff --git a/src/core/handler/qtwindowcontext.cpp b/src/core/handler/qtwindowcontext.cpp
index 0dfd7a1..1716fb2 100644
--- a/src/core/handler/qtwindowcontext.cpp
+++ b/src/core/handler/qtwindowcontext.cpp
@@ -2,6 +2,44 @@
 
 namespace QWK {
 
+    static constexpr const int kDefaultResizeBorderThickness = 8;
+
+    static Qt::CursorShape calculateCursorShape(const QWindow *window, const QPoint &pos) {
+#ifdef Q_OS_MACOS
+        Q_UNUSED(window);
+        Q_UNUSED(pos);
+        return Qt::ArrowCursor;
+#else
+        Q_ASSERT(window);
+        if (!window) {
+            return Qt::ArrowCursor;
+        }
+        if (window->visibility() != QWindow::Windowed) {
+            return Qt::ArrowCursor;
+        }
+        const int x = pos.x();
+        const int y = pos.y();
+        const int w = window->width();
+        const int h = window->height();
+        if (((x < kDefaultResizeBorderThickness) && (y < kDefaultResizeBorderThickness)) ||
+            ((x >= (w - kDefaultResizeBorderThickness)) &&
+             (y >= (h - kDefaultResizeBorderThickness)))) {
+            return Qt::SizeFDiagCursor;
+        }
+        if (((x >= (w - kDefaultResizeBorderThickness)) && (y < kDefaultResizeBorderThickness)) ||
+            ((x < kDefaultResizeBorderThickness) && (y >= (h - kDefaultResizeBorderThickness)))) {
+            return Qt::SizeBDiagCursor;
+        }
+        if ((x < kDefaultResizeBorderThickness) || (x >= (w - kDefaultResizeBorderThickness))) {
+            return Qt::SizeHorCursor;
+        }
+        if ((y < kDefaultResizeBorderThickness) || (y >= (h - kDefaultResizeBorderThickness))) {
+            return Qt::SizeVerCursor;
+        }
+        return Qt::ArrowCursor;
+#endif
+    }
+
     QtWindowContext::QtWindowContext(QWindow *window, WindowItemDelegate *delegate)
         : AbstractWindowContext(window, delegate) {
     }
@@ -9,4 +47,8 @@
     QtWindowContext::~QtWindowContext() {
     }
 
+    bool QtWindowContext::eventFilter(QObject *obj, QEvent *event) {
+        return AbstractWindowContext::eventFilter(obj, event);
+    }
+
 }
\ No newline at end of file
diff --git a/src/core/handler/qtwindowcontext_p.h b/src/core/handler/qtwindowcontext_p.h
index 3134384..c856da2 100644
--- a/src/core/handler/qtwindowcontext_p.h
+++ b/src/core/handler/qtwindowcontext_p.h
@@ -10,6 +10,9 @@
     public:
         QtWindowContext(QWindow *window, WindowItemDelegate *delegate);
         ~QtWindowContext();
+
+    protected:
+        bool eventFilter(QObject *obj, QEvent *event) override;
     };
 
 }
diff --git a/src/core/handler/win32windowcontext.cpp b/src/core/handler/win32windowcontext.cpp
index 1208b04..0311532 100644
--- a/src/core/handler/win32windowcontext.cpp
+++ b/src/core/handler/win32windowcontext.cpp
@@ -4,16 +4,45 @@
 
 namespace QWK {
 
-    static LRESULT CALLBACK QWKWindowsWndProc(const HWND hWnd, const UINT uMsg, const WPARAM wParam,
-                                              const LPARAM lParam) {
+    static LRESULT CALLBACK QWK_WindowsWndProc(const HWND hWnd, const UINT uMsg,
+                                               const WPARAM wParam, const LPARAM lParam) {
         // Implement
         return 0;
     }
 
-    Win32WindowContext::Win32WindowContext(QWindow *window,
-                                                     WindowItemDelegate *delegate)
+    static bool hookWindowProc(QObject *window, WId windowId) {
+        Q_ASSERT(windowId);
+        if (!windowId) {
+            return false;
+        }
+
+        const auto hwnd = reinterpret_cast<HWND>(windowId);
+        if (!extraData->qtWindowProc) {
+            ::SetLastError(ERROR_SUCCESS);
+            const auto qtWindowProc =
+                reinterpret_cast<WNDPROC>(::GetWindowLongPtrW(hwnd, GWLP_WNDPROC));
+            Q_ASSERT(qtWindowProc);
+            if (!qtWindowProc) {
+                WARNING << getSystemErrorMessage(kGetWindowLongPtrW);
+                return false;
+            }
+            extraData->qtWindowProc = qtWindowProc;
+        }
+        if (!extraData->windowProcHooked) {
+            ::SetLastError(ERROR_SUCCESS);
+            if (::SetWindowLongPtrW(hwnd, GWLP_WNDPROC,
+                                    reinterpret_cast<LONG_PTR>(QWK_WindowsWndProc)) == 0) {
+                WARNING << getSystemErrorMessage(kSetWindowLongPtrW);
+                return false;
+            }
+            extraData->windowProcHooked = true;
+        }
+        return true;
+    }
+
+    Win32WindowContext::Win32WindowContext(QWindow *window, WindowItemDelegate *delegate)
         : AbstractWindowContext(window, delegate) {
-        // Install windows hook
+        // Install windows window hook
     }
 
     Win32WindowContext::~Win32WindowContext() {

--
Gitblit v1.9.1