From a48820e9f4b4de67963267d3ace6735642c5a8a2 Mon Sep 17 00:00:00 2001 From: Stefan Csomor Date: Fri, 20 Dec 2002 14:16:16 +0000 Subject: [PATCH] corrected setting invoking windows for wxMenus added after AttachMenuBar has been issued already. removal of Apple Help Menu Items occurs now also when the new menubar has no help menu itself git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_4_BRANCH@18372 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/mac/carbon/menu.cpp | 40 ++++++++++++++++++++++++++++++++-------- src/mac/menu.cpp | 40 ++++++++++++++++++++++++++++++++-------- 2 files changed, 64 insertions(+), 16 deletions(-) diff --git a/src/mac/carbon/menu.cpp b/src/mac/carbon/menu.cpp index e81e6de61a..d0ba511b85 100644 --- a/src/mac/carbon/menu.cpp +++ b/src/mac/carbon/menu.cpp @@ -51,7 +51,8 @@ const short kwxMacAppleMenuId = 1 ; // ============================================================================ // implementation // ============================================================================ - +static void wxMenubarUnsetInvokingWindow( wxMenu *menu ) ; +static void wxMenubarSetInvokingWindow( wxMenu *menu, wxWindow *win ); // Menus @@ -194,6 +195,12 @@ bool wxMenu::DoInsertOrAppend(wxMenuItem *pItem, size_t pos) { UMAInsertSubMenuItem(MAC_WXHMENU(m_hMenu), label , pos, pSubMenu->m_macMenuId); } + + // if adding a submenu to a menu already existing in the menu bar, we + // must set invoking window to allow processing events from this + // submenu + if ( m_invokingWindow ) + wxMenubarSetInvokingWindow(pSubMenu, m_invokingWindow); } else { @@ -457,6 +464,7 @@ void wxMenuBar::Init() { m_eventHandler = this; m_menuBarFrame = NULL; + m_invokingWindow = (wxWindow*) NULL; } wxMenuBar::wxMenuBar() @@ -557,6 +565,21 @@ void wxMenuBar::MacInstallMenuBar() } #endif + // clean-up the help menu before adding new items + MenuHandle mh = NULL ; + if ( UMAGetHelpMenu( &mh , &firstUserHelpMenuItem) == noErr ) + { + for ( int i = CountMenuItems( mh ) ; i >= firstUserHelpMenuItem ; --i ) + { + DeleteMenuItem( mh , i ) ; + } + } + else + { + mh = NULL ; + } + + for (size_t i = 0; i < m_menus.GetCount(); i++) { Str255 label; @@ -567,16 +590,10 @@ void wxMenuBar::MacInstallMenuBar() if( m_titles[i] == "?" || m_titles[i] == "&?" || m_titles[i] == wxApp::s_macHelpMenuTitleName ) { - MenuHandle mh = NULL ; - if ( UMAGetHelpMenu( &mh , &firstUserHelpMenuItem) != noErr ) + if ( mh == NULL ) { continue ; } - - for ( int i = CountMenuItems( mh ) ; i >= firstUserHelpMenuItem ; --i ) - { - DeleteMenuItem( mh , i ) ; - } for (pos = 0 , node = menu->GetMenuItems().First(); node; node = node->Next(), pos++) { @@ -862,6 +879,11 @@ bool wxMenuBar::Append(wxMenu *menu, const wxString& title) Refresh(); } + // m_invokingWindow is set after wxFrame::SetMenuBar(). This call enables + // adding menu later on. + if (m_invokingWindow) + wxMenubarSetInvokingWindow( menu, m_invokingWindow ); + return TRUE; } @@ -895,6 +917,7 @@ static void wxMenubarSetInvokingWindow( wxMenu *menu, wxWindow *win ) void wxMenuBar::UnsetInvokingWindow() { + m_invokingWindow = (wxWindow*) NULL; wxMenuList::Node *node = m_menus.GetFirst(); while (node) { @@ -906,6 +929,7 @@ void wxMenuBar::UnsetInvokingWindow() void wxMenuBar::SetInvokingWindow(wxFrame *frame) { + m_invokingWindow = frame; wxMenuList::Node *node = m_menus.GetFirst(); while (node) { diff --git a/src/mac/menu.cpp b/src/mac/menu.cpp index e81e6de61a..d0ba511b85 100644 --- a/src/mac/menu.cpp +++ b/src/mac/menu.cpp @@ -51,7 +51,8 @@ const short kwxMacAppleMenuId = 1 ; // ============================================================================ // implementation // ============================================================================ - +static void wxMenubarUnsetInvokingWindow( wxMenu *menu ) ; +static void wxMenubarSetInvokingWindow( wxMenu *menu, wxWindow *win ); // Menus @@ -194,6 +195,12 @@ bool wxMenu::DoInsertOrAppend(wxMenuItem *pItem, size_t pos) { UMAInsertSubMenuItem(MAC_WXHMENU(m_hMenu), label , pos, pSubMenu->m_macMenuId); } + + // if adding a submenu to a menu already existing in the menu bar, we + // must set invoking window to allow processing events from this + // submenu + if ( m_invokingWindow ) + wxMenubarSetInvokingWindow(pSubMenu, m_invokingWindow); } else { @@ -457,6 +464,7 @@ void wxMenuBar::Init() { m_eventHandler = this; m_menuBarFrame = NULL; + m_invokingWindow = (wxWindow*) NULL; } wxMenuBar::wxMenuBar() @@ -557,6 +565,21 @@ void wxMenuBar::MacInstallMenuBar() } #endif + // clean-up the help menu before adding new items + MenuHandle mh = NULL ; + if ( UMAGetHelpMenu( &mh , &firstUserHelpMenuItem) == noErr ) + { + for ( int i = CountMenuItems( mh ) ; i >= firstUserHelpMenuItem ; --i ) + { + DeleteMenuItem( mh , i ) ; + } + } + else + { + mh = NULL ; + } + + for (size_t i = 0; i < m_menus.GetCount(); i++) { Str255 label; @@ -567,16 +590,10 @@ void wxMenuBar::MacInstallMenuBar() if( m_titles[i] == "?" || m_titles[i] == "&?" || m_titles[i] == wxApp::s_macHelpMenuTitleName ) { - MenuHandle mh = NULL ; - if ( UMAGetHelpMenu( &mh , &firstUserHelpMenuItem) != noErr ) + if ( mh == NULL ) { continue ; } - - for ( int i = CountMenuItems( mh ) ; i >= firstUserHelpMenuItem ; --i ) - { - DeleteMenuItem( mh , i ) ; - } for (pos = 0 , node = menu->GetMenuItems().First(); node; node = node->Next(), pos++) { @@ -862,6 +879,11 @@ bool wxMenuBar::Append(wxMenu *menu, const wxString& title) Refresh(); } + // m_invokingWindow is set after wxFrame::SetMenuBar(). This call enables + // adding menu later on. + if (m_invokingWindow) + wxMenubarSetInvokingWindow( menu, m_invokingWindow ); + return TRUE; } @@ -895,6 +917,7 @@ static void wxMenubarSetInvokingWindow( wxMenu *menu, wxWindow *win ) void wxMenuBar::UnsetInvokingWindow() { + m_invokingWindow = (wxWindow*) NULL; wxMenuList::Node *node = m_menus.GetFirst(); while (node) { @@ -906,6 +929,7 @@ void wxMenuBar::UnsetInvokingWindow() void wxMenuBar::SetInvokingWindow(wxFrame *frame) { + m_invokingWindow = frame; wxMenuList::Node *node = m_menus.GetFirst(); while (node) {