https://git.reactos.org/?p=reactos.git;a=commitdiff;h=1a886073876781c410fb2…
commit 1a886073876781c410fb2e815a3528a1430b852b
Author: Katayama Hirofumi MZ <katayama.hirofumi.mz(a)gmail.com>
AuthorDate: Tue Jun 13 16:31:18 2023 +0900
Commit: GitHub <noreply(a)github.com>
CommitDate: Tue Jun 13 16:31:18 2023 +0900
[MSPAINT] Move selection by arrow keys (#5334)
Improve keyboard usability.
- Add CCanvasWindow::MoveSelection.
- Modify CMainWindow::OnKeyDown.
- If Esc key is pressed, then the selection will land to canvas.
- If any arrow key is pressed, then the selection will move a bit.
CORE-18867
---
base/applications/mspaint/canvas.cpp | 10 +++++++++
base/applications/mspaint/canvas.h | 1 +
base/applications/mspaint/winproc.cpp | 38 +++++++++++++++++++++++++++--------
3 files changed, 41 insertions(+), 8 deletions(-)
diff --git a/base/applications/mspaint/canvas.cpp b/base/applications/mspaint/canvas.cpp
index a6aa9b461f9..b83a692ab7c 100644
--- a/base/applications/mspaint/canvas.cpp
+++ b/base/applications/mspaint/canvas.cpp
@@ -777,6 +777,16 @@ VOID CCanvasWindow::EndSelectionDrag(POINT ptImage)
Invalidate(FALSE);
}
+VOID CCanvasWindow::MoveSelection(INT xDelta, INT yDelta)
+{
+ if (!selectionModel.m_bShow)
+ return;
+
+ selectionModel.TakeOff();
+ ::OffsetRect(&selectionModel.m_rc, xDelta, yDelta);
+ Invalidate(FALSE);
+}
+
LRESULT CCanvasWindow::OnCtlColorEdit(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL&
bHandled)
{
SetTextColor((HDC)wParam, paletteModel.GetFgColor());
diff --git a/base/applications/mspaint/canvas.h b/base/applications/mspaint/canvas.h
index a201bdc2c7a..53d5fa1acc1 100644
--- a/base/applications/mspaint/canvas.h
+++ b/base/applications/mspaint/canvas.h
@@ -48,6 +48,7 @@ public:
VOID CanvasToImage(POINT& pt, BOOL bZoomed = FALSE);
VOID CanvasToImage(RECT& rc, BOOL bZoomed = FALSE);
VOID GetImageRect(RECT& rc);
+ VOID MoveSelection(INT xDelta, INT yDelta);
protected:
CANVAS_HITTEST m_hitSelection;
diff --git a/base/applications/mspaint/winproc.cpp
b/base/applications/mspaint/winproc.cpp
index 857eedd81ae..087c50fd76e 100644
--- a/base/applications/mspaint/winproc.cpp
+++ b/base/applications/mspaint/winproc.cpp
@@ -493,17 +493,39 @@ LRESULT CMainWindow::OnGetMinMaxInfo(UINT nMsg, WPARAM wParam,
LPARAM lParam, BO
LRESULT CMainWindow::OnKeyDown(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL&
bHandled)
{
- if (wParam == VK_ESCAPE)
+ HWND hwndCapture;
+ switch (wParam)
{
- HWND hwndCapture = GetCapture();
- if (hwndCapture)
- {
- if (canvasWindow.m_hWnd == hwndCapture ||
- fullscreenWindow.m_hWnd == hwndCapture)
+ case VK_ESCAPE:
+ hwndCapture = GetCapture();
+ if (hwndCapture)
+ {
+ if (canvasWindow.m_hWnd == hwndCapture ||
+ fullscreenWindow.m_hWnd == hwndCapture)
+ {
+ SendMessage(hwndCapture, nMsg, wParam, lParam);
+ }
+ }
+ else if (selectionModel.m_bShow)
{
- SendMessage(hwndCapture, nMsg, wParam, lParam);
+ selectionModel.Landing();
+ selectionModel.m_bShow = FALSE;
+ canvasWindow.Invalidate(FALSE);
}
- }
+ break;
+
+ case VK_LEFT:
+ canvasWindow.MoveSelection(-1, 0);
+ break;
+ case VK_RIGHT:
+ canvasWindow.MoveSelection(+1, 0);
+ break;
+ case VK_UP:
+ canvasWindow.MoveSelection(0, -1);
+ break;
+ case VK_DOWN:
+ canvasWindow.MoveSelection(0, +1);
+ break;
}
return 0;
}