Skip to content

Commit f49919c

Browse files
authored
[MSPAINT] Simplify canvas mouse message handling (reactos#5803)
- Unify some mouse message handlers of CCanvasWindow. - Add CCanvasWindow::m_nMouseDownMsg member. CORE-19094
1 parent 8f1eb03 commit f49919c

File tree

2 files changed

+26
-53
lines changed

2 files changed

+26
-53
lines changed

base/applications/mspaint/canvas.cpp

Lines changed: 16 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -310,10 +310,13 @@ LRESULT CCanvasWindow::OnVScroll(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL&
310310
return 0;
311311
}
312312

313-
LRESULT CCanvasWindow::OnLRButtonDown(BOOL bLeftButton, UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
313+
LRESULT CCanvasWindow::OnButtonDown(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
314314
{
315315
POINT pt = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) };
316316

317+
m_nMouseDownMsg = nMsg;
318+
BOOL bLeftButton = (m_nMouseDownMsg == WM_LBUTTONDOWN);
319+
317320
HITTEST hitSelection = SelectionHitTest(pt);
318321
if (hitSelection != HIT_NONE)
319322
{
@@ -333,7 +336,7 @@ LRESULT CCanvasWindow::OnLRButtonDown(BOOL bLeftButton, UINT nMsg, WPARAM wParam
333336
}
334337
else
335338
{
336-
canvasWindow.ClientToScreen(&pt);
339+
ClientToScreen(&pt);
337340
mainWindow.TrackPopupMenu(pt, 0);
338341
}
339342
return 0;
@@ -347,13 +350,13 @@ LRESULT CCanvasWindow::OnLRButtonDown(BOOL bLeftButton, UINT nMsg, WPARAM wParam
347350
case TOOL_BEZIER:
348351
case TOOL_SHAPE:
349352
toolsModel.OnCancelDraw();
350-
canvasWindow.Invalidate();
353+
Invalidate();
351354
break;
352355

353356
case TOOL_FREESEL:
354357
case TOOL_RECTSEL:
355358
toolsModel.OnFinishDraw();
356-
canvasWindow.Invalidate();
359+
Invalidate();
357360
break;
358361

359362
default:
@@ -386,40 +389,21 @@ LRESULT CCanvasWindow::OnLRButtonDown(BOOL bLeftButton, UINT nMsg, WPARAM wParam
386389
return 0;
387390
}
388391

389-
LRESULT CCanvasWindow::OnLButtonDown(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
390-
{
391-
return OnLRButtonDown(TRUE, nMsg, wParam, lParam, bHandled);
392-
}
393-
394-
LRESULT CCanvasWindow::OnRButtonDown(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
395-
{
396-
return OnLRButtonDown(FALSE, nMsg, wParam, lParam, bHandled);
397-
}
398-
399-
LRESULT CCanvasWindow::OnLRButtonDblClk(BOOL bLeftButton, UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
392+
LRESULT CCanvasWindow::OnButtonDblClk(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
400393
{
401394
POINT pt = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) };
402395
CanvasToImage(pt);
403396

404397
m_drawing = FALSE;
405-
ReleaseCapture();
398+
::ReleaseCapture();
399+
m_nMouseDownMsg = 0;
406400

407-
toolsModel.OnButtonDown(bLeftButton, pt.x, pt.y, TRUE);
401+
toolsModel.OnButtonDown(nMsg == WM_LBUTTONDBLCLK, pt.x, pt.y, TRUE);
408402
toolsModel.resetTool();
409403
Invalidate(FALSE);
410404
return 0;
411405
}
412406

413-
LRESULT CCanvasWindow::OnLButtonDblClk(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
414-
{
415-
return OnLRButtonDblClk(TRUE, nMsg, wParam, lParam, bHandled);
416-
}
417-
418-
LRESULT CCanvasWindow::OnRButtonDblClk(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
419-
{
420-
return OnLRButtonDblClk(FALSE, nMsg, wParam, lParam, bHandled);
421-
}
422-
423407
LRESULT CCanvasWindow::OnMouseMove(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
424408
{
425409
POINT pt = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) };
@@ -612,13 +596,16 @@ LRESULT CCanvasWindow::OnMouseMove(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL
612596
return 0;
613597
}
614598

615-
LRESULT CCanvasWindow::OnLRButtonUp(BOOL bLeftButton, UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
599+
LRESULT CCanvasWindow::OnButtonUp(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
616600
{
617601
POINT pt = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) };
618602
CanvasToImage(pt);
619603

620604
::ReleaseCapture();
621605

606+
BOOL bLeftButton = (m_nMouseDownMsg == WM_LBUTTONDOWN);
607+
m_nMouseDownMsg = 0;
608+
622609
if (m_drawing)
623610
{
624611
m_drawing = FALSE;
@@ -680,16 +667,6 @@ LRESULT CCanvasWindow::OnLRButtonUp(BOOL bLeftButton, UINT nMsg, WPARAM wParam,
680667
return 0;
681668
}
682669

683-
LRESULT CCanvasWindow::OnLButtonUp(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
684-
{
685-
return OnLRButtonUp(TRUE, nMsg, wParam, lParam, bHandled);
686-
}
687-
688-
LRESULT CCanvasWindow::OnRButtonUp(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
689-
{
690-
return OnLRButtonUp(FALSE, nMsg, wParam, lParam, bHandled);
691-
}
692-
693670
LRESULT CCanvasWindow::OnSetCursor(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
694671
{
695672
if (CWaitCursor::IsWaiting())
@@ -760,6 +737,7 @@ LRESULT CCanvasWindow::OnKeyDown(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL&
760737
{
761738
// Cancel dragging
762739
::ReleaseCapture();
740+
m_nMouseDownMsg = 0;
763741
m_hitCanvasSizeBox = HIT_NONE;
764742
::SetRectEmpty(&m_rcResizing);
765743
Invalidate(TRUE);

base/applications/mspaint/canvas.h

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@ class CCanvasWindow : public CWindowImpl<CCanvasWindow>
2020
MESSAGE_HANDLER(WM_HSCROLL, OnHScroll)
2121
MESSAGE_HANDLER(WM_VSCROLL, OnVScroll)
2222
MESSAGE_HANDLER(WM_ERASEBKGND, OnEraseBkgnd)
23-
MESSAGE_HANDLER(WM_LBUTTONDOWN, OnLButtonDown)
24-
MESSAGE_HANDLER(WM_RBUTTONDOWN, OnRButtonDown)
25-
MESSAGE_HANDLER(WM_LBUTTONDBLCLK, OnLButtonDblClk)
26-
MESSAGE_HANDLER(WM_RBUTTONDBLCLK, OnRButtonDblClk)
23+
MESSAGE_HANDLER(WM_LBUTTONDOWN, OnButtonDown)
24+
MESSAGE_HANDLER(WM_RBUTTONDOWN, OnButtonDown)
25+
MESSAGE_HANDLER(WM_LBUTTONDBLCLK, OnButtonDblClk)
26+
MESSAGE_HANDLER(WM_RBUTTONDBLCLK, OnButtonDblClk)
2727
MESSAGE_HANDLER(WM_KEYDOWN, OnKeyDown)
28-
MESSAGE_HANDLER(WM_LBUTTONUP, OnLButtonUp)
29-
MESSAGE_HANDLER(WM_RBUTTONUP, OnRButtonUp)
28+
MESSAGE_HANDLER(WM_LBUTTONUP, OnButtonUp)
29+
MESSAGE_HANDLER(WM_RBUTTONUP, OnButtonUp)
3030
MESSAGE_HANDLER(WM_SETCURSOR, OnSetCursor)
3131
MESSAGE_HANDLER(WM_MOUSEWHEEL, OnMouseWheel)
3232
MESSAGE_HANDLER(WM_CANCELMODE, OnCancelMode)
@@ -76,22 +76,17 @@ class CCanvasWindow : public CWindowImpl<CCanvasWindow>
7676
LRESULT OnVScroll(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
7777
LRESULT OnEraseBkgnd(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
7878
LRESULT OnPaint(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
79-
LRESULT OnLButtonDown(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
80-
LRESULT OnRButtonDown(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
81-
LRESULT OnLButtonDblClk(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
82-
LRESULT OnRButtonDblClk(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
8379
LRESULT OnMouseMove(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
8480
LRESULT OnKeyDown(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
85-
LRESULT OnLButtonUp(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
86-
LRESULT OnRButtonUp(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
8781
LRESULT OnSetCursor(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
8882
LRESULT OnMouseWheel(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
8983
LRESULT OnCancelMode(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
9084
LRESULT OnCaptureChanged(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
9185
LRESULT OnCtlColorEdit(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
9286
LRESULT OnPaletteModelColorChanged(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
9387

94-
LRESULT OnLRButtonDown(BOOL bLeftButton, UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
95-
LRESULT OnLRButtonDblClk(BOOL bLeftButton, UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
96-
LRESULT OnLRButtonUp(BOOL bLeftButton, UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
88+
UINT m_nMouseDownMsg = 0;
89+
LRESULT OnButtonDown(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
90+
LRESULT OnButtonDblClk(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
91+
LRESULT OnButtonUp(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
9792
};

0 commit comments

Comments
 (0)