X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/262ce38a2af9de50f6efca91463123c75a237ed4..aa13eec58591663854bc68c987578312238cf254:/src/mac/carbon/menu.cpp diff --git a/src/mac/carbon/menu.cpp b/src/mac/carbon/menu.cpp index 37e4141243..841f2815ec 100644 --- a/src/mac/carbon/menu.cpp +++ b/src/mac/carbon/menu.cpp @@ -406,23 +406,64 @@ void wxMenu::MacBeforeDisplay( bool isSubMenu ) { subMenu->MacBeforeDisplay( true ) ; } - else + else // normal item { #if TARGET_CARBON if ( UMAGetSystemVersion() >= 0x1000 ) { - if ( item->GetId() == wxApp::s_macPreferencesMenuItemId || item->GetId() == wxApp::s_macExitMenuItemId) + // what we do here is to hide the special items which are + // shown in the application menu anyhow -- it doesn't make + // sense to show them in their normal place as well + if ( item->GetId() == wxApp::s_macPreferencesMenuItemId || + item->GetId() == wxApp::s_macExitMenuItemId ) { - ChangeMenuItemAttributes( MAC_WXHMENU( GetHMenu() ) , pos + 1, kMenuItemAttrHidden, 0 ); - if ( GetMenuItems().GetCount() == pos + 1 && - previousItem != NULL && - previousItem->IsSeparator() ) + ChangeMenuItemAttributes( MAC_WXHMENU( GetHMenu() ), + pos + 1, kMenuItemAttrHidden, 0 ); + + // also check for a separator which was used just to + // separate this item from the others, so don't leave + // separator at the menu start or end nor 2 consecutive + // separators + wxMenuItemList::Node *nextNode = node->GetNext(); + wxMenuItem *next = nextNode ? nextNode->GetData() : NULL; + + size_t posSeptoHide; + if ( !previousItem && next && next->IsSeparator() ) + { + // next (i.e. second as we must be first) item is + // the separator to hide + wxASSERT_MSG( pos == 0, _T("should be the menu start") ); + posSeptoHide = 2; + } + else if ( GetMenuItems().GetCount() == pos + 1 && + previousItem != NULL && + previousItem->IsSeparator() ) + { + // prev item is a trailing separator we want to hide + posSeptoHide = pos; + } + else if ( previousItem && previousItem->IsSeparator() && + next && next->IsSeparator() ) + { + // two consecutive separators, this is one too many + posSeptoHide = pos; + } + else // no separators to hide { - ChangeMenuItemAttributes( MAC_WXHMENU( GetHMenu() ) , pos , kMenuItemAttrHidden, 0 ); + posSeptoHide = 0; + } + + if ( posSeptoHide ) + { + // hide the separator as well + ChangeMenuItemAttributes( MAC_WXHMENU( GetHMenu() ), + posSeptoHide, + kMenuItemAttrHidden, + 0 ); } } } - #endif + #endif // TARGET_CARBON } previousItem = item ; } @@ -750,6 +791,8 @@ wxMenu *wxMenuBar::Replace(size_t pos, wxMenu *menu, const wxString& title) Refresh(); } + if (m_invokingWindow) + wxMenubarSetInvokingWindow( menu, m_invokingWindow ); return menuOld; } @@ -779,6 +822,8 @@ bool wxMenuBar::Insert(size_t pos, wxMenu *menu, const wxString& title) } Refresh(); } + if (m_invokingWindow) + wxMenubarSetInvokingWindow( menu, m_invokingWindow ); return TRUE; } @@ -826,7 +871,7 @@ bool wxMenuBar::Append(wxMenu *menu, const wxString& title) Refresh(); } - // m_invokingWindow is set after wxFrame::SetMenuBar(). This call enables + // m_invokingWindow is set after wxFrame::SetMenuBar(). This call enables // adding menu later on. if (m_invokingWindow) wxMenubarSetInvokingWindow( menu, m_invokingWindow );