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
This commit is contained in:
Stefan Csomor
2002-12-20 14:16:16 +00:00
parent 8979386806
commit a48820e9f4
2 changed files with 64 additions and 16 deletions

View File

@@ -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)
{

View File

@@ -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)
{