[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
This commit is contained in:
Katayama Hirofumi MZ 2019-11-20 20:37:57 +09:00 committed by GitHub
parent 871d322f92
commit 79b030219f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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,