Avoid generating wxEVT_MENU_OPEN and CLOSE for disabled menus in wxMSW.
Check if a top level menu is disabled and consume WM_[UN]INITMENUPOPUP that Windows still generates for it when it's clicked for some reason. Closes #2168. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@77657 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -990,6 +990,47 @@ WXLRESULT wxFrame::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lPara
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
#endif // !__WXMICROWIN__
|
#endif // !__WXMICROWIN__
|
||||||
|
|
||||||
|
#if wxUSE_MENUS
|
||||||
|
case WM_INITMENUPOPUP:
|
||||||
|
{
|
||||||
|
wxMenuBar* const bar = GetMenuBar();
|
||||||
|
if ( bar && !bar->IsEnabledTop(LOWORD(lParam)) )
|
||||||
|
{
|
||||||
|
// Skip sending of wxEVT_MENU_OPEN in the base class
|
||||||
|
// MSWWindowProc() for disabled top level menus.
|
||||||
|
return MSWDefWindowProc(message, wParam, lParam);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case WM_UNINITMENUPOPUP:
|
||||||
|
{
|
||||||
|
wxMenuBar* const bar = GetMenuBar();
|
||||||
|
if ( !bar )
|
||||||
|
break;
|
||||||
|
|
||||||
|
// Unlike in WM_INITMENUPOPUP above, we don't have the position
|
||||||
|
// of the menu in the message itself, so find it ourselves.
|
||||||
|
const HMENU hmenu = (HMENU)wParam;
|
||||||
|
|
||||||
|
const size_t count = bar->GetMenuCount();
|
||||||
|
for ( size_t n = 0; n < count; n++ )
|
||||||
|
{
|
||||||
|
wxMenu* const menu = bar->GetMenu(n);
|
||||||
|
if ( GetHmenuOf(menu) == hmenu )
|
||||||
|
{
|
||||||
|
if ( !bar->IsEnabledTop(n) )
|
||||||
|
{
|
||||||
|
// If we skipped sending wxEVT_MENU_OPEN, don't
|
||||||
|
// send wxEVT_MENU_CLOSE neither.
|
||||||
|
return MSWDefWindowProc(message, wParam, lParam);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
#endif // wxUSE_MENUS
|
||||||
}
|
}
|
||||||
#if wxUSE_TASKBARBUTTON
|
#if wxUSE_TASKBARBUTTON
|
||||||
if ( message == wxMsgTaskbarButtonCreated )
|
if ( message == wxMsgTaskbarButtonCreated )
|
||||||
|
Reference in New Issue
Block a user