]> git.saurik.com Git - wxWidgets.git/commitdiff
Fix restoring the status bar help message after closing MSW menu from keyboard.
authorVadim Zeitlin <vadim@wxwidgets.org>
Wed, 10 Jul 2013 12:28:06 +0000 (12:28 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Wed, 10 Jul 2013 12:28:06 +0000 (12:28 +0000)
Add a hack to ignore WM_MENUSELECT messages we get for the top level menu
items: we must not clear the status bar help message when we get those because
it had just been restored to the original message that was there before the
menu was opened from the base class wxEVT_MENU_CLOSE handler, but this message
comes after it when keyboard is used to close the menu.

Closes #15315.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@74468 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/msw/toplevel.h
src/msw/toplevel.cpp

index 690536dd82cabc8c13bbf6f3c7d04e673a98f1ba..d3ad4a1edc00f46c470a498f699407fa974acd98 100644 (file)
@@ -252,6 +252,10 @@ private:
     // MSWGetSystemMenu(). Owned by this window.
     wxMenu *m_menuSystem;
 
+    // The number of currently opened menus: 0 initially, 1 when a top level
+    // menu is opened, 2 when its submenu is opened and so on.
+    int m_menuDepth;
+
     DECLARE_EVENT_TABLE()
     wxDECLARE_NO_COPY_CLASS(wxTopLevelWindowMSW);
 };
index 82b7c4d13c212bb8861eae51418c7e55c2e1c13d..1a77562f51d378f73def7c6aaed056392e5dd95d 100644 (file)
@@ -159,6 +159,7 @@ void wxTopLevelWindowMSW::Init()
 #endif
 
     m_menuSystem = NULL;
+    m_menuDepth = 0;
 }
 
 WXDWORD wxTopLevelWindowMSW::MSWGetStyle(long style, WXDWORD *exflags) const
@@ -1487,6 +1488,17 @@ wxTopLevelWindowMSW::HandleMenuSelect(WXWORD nItem, WXWORD flags, WXHMENU hMenu)
     if ( !hMenu && flags == 0xffff )
         return false;
 
+    // Unfortunately we also need to ignore another message which is sent after
+    // closing the currently active submenu of the menu bar by pressing Escape:
+    // in this case we get WM_UNINITMENUPOPUP, from which we generate
+    // wxEVT_MENU_CLOSE, and _then_ we get WM_MENUSELECT for the top level menu
+    // from which we overwrite the help string just restored by OnMenuClose()
+    // handler in wxFrameBase. To prevent this from happening we discard these
+    // messages but only in the case it's really the top level menu as we still
+    // need to clear the help string when a submenu is selected in a menu.
+    if ( flags == (MF_POPUP | MF_HILITE) && !m_menuDepth )
+        return false;
+
     // sign extend to int from unsigned short we get from Windows
     int item = (signed short)nItem;
 
@@ -1515,6 +1527,25 @@ wxTopLevelWindowMSW::HandleMenuSelect(WXWORD nItem, WXWORD flags, WXHMENU hMenu)
 bool
 wxTopLevelWindowMSW::DoSendMenuOpenCloseEvent(wxEventType evtType, wxMenu* menu, bool popup)
 {
+    // Update the menu depth when dealing with the top level menus.
+    if ( !popup )
+    {
+        if ( evtType == wxEVT_MENU_OPEN )
+        {
+            m_menuDepth++;
+        }
+        else if ( evtType == wxEVT_MENU_CLOSE )
+        {
+            wxASSERT_MSG( m_menuDepth > 0, wxS("No open menus?") );
+
+            m_menuDepth--;
+        }
+        else
+        {
+            wxFAIL_MSG( wxS("Unexpected menu event type") );
+        }
+    }
+
     wxMenuEvent event(evtType, popup ? wxID_ANY : 0, menu);
     event.SetEventObject(menu);