https://git.reactos.org/?p=reactos.git;a=commitdiff;h=f49919ce5d3de933c6dd4…
commit f49919ce5d3de933c6dd42b2beb54f82cae47e8c
Author: Katayama Hirofumi MZ <katayama.hirofumi.mz(a)gmail.com>
AuthorDate: Tue Oct 17 13:48:19 2023 +0900
Commit: GitHub <noreply(a)github.com>
CommitDate: Tue Oct 17 13:48:19 2023 +0900
[MSPAINT] Simplify canvas mouse message handling (#5803)
- Unify some mouse message handlers of
CCanvasWindow.
- Add CCanvasWindow::m_nMouseDownMsg
member.
CORE-19094
---
base/applications/mspaint/canvas.cpp | 54 +++++++++++-------------------------
base/applications/mspaint/canvas.h | 25 +++++++----------
2 files changed, 26 insertions(+), 53 deletions(-)
diff --git a/base/applications/mspaint/canvas.cpp b/base/applications/mspaint/canvas.cpp
index e19c4e6e306..e8b024e21ec 100644
--- a/base/applications/mspaint/canvas.cpp
+++ b/base/applications/mspaint/canvas.cpp
@@ -310,10 +310,13 @@ LRESULT CCanvasWindow::OnVScroll(UINT nMsg, WPARAM wParam, LPARAM
lParam, BOOL&
return 0;
}
-LRESULT CCanvasWindow::OnLRButtonDown(BOOL bLeftButton, UINT nMsg, WPARAM wParam, LPARAM
lParam, BOOL& bHandled)
+LRESULT CCanvasWindow::OnButtonDown(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL&
bHandled)
{
POINT pt = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) };
+ m_nMouseDownMsg = nMsg;
+ BOOL bLeftButton = (m_nMouseDownMsg == WM_LBUTTONDOWN);
+
HITTEST hitSelection = SelectionHitTest(pt);
if (hitSelection != HIT_NONE)
{
@@ -333,7 +336,7 @@ LRESULT CCanvasWindow::OnLRButtonDown(BOOL bLeftButton, UINT nMsg,
WPARAM wParam
}
else
{
- canvasWindow.ClientToScreen(&pt);
+ ClientToScreen(&pt);
mainWindow.TrackPopupMenu(pt, 0);
}
return 0;
@@ -347,13 +350,13 @@ LRESULT CCanvasWindow::OnLRButtonDown(BOOL bLeftButton, UINT nMsg,
WPARAM wParam
case TOOL_BEZIER:
case TOOL_SHAPE:
toolsModel.OnCancelDraw();
- canvasWindow.Invalidate();
+ Invalidate();
break;
case TOOL_FREESEL:
case TOOL_RECTSEL:
toolsModel.OnFinishDraw();
- canvasWindow.Invalidate();
+ Invalidate();
break;
default:
@@ -386,40 +389,21 @@ LRESULT CCanvasWindow::OnLRButtonDown(BOOL bLeftButton, UINT nMsg,
WPARAM wParam
return 0;
}
-LRESULT CCanvasWindow::OnLButtonDown(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL&
bHandled)
-{
- return OnLRButtonDown(TRUE, nMsg, wParam, lParam, bHandled);
-}
-
-LRESULT CCanvasWindow::OnRButtonDown(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL&
bHandled)
-{
- return OnLRButtonDown(FALSE, nMsg, wParam, lParam, bHandled);
-}
-
-LRESULT CCanvasWindow::OnLRButtonDblClk(BOOL bLeftButton, UINT nMsg, WPARAM wParam,
LPARAM lParam, BOOL& bHandled)
+LRESULT CCanvasWindow::OnButtonDblClk(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL&
bHandled)
{
POINT pt = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) };
CanvasToImage(pt);
m_drawing = FALSE;
- ReleaseCapture();
+ ::ReleaseCapture();
+ m_nMouseDownMsg = 0;
- toolsModel.OnButtonDown(bLeftButton, pt.x, pt.y, TRUE);
+ toolsModel.OnButtonDown(nMsg == WM_LBUTTONDBLCLK, pt.x, pt.y, TRUE);
toolsModel.resetTool();
Invalidate(FALSE);
return 0;
}
-LRESULT CCanvasWindow::OnLButtonDblClk(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL&
bHandled)
-{
- return OnLRButtonDblClk(TRUE, nMsg, wParam, lParam, bHandled);
-}
-
-LRESULT CCanvasWindow::OnRButtonDblClk(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL&
bHandled)
-{
- return OnLRButtonDblClk(FALSE, nMsg, wParam, lParam, bHandled);
-}
-
LRESULT CCanvasWindow::OnMouseMove(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL&
bHandled)
{
POINT pt = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) };
@@ -612,13 +596,16 @@ LRESULT CCanvasWindow::OnMouseMove(UINT nMsg, WPARAM wParam, LPARAM
lParam, BOOL
return 0;
}
-LRESULT CCanvasWindow::OnLRButtonUp(BOOL bLeftButton, UINT nMsg, WPARAM wParam, LPARAM
lParam, BOOL& bHandled)
+LRESULT CCanvasWindow::OnButtonUp(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL&
bHandled)
{
POINT pt = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) };
CanvasToImage(pt);
::ReleaseCapture();
+ BOOL bLeftButton = (m_nMouseDownMsg == WM_LBUTTONDOWN);
+ m_nMouseDownMsg = 0;
+
if (m_drawing)
{
m_drawing = FALSE;
@@ -680,16 +667,6 @@ LRESULT CCanvasWindow::OnLRButtonUp(BOOL bLeftButton, UINT nMsg,
WPARAM wParam,
return 0;
}
-LRESULT CCanvasWindow::OnLButtonUp(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL&
bHandled)
-{
- return OnLRButtonUp(TRUE, nMsg, wParam, lParam, bHandled);
-}
-
-LRESULT CCanvasWindow::OnRButtonUp(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL&
bHandled)
-{
- return OnLRButtonUp(FALSE, nMsg, wParam, lParam, bHandled);
-}
-
LRESULT CCanvasWindow::OnSetCursor(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL&
bHandled)
{
if (CWaitCursor::IsWaiting())
@@ -760,6 +737,7 @@ LRESULT CCanvasWindow::OnKeyDown(UINT nMsg, WPARAM wParam, LPARAM
lParam, BOOL&
{
// Cancel dragging
::ReleaseCapture();
+ m_nMouseDownMsg = 0;
m_hitCanvasSizeBox = HIT_NONE;
::SetRectEmpty(&m_rcResizing);
Invalidate(TRUE);
diff --git a/base/applications/mspaint/canvas.h b/base/applications/mspaint/canvas.h
index 21a6e11ecfa..238229e3b2b 100644
--- a/base/applications/mspaint/canvas.h
+++ b/base/applications/mspaint/canvas.h
@@ -20,13 +20,13 @@ public:
MESSAGE_HANDLER(WM_HSCROLL, OnHScroll)
MESSAGE_HANDLER(WM_VSCROLL, OnVScroll)
MESSAGE_HANDLER(WM_ERASEBKGND, OnEraseBkgnd)
- MESSAGE_HANDLER(WM_LBUTTONDOWN, OnLButtonDown)
- MESSAGE_HANDLER(WM_RBUTTONDOWN, OnRButtonDown)
- MESSAGE_HANDLER(WM_LBUTTONDBLCLK, OnLButtonDblClk)
- MESSAGE_HANDLER(WM_RBUTTONDBLCLK, OnRButtonDblClk)
+ MESSAGE_HANDLER(WM_LBUTTONDOWN, OnButtonDown)
+ MESSAGE_HANDLER(WM_RBUTTONDOWN, OnButtonDown)
+ MESSAGE_HANDLER(WM_LBUTTONDBLCLK, OnButtonDblClk)
+ MESSAGE_HANDLER(WM_RBUTTONDBLCLK, OnButtonDblClk)
MESSAGE_HANDLER(WM_KEYDOWN, OnKeyDown)
- MESSAGE_HANDLER(WM_LBUTTONUP, OnLButtonUp)
- MESSAGE_HANDLER(WM_RBUTTONUP, OnRButtonUp)
+ MESSAGE_HANDLER(WM_LBUTTONUP, OnButtonUp)
+ MESSAGE_HANDLER(WM_RBUTTONUP, OnButtonUp)
MESSAGE_HANDLER(WM_SETCURSOR, OnSetCursor)
MESSAGE_HANDLER(WM_MOUSEWHEEL, OnMouseWheel)
MESSAGE_HANDLER(WM_CANCELMODE, OnCancelMode)
@@ -76,14 +76,8 @@ protected:
LRESULT OnVScroll(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
LRESULT OnEraseBkgnd(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
LRESULT OnPaint(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
- LRESULT OnLButtonDown(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
- LRESULT OnRButtonDown(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
- LRESULT OnLButtonDblClk(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL&
bHandled);
- LRESULT OnRButtonDblClk(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL&
bHandled);
LRESULT OnMouseMove(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
LRESULT OnKeyDown(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
- LRESULT OnLButtonUp(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
- LRESULT OnRButtonUp(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
LRESULT OnSetCursor(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
LRESULT OnMouseWheel(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
LRESULT OnCancelMode(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
@@ -91,7 +85,8 @@ protected:
LRESULT OnCtlColorEdit(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
LRESULT OnPaletteModelColorChanged(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL&
bHandled);
- LRESULT OnLRButtonDown(BOOL bLeftButton, UINT nMsg, WPARAM wParam, LPARAM lParam,
BOOL& bHandled);
- LRESULT OnLRButtonDblClk(BOOL bLeftButton, UINT nMsg, WPARAM wParam, LPARAM lParam,
BOOL& bHandled);
- LRESULT OnLRButtonUp(BOOL bLeftButton, UINT nMsg, WPARAM wParam, LPARAM lParam,
BOOL& bHandled);
+ UINT m_nMouseDownMsg = 0;
+ LRESULT OnButtonDown(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
+ LRESULT OnButtonDblClk(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
+ LRESULT OnButtonUp(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
};