Move menu messages handling from wxFrame to wxTLW in wxMSW.

This allows to generate the menu open/close/highlight events correctly for the
popup menus used in the dialogs.

Extend the menu sample with a test using such menus.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@73562 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2013-02-24 13:48:13 +00:00
parent 823e18c7bc
commit 95316a3f24
8 changed files with 313 additions and 117 deletions

View File

@@ -429,6 +429,13 @@ void wxFrame::InternalSetMenuBar()
#endif // wxUSE_MENUS_NATIVE
#if wxUSE_MENUS
wxMenu* wxFrame::MSWFindMenuFromHMENU(WXHMENU hMenu)
{
return GetMenuBar() ? GetMenuBar()->MSWGetMenu(hMenu) : NULL;
}
#endif // wxUSE_MENUS
// Responds to colour changes, and passes event on to children.
void wxFrame::OnSysColourChanged(wxSysColourChangedEvent& event)
{
@@ -824,72 +831,6 @@ bool wxFrame::HandleCommand(WXWORD id, WXWORD cmd, WXHWND control)
return wxFrameBase::HandleCommand(id, cmd, control);;
}
#if wxUSE_MENUS
bool
wxFrame::HandleMenuSelect(WXWORD nItem, WXWORD flags, WXHMENU WXUNUSED(hMenu))
{
// sign extend to int from unsigned short we get from Windows
int item = (signed short)nItem;
// WM_MENUSELECT is generated for both normal items and menus, including
// the top level menus of the menu bar, which can't be represented using
// any valid identifier in wxMenuEvent so use an otherwise unused value for
// them
if ( flags & (MF_POPUP | MF_SEPARATOR) )
item = wxID_NONE;
wxMenuEvent event(wxEVT_MENU_HIGHLIGHT, item);
event.SetEventObject(this);
if ( HandleWindowEvent(event) )
return true;
// by default, i.e. if the event wasn't handled above, clear the status bar
// text when an item which can't have any associated help string in wx API
// is selected
if ( item == wxID_NONE )
DoGiveHelp(wxEmptyString, true);
return false;
}
bool
wxFrame::DoSendMenuOpenCloseEvent(wxEventType evtType, wxMenu* menu, bool popup)
{
wxMenuEvent event(evtType, popup ? wxID_ANY : 0, menu);
event.SetEventObject(menu);
return HandleWindowEvent(event);
}
bool wxFrame::HandleExitMenuLoop(WXWORD isPopup)
{
return DoSendMenuOpenCloseEvent(wxEVT_MENU_CLOSE,
isPopup ? wxCurrentPopupMenu : NULL,
isPopup != 0);
}
bool wxFrame::HandleMenuPopup(wxEventType evtType, WXHMENU hMenu)
{
bool isPopup = false;
wxMenu* menu = NULL;
if ( wxCurrentPopupMenu && wxCurrentPopupMenu->GetHMenu() == hMenu )
{
menu = wxCurrentPopupMenu;
isPopup = true;
}
else if ( GetMenuBar() )
{
menu = GetMenuBar()->MSWGetMenu(hMenu);
}
return DoSendMenuOpenCloseEvent(evtType, menu, isPopup);
}
#endif // wxUSE_MENUS
// ---------------------------------------------------------------------------
// the window proc for wxFrame
// ---------------------------------------------------------------------------
@@ -930,36 +871,6 @@ WXLRESULT wxFrame::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lPara
break;
#if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
#if wxUSE_MENUS
case WM_INITMENUPOPUP:
processed = HandleMenuPopup(wxEVT_MENU_OPEN, (WXHMENU)wParam);
break;
case WM_MENUSELECT:
{
WXWORD item, flags;
WXHMENU hmenu;
UnpackMenuSelect(wParam, lParam, &item, &flags, &hmenu);
processed = HandleMenuSelect(item, flags, hmenu);
}
break;
case WM_EXITMENULOOP:
// Under Windows 98 and 2000 and later we're going to get
// WM_UNINITMENUPOPUP which will be used to generate this event
// with more information (notably the menu that was closed) so we
// only need this one under old Windows systems where the newer
// event is never sent.
if ( wxGetWinVersion() < wxWinVersion_98 )
processed = HandleExitMenuLoop(wParam);
break;
case WM_UNINITMENUPOPUP:
processed = HandleMenuPopup(wxEVT_MENU_CLOSE, (WXHMENU)wParam);
break;
#endif // wxUSE_MENUS
case WM_QUERYDRAGICON:
{
const wxIcon& icon = GetIcon();