https://git.reactos.org/?p=reactos.git;a=commitdiff;h=97e53c6963678be5f399e…
commit 97e53c6963678be5f399e99e179c177358c14ab3
Author: Katayama Hirofumi MZ <katayama.hirofumi.mz(a)gmail.com>
AuthorDate: Tue Oct 17 15:58:34 2023 +0900
Commit: GitHub <noreply(a)github.com>
CommitDate: Tue Oct 17 15:58:34 2023 +0900
[MSPAINT] Implement mouse middle button dragging (#5804)
- Handle WM_MBUTTONDOWN and
WM_MBUTTONUP messages.
- Implement dragging by mouse middle button.
- Add IDC_HANDDRAG cursor resource.
CORE-19094
---
base/applications/mspaint/canvas.cpp | 33 +++++++++++++++++++++++----
base/applications/mspaint/canvas.h | 2 ++
base/applications/mspaint/icons/handdrag.cur | Bin 0 -> 326 bytes
base/applications/mspaint/resource.h | 1 +
base/applications/mspaint/rsrc.rc | 1 +
5 files changed, 33 insertions(+), 4 deletions(-)
diff --git a/base/applications/mspaint/canvas.cpp b/base/applications/mspaint/canvas.cpp
index e8b024e21ec..b423662d882 100644
--- a/base/applications/mspaint/canvas.cpp
+++ b/base/applications/mspaint/canvas.cpp
@@ -278,7 +278,7 @@ VOID CCanvasWindow::OnHVScroll(WPARAM wParam, INT fnBar)
{
case SB_THUMBTRACK:
case SB_THUMBPOSITION:
- si.nPos = HIWORD(wParam);
+ si.nPos = (SHORT)HIWORD(wParam);
break;
case SB_LINELEFT:
si.nPos -= 5;
@@ -293,9 +293,9 @@ VOID CCanvasWindow::OnHVScroll(WPARAM wParam, INT fnBar)
si.nPos += si.nPage;
break;
}
+ si.nPos = max(min(si.nPos, si.nMax), si.nMin);
SetScrollInfo(fnBar, &si);
- updateScrollRange();
- Invalidate(FALSE); // FIXME: Flicker
+ Invalidate();
}
LRESULT CCanvasWindow::OnHScroll(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL&
bHandled)
@@ -315,7 +315,15 @@ LRESULT CCanvasWindow::OnButtonDown(UINT nMsg, WPARAM wParam, LPARAM
lParam, BOO
POINT pt = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) };
m_nMouseDownMsg = nMsg;
- BOOL bLeftButton = (m_nMouseDownMsg == WM_LBUTTONDOWN);
+ BOOL bLeftButton = (nMsg == WM_LBUTTONDOWN);
+
+ if (nMsg == WM_MBUTTONDOWN)
+ {
+ m_ptOrig = pt;
+ SetCapture();
+ ::SetCursor(::LoadCursor(g_hinstExe, MAKEINTRESOURCE(IDC_HANDDRAG)));
+ return 0;
+ }
HITTEST hitSelection = SelectionHitTest(pt);
if (hitSelection != HIT_NONE)
@@ -407,6 +415,17 @@ LRESULT CCanvasWindow::OnButtonDblClk(UINT nMsg, WPARAM wParam,
LPARAM lParam, B
LRESULT CCanvasWindow::OnMouseMove(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL&
bHandled)
{
POINT pt = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) };
+
+ if (m_nMouseDownMsg == WM_MBUTTONDOWN)
+ {
+ INT x = GetScrollPos(SB_HORZ) - (pt.x - m_ptOrig.x);
+ INT y = GetScrollPos(SB_VERT) - (pt.y - m_ptOrig.y);
+ SendMessage(WM_HSCROLL, MAKEWPARAM(SB_THUMBPOSITION, x), 0);
+ SendMessage(WM_VSCROLL, MAKEWPARAM(SB_THUMBPOSITION, y), 0);
+ m_ptOrig = pt;
+ return 0;
+ }
+
CanvasToImage(pt);
if (toolsModel.GetActiveTool() == TOOL_ZOOM)
@@ -675,6 +694,12 @@ LRESULT CCanvasWindow::OnSetCursor(UINT nMsg, WPARAM wParam, LPARAM
lParam, BOOL
return 0;
}
+ if (m_nMouseDownMsg == WM_MBUTTONDOWN)
+ {
+ ::SetCursor(::LoadCursor(g_hinstExe, MAKEINTRESOURCE(IDC_HANDDRAG)));
+ return 0;
+ }
+
POINT pt;
::GetCursorPos(&pt);
ScreenToClient(&pt);
diff --git a/base/applications/mspaint/canvas.h b/base/applications/mspaint/canvas.h
index 238229e3b2b..76e7225ccfd 100644
--- a/base/applications/mspaint/canvas.h
+++ b/base/applications/mspaint/canvas.h
@@ -22,11 +22,13 @@ public:
MESSAGE_HANDLER(WM_ERASEBKGND, OnEraseBkgnd)
MESSAGE_HANDLER(WM_LBUTTONDOWN, OnButtonDown)
MESSAGE_HANDLER(WM_RBUTTONDOWN, OnButtonDown)
+ MESSAGE_HANDLER(WM_MBUTTONDOWN, OnButtonDown)
MESSAGE_HANDLER(WM_LBUTTONDBLCLK, OnButtonDblClk)
MESSAGE_HANDLER(WM_RBUTTONDBLCLK, OnButtonDblClk)
MESSAGE_HANDLER(WM_KEYDOWN, OnKeyDown)
MESSAGE_HANDLER(WM_LBUTTONUP, OnButtonUp)
MESSAGE_HANDLER(WM_RBUTTONUP, OnButtonUp)
+ MESSAGE_HANDLER(WM_MBUTTONUP, OnButtonUp)
MESSAGE_HANDLER(WM_SETCURSOR, OnSetCursor)
MESSAGE_HANDLER(WM_MOUSEWHEEL, OnMouseWheel)
MESSAGE_HANDLER(WM_CANCELMODE, OnCancelMode)
diff --git a/base/applications/mspaint/icons/handdrag.cur
b/base/applications/mspaint/icons/handdrag.cur
new file mode 100644
index 00000000000..74e5ba6b9c2
Binary files /dev/null and b/base/applications/mspaint/icons/handdrag.cur differ
diff --git a/base/applications/mspaint/resource.h b/base/applications/mspaint/resource.h
index b41486cee4d..3f87e6e42e1 100644
--- a/base/applications/mspaint/resource.h
+++ b/base/applications/mspaint/resource.h
@@ -22,6 +22,7 @@
#define IDC_ZOOM 532
#define IDC_PEN 533
#define IDC_AIRBRUSH 534
+#define IDC_HANDDRAG 535
#define IDI_HORZSTRETCH 535
#define IDI_VERTSTRETCH 536
diff --git a/base/applications/mspaint/rsrc.rc b/base/applications/mspaint/rsrc.rc
index 4bca40c0a6f..1f0ee5aca23 100644
--- a/base/applications/mspaint/rsrc.rc
+++ b/base/applications/mspaint/rsrc.rc
@@ -33,6 +33,7 @@ IDC_COLOR ICON "icons/color_cur.ico"
IDC_ZOOM ICON "icons/zoom_cur.ico"
IDC_PEN ICON "icons/pen_cur.ico"
IDC_AIRBRUSH ICON "icons/airbrush_cur.ico"
+IDC_HANDDRAG CURSOR "icons/handdrag.cur"
IDI_HORZSTRETCH ICON "icons/horzstretch.ico"
IDI_VERTSTRETCH ICON "icons/vertstretch.ico"