https://git.reactos.org/?p=reactos.git;a=commitdiff;h=79b030219ff42c1b9df0bcfa54bd4c6aab338b52

commit 79b030219ff42c1b9df0bcfa54bd4c6aab338b52
Author:     Katayama Hirofumi MZ <[email protected]>
AuthorDate: Wed Nov 20 20:37:57 2019 +0900
Commit:     GitHub <[email protected]>
CommitDate: Wed Nov 20 20:37:57 2019 +0900

    [SHELL32] Improve icon selection upon right click (#2063)
    
    If the Right-Clicked item is not being selected, then reset the selection 
and select the Right-Clicked item. CORE-16519
---
 dll/win32/shell32/CDefView.cpp | 23 ++++++++++++++++++-----
 1 file changed, 18 insertions(+), 5 deletions(-)

diff --git a/dll/win32/shell32/CDefView.cpp b/dll/win32/shell32/CDefView.cpp
index 9fd104025a5..9dc6bc98110 100644
--- a/dll/win32/shell32/CDefView.cpp
+++ b/dll/win32/shell32/CDefView.cpp
@@ -1426,6 +1426,24 @@ LRESULT CDefView::OnContextMenu(UINT uMsg, WPARAM 
wParam, LPARAM lParam, BOOL &b
     if (!m_hContextMenu) 
         return E_FAIL;
 
+    if (lParam != ~0)   // unless app key (menu key) was pressed
+    {
+        x = GET_X_LPARAM(lParam);
+        y = GET_Y_LPARAM(lParam);
+
+        LV_HITTESTINFO hittest = { { x, y } };
+        ScreenToClient(&hittest.pt);
+        m_ListView.HitTest(&hittest);
+
+        // Right-Clicked item is selected? If selected, no selection change.
+        // If not selected, then reset the selection and select the item.
+        if ((hittest.flags & LVHT_ONITEM) &&
+            m_ListView.GetItemState(hittest.iItem, LVIS_SELECTED) != 
LVIS_SELECTED)
+        {
+            SelectItem(hittest.iItem, SVSI_SELECT | SVSI_DESELECTOTHERS | 
SVSI_ENSUREVISIBLE);
+        }
+    }
+
     m_cidl = m_ListView.GetSelectedCount();
 
     hResult = GetItemObject( m_cidl ? SVGIO_SELECTION : SVGIO_BACKGROUND, 
IID_PPV_ARG(IContextMenu, &m_pCM));
@@ -1472,11 +1490,6 @@ LRESULT CDefView::OnContextMenu(UINT uMsg, WPARAM 
wParam, LPARAM lParam, BOOL &b
         x = pt.x;
         y = pt.y;
     }
-    else
-    {
-        x = GET_X_LPARAM(lParam);
-        y = GET_Y_LPARAM(lParam);
-    }
 
     uCommand = TrackPopupMenu(m_hContextMenu,
                               TPM_LEFTALIGN | TPM_RETURNCMD | TPM_LEFTBUTTON | 
TPM_RIGHTBUTTON,

Reply via email to