Skip to content

Commit 04e0bbc

Browse files
committed
Comparator: right-click menu for Sel Mode and Clear Selection
Right-click now opens a popup menu (like the MFC Viewer mouse menu) with a checkable Sel Mode toggle, the same region-selection capture as the S shortcut, and a Clear Selection item for the synchronized rectangle, enabled only when a selection exists. Previously right-click only cleared the selection and selection mode was reachable solely via the S key.
1 parent 831dc9b commit 04e0bbc

4 files changed

Lines changed: 59 additions & 9 deletions

File tree

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ All notable changes to Q1View are documented here. Releases follow [semantic ver
66

77
## [Unreleased]
88

9+
### Added
10+
- Comparator: right-click now opens a popup menu with a checkable `Sel Mode` toggle (the same region-selection capture as the `S` shortcut) and a `Clear Selection` item for the synchronized rectangle (enabled only when a selection exists), mirroring the Viewer's right-click menu. Previously right-click only cleared the selection and selection mode was reachable solely via the keyboard.
11+
912
---
1013

1114
## [2.6.0] — 2026-06-17

Comparator/ComparatorView.cpp

Lines changed: 51 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ CComparatorView::CComparatorView()
7171
CComparatorView::~CComparatorView()
7272
{
7373
mCsMenu.DestroyMenu();
74+
mMouseMenu.DestroyMenu();
7475

7576
if (mRgbBuf)
7677
_mm_free(mRgbBuf);
@@ -86,6 +87,7 @@ CComparatorView::~CComparatorView()
8687

8788
BEGIN_MESSAGE_MAP(CComparatorView, CScrollView)
8889
ON_COMMAND_RANGE(ID_CS_START, ID_CS_END, CComparatorView::OnCsChange)
90+
ON_COMMAND_RANGE(ID_MOUSEMENU_START, ID_MOUSEMENU_END, CComparatorView::OnMouseMenu)
8991
ON_WM_CREATE()
9092
ON_WM_DROPFILES()
9193
ON_WM_ERASEBKGND()
@@ -97,9 +99,16 @@ BEGIN_MESSAGE_MAP(CComparatorView, CScrollView)
9799
ON_WM_LBUTTONUP()
98100
ON_WM_SETCURSOR()
99101
ON_WM_KEYDOWN()
100-
ON_WM_RBUTTONDOWN()
102+
ON_WM_RBUTTONUP()
101103
END_MESSAGE_MAP()
102104

105+
// Right-click popup items, mirroring the MFC Viewer's mouse menu. The command
106+
// IDs are ID_MOUSEMENU_START + this index.
107+
enum QMouseMenuId {
108+
QMouseMenuSel = 0, // toggle selection mode (same as the 'S' shortcut)
109+
QMouseMenuClear, // clear the synchronized selection rectangle
110+
};
111+
103112
enum {
104113
STATIC_CS_EVENT_ID = 0x1000,
105114

@@ -916,6 +925,12 @@ int CComparatorView::OnCreate(LPCREATESTRUCT lpCreateStruct)
916925
mRcNameQMenu.InflateRect(0, 0, 0, QMENUITEM_IN_MARGIN_H);
917926
mNameQMenu.MoveWindow(&mRcNameQMenu);
918927

928+
// Right-click popup, mirroring the MFC Viewer's mouse menu: a checkable
929+
// "Sel Mode" toggle plus "Clear Selection" for the synchronized rectangle.
930+
mMouseMenu.CreatePopupMenu();
931+
mMouseMenu.AppendMenu(MF_STRING, ID_MOUSEMENU_START + QMouseMenuSel, _T("Sel Mode"));
932+
mMouseMenu.AppendMenu(MF_STRING, ID_MOUSEMENU_START + QMouseMenuClear, _T("Clear Selection"));
933+
919934
return 0;
920935
}
921936

@@ -1405,14 +1420,42 @@ ComparatorPane* CComparatorView::GetPane(CComparatorDoc* pDoc) const
14051420
return nullptr;
14061421
}
14071422

1408-
void CComparatorView::OnRButtonDown(UINT nFlags, CPoint point)
1423+
void CComparatorView::OnRButtonUp(UINT nFlags, CPoint point)
14091424
{
1410-
// Right-click clears the synchronized selection rectangle (issue #74).
1411-
CComparatorDoc* pDoc = GetDocument();
1412-
if (pDoc && (pDoc->mHasSelection || pDoc->mSelecting)) {
1413-
ClearSelection(pDoc);
1414-
return;
1425+
// Right-click popup, like the MFC Viewer: toggle selection mode and clear the
1426+
// synchronized rectangle (issue #74). Esc also clears. The check/enable state
1427+
// is refreshed from the document each time the menu opens.
1428+
CComparatorDoc *pDoc = GetDocument();
1429+
if (pDoc) {
1430+
mMouseMenu.CheckMenuItem(ID_MOUSEMENU_START + QMouseMenuSel,
1431+
MF_BYCOMMAND | (pDoc->mSelMode ? MF_CHECKED : MF_UNCHECKED));
1432+
const bool hasSel = pDoc->mHasSelection || pDoc->mSelecting;
1433+
mMouseMenu.EnableMenuItem(ID_MOUSEMENU_START + QMouseMenuClear,
1434+
MF_BYCOMMAND | (hasSel ? MF_ENABLED : (MF_GRAYED | MF_DISABLED)));
1435+
1436+
CPoint screenPoint = point;
1437+
ClientToScreen(&screenPoint);
1438+
mMouseMenu.TrackPopupMenu(TPM_LEFTALIGN | TPM_TOPALIGN | TPM_LEFTBUTTON,
1439+
screenPoint.x, screenPoint.y, this);
14151440
}
14161441

1417-
CScrollView::OnRButtonDown(nFlags, point);
1442+
CScrollView::OnRButtonUp(nFlags, point);
1443+
}
1444+
1445+
void CComparatorView::OnMouseMenu(UINT nID)
1446+
{
1447+
CComparatorDoc *pDoc = GetDocument();
1448+
if (!pDoc)
1449+
return;
1450+
1451+
switch (nID - ID_MOUSEMENU_START) {
1452+
case QMouseMenuSel:
1453+
// Same effect as the 'S' shortcut: left-drag selects instead of panning.
1454+
pDoc->mSelMode = !pDoc->mSelMode;
1455+
pDoc->UpdateAllViews(NULL);
1456+
break;
1457+
case QMouseMenuClear:
1458+
ClearSelection(pDoc);
1459+
break;
1460+
}
14181461
}

Comparator/ComparatorView.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ class CComparatorView : public CScrollView
4747
CRect mRcClose;
4848
bool mCloseHover;
4949
CMenu mCsMenu;
50+
CMenu mMouseMenu; // right-click popup: Sel Mode / Clear Selection
5051
CQMenuItem mNameQMenu;
5152
CQMenuItem mCsQMenu;
5253
bool mProcessing;
@@ -102,7 +103,8 @@ class CComparatorView : public CScrollView
102103
afx_msg BOOL OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message);
103104
afx_msg void OnCsChange(UINT nID);
104105
afx_msg void OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags);
105-
afx_msg void OnRButtonDown(UINT nFlags, CPoint point);
106+
afx_msg void OnRButtonUp(UINT nFlags, CPoint point);
107+
afx_msg void OnMouseMenu(UINT nID);
106108
};
107109

108110
#ifndef _DEBUG // debug version in ComparatorView.cpp

Comparator/Resource.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
#define ID_VIEWS_END 0x74ff
2323
#define ID_OPTIONS_START 0x7500
2424
#define ID_OPTIONS_END 0x75ff
25+
#define ID_MOUSEMENU_START 0x7600
26+
#define ID_MOUSEMENU_END 0x76ff
2527
#define ID_MAGNIFY 32771
2628

2729
// Next default values for new objects

0 commit comments

Comments
 (0)