From 10816efb2cb6561a227a87de6d5f8b5750c2705d Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Fri, 18 May 2007 17:03:38 +0000 Subject: [PATCH] added virtual wxFrame::FindItemInMenuBar(): overriding it in wxMDIParentFrame allows to look for the items in the active child when giving help for the current menu item git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@46114 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/frame.h | 9 +++++++-- include/wx/msw/mdi.h | 3 +++ src/common/framecmn.cpp | 22 +++++++++++++--------- src/msw/mdi.cpp | 29 +++++++++++------------------ 4 files changed, 34 insertions(+), 29 deletions(-) diff --git a/include/wx/frame.h b/include/wx/frame.h index c9bf79c946..2d3a8988c9 100644 --- a/include/wx/frame.h +++ b/include/wx/frame.h @@ -81,6 +81,11 @@ public: #if wxUSE_MENUS virtual void SetMenuBar(wxMenuBar *menubar); virtual wxMenuBar *GetMenuBar() const { return m_frameMenuBar; } + + // find the item by id in the frame menu bar: this is an internal function + // and exists mainly in order to be overridden in the MDI parent frame + // which also looks at its active child menu bar + virtual const wxMenuItem *FindItemInMenuBar(int menuId) const; #endif // wxUSE_MENUS // process menu command: returns true if processed @@ -212,8 +217,8 @@ protected: virtual void PositionStatusBar() { } // show the help string for the given menu item using DoGiveHelp() if the - // given item does have a help string, return false if there is no help for - // such item + // given item does have a help string (as determined by FindInMenuBar()), + // return false if there is no help for such item bool ShowMenuHelp(int helpid); wxStatusBar *m_frameStatusBar; diff --git a/include/wx/msw/mdi.h b/include/wx/msw/mdi.h index cd0b21b28d..3b9c41387e 100644 --- a/include/wx/msw/mdi.h +++ b/include/wx/msw/mdi.h @@ -92,6 +92,9 @@ public: virtual WXLRESULT MSWDefWindowProc(WXUINT, WXWPARAM, WXLPARAM); virtual bool MSWTranslateMessage(WXMSG* msg); + // override wxFrameBase function to also look in the active child menu bar + virtual const wxMenuItem *FindItemInMenuBar(int menuId) const; + protected: #if wxUSE_MENUS_NATIVE virtual void InternalSetMenuBar(); diff --git a/src/common/framecmn.cpp b/src/common/framecmn.cpp index 0c964bb6f4..e93d1010e1 100644 --- a/src/common/framecmn.cpp +++ b/src/common/framecmn.cpp @@ -356,15 +356,12 @@ bool wxFrameBase::ShowMenuHelp(int menuId) wxString helpString; if ( menuId != wxID_SEPARATOR && menuId != -3 /* wxID_TITLE */ ) { - wxMenuBar *menuBar = GetMenuBar(); - if ( menuBar ) - { - // it's ok if we don't find the item because it might belong - // to the popup menu - wxMenuItem *item = menuBar->FindItem(menuId); - if ( item ) - helpString = item->GetHelp(); - } + const wxMenuItem * const item = FindItemInMenuBar(menuId); + if ( item ) + helpString = item->GetHelp(); + + // notice that it's ok if we don't find the item because it might + // belong to the popup menu, so don't assert here } DoGiveHelp(helpString, true); @@ -560,4 +557,11 @@ void wxFrameBase::SetMenuBar(wxMenuBar *menubar) this->AttachMenuBar(menubar); } +const wxMenuItem *wxFrameBase::FindItemInMenuBar(int menuId) const +{ + const wxMenuBar * const menuBar = GetMenuBar(); + + return menuBar ? menuBar->FindItem(menuId) : NULL; +} + #endif // wxUSE_MENUS diff --git a/src/msw/mdi.cpp b/src/msw/mdi.cpp index 231ab43b1f..881f48fce9 100644 --- a/src/msw/mdi.cpp +++ b/src/msw/mdi.cpp @@ -315,6 +315,17 @@ void wxMDIParentFrame::DoMenuUpdates(wxMenu* menu) } } +const wxMenuItem *wxMDIParentFrame::FindItemInMenuBar(int menuId) const +{ + const wxMenuItem *item = wxFrame::FindItemInMenuBar(menuId); + if ( !item && m_currentChild ) + { + item = m_currentChild->FindItemInMenuBar(menuId); + } + + return item; +} + void wxMDIParentFrame::UpdateClientSize() { if ( GetClientWindow() ) @@ -475,24 +486,6 @@ WXLRESULT wxMDIParentFrame::MSWWindowProc(WXUINT message, rc = true; break; - case WM_MENUSELECT: - { - WXWORD item, flags; - WXHMENU hmenu; - UnpackMenuSelect(wParam, lParam, &item, &flags, &hmenu); - - if ( m_parentFrameActive ) - { - processed = HandleMenuSelect(item, flags, hmenu); - } - else if (m_currentChild) - { - processed = m_currentChild-> - HandleMenuSelect(item, flags, hmenu); - } - } - break; - case WM_SIZE: // though we don't (usually) resize the MDI client to exactly fit the // client area we need to pass this one to DefFrameProc to allow the children to show -- 2.45.2