Previously we would always show a menu on the focused item, but
this should only be done when it is also selected.
/* There is no position requested, so try to find one */
if (lParam == ~0)
{
/* There is no position requested, so try to find one */
if (lParam == ~0)
{
+ HWND hFocus = ::GetFocus();
+ int lvIndex = -1;
- /* Do we have a focused item, */
- if ((lvIndex = m_ListView.GetNextItem(-1, LVIS_FOCUSED)) < 0)
+ if (hFocus == m_ListView.m_hWnd || m_ListView.IsChild(hFocus))
- /* or a selected item? */
- lvIndex = m_ListView.GetNextItem(-1, LVIS_SELECTED);
+ /* Is there an item focused and selected? */
+ lvIndex = m_ListView.GetNextItem(-1, LVIS_SELECTED|LVIS_FOCUSED);
+ /* If not, find the first selected item */
+ if (lvIndex < 0)
+ lvIndex = m_ListView.GetNextItem(-1, LVIS_SELECTED);
/* We got something */
if (lvIndex > -1)
{
/* We got something */
if (lvIndex > -1)
{