-
- for (int i = 0; i < m_menus.GetCount(); i++)
- {
- Str255 label;
- wxNode *node;
- wxMenuItem *item;
- int pos ;
- wxMenu* menu = m_menus[i] , *subMenu = NULL ;
-
- if( m_titles[i] == "?" || m_titles[i] == "&?" || m_titles[i] == wxApp::s_macHelpMenuTitleName )
- {
- MenuHandle mh = NULL ;
- if ( UMAGetHelpMenu( &mh , &firstUserHelpMenuItem) != noErr )
- {
- continue ;
- }
-
- for ( int i = CountMenuItems( mh ) ; i >= firstUserHelpMenuItem ; --i )
- {
- DeleteMenuItem( mh , i ) ;
- }
-
- for (pos = 0 , node = menu->GetMenuItems().First(); node; node = node->Next(), pos++)
- {
- item = (wxMenuItem *)node->Data();
- subMenu = item->GetSubMenu() ;
- if (subMenu)
- {
- // we don't support hierarchical menus in the help menu yet
- }
- else
- {
- if ( item->IsSeparator() )
- {
- if ( mh )
- MacAppendMenu(mh, "\p-" );
- }
- else
- {
- Str255 label ;
- UInt8 modifiers ;
- SInt16 key ;
- wxMenuItem::MacBuildMenuString( label, &key , &modifiers , item->GetText(), item->GetId() != wxApp::s_macAboutMenuItemId); // no shortcut in about menu
- if ( label[0] == 0 )
- {
- // we cannot add empty menus on mac
- label[0] = 1 ;
- label[1] = ' ' ;
- }
- if ( item->GetId() == wxApp::s_macAboutMenuItemId )
- {
- ::SetMenuItemText( GetMenuHandle( kwxMacAppleMenuId ) , 1 , label );
- UMAEnableMenuItem( GetMenuHandle( kwxMacAppleMenuId ) , 1 );
- }
- else
- {
- if ( mh )
- UMAAppendMenuItem(mh, label , key , modifiers );
- }
- }
- }
- }
- }
- else
- {
- wxMenuItem::MacBuildMenuString( label, NULL , NULL , m_titles[i] , false );
- UMASetMenuTitle( MAC_WXHMENU(menu->GetHMenu()) , label ) ;
- wxArrayPtrVoid submenus ;
-
- for (pos = 0, node = menu->GetMenuItems().First(); node; node = node->Next(), pos++)
- {
- item = (wxMenuItem *)node->Data();
- subMenu = item->GetSubMenu() ;
- if (subMenu)
- {
- submenus.Add(subMenu) ;
- }
- }
- ::InsertMenu(MAC_WXHMENU(m_menus[i]->GetHMenu()), 0);
- for ( int i = 0 ; i < submenus.GetCount() ; ++i )
- {
- wxMenu* submenu = (wxMenu*) submenus[i] ;
- wxNode *subnode;
- wxMenuItem *subitem;
- int subpos ;
- for ( subpos = 0 , subnode = submenu->GetMenuItems().First(); subnode; subnode = subnode->Next(), subpos++)
- {
- subitem = (wxMenuItem *)subnode->Data();
- wxMenu* itsSubMenu = subitem->GetSubMenu() ;
- if (itsSubMenu)
- {
- submenus.Add(itsSubMenu) ;
- }
- }
- ::InsertMenu( MAC_WXHMENU(submenu->GetHMenu()) , -1 ) ;
- }
- }
- }
- ::DrawMenuBar() ;
- s_macInstalledMenuBar = this;
+
+ // 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 ;
+ }
+#if TARGET_CARBON
+ if ( UMAGetSystemVersion() >= 0x1000 && wxApp::s_macPreferencesMenuItemId)
+ {
+ wxMenuItem *item = FindItem( wxApp::s_macPreferencesMenuItemId , NULL ) ;
+ if ( item == NULL || !(item->IsEnabled()) )
+ DisableMenuCommand( NULL , kHICommandPreferences ) ;
+ else
+ EnableMenuCommand( NULL , kHICommandPreferences ) ;
+ }
+#endif
+ for (size_t i = 0; i < m_menus.GetCount(); i++)
+ {
+ wxMenuItemList::Node *node;
+ wxMenuItem *item;
+ int pos ;
+ wxMenu* menu = m_menus[i] , *subMenu = NULL ;
+
+ if( m_titles[i] == wxT("?") || m_titles[i] == wxT("&?") || m_titles[i] == wxApp::s_macHelpMenuTitleName )
+ {
+ if ( mh == NULL )
+ {
+ continue ;
+ }
+
+ for (pos = 0 , node = menu->GetMenuItems().GetFirst(); node; node = node->GetNext(), pos++)
+ {
+ item = (wxMenuItem *)node->GetData();
+ subMenu = item->GetSubMenu() ;
+ if (subMenu)
+ {
+ // we don't support hierarchical menus in the help menu yet
+ }
+ else
+ {
+ if ( item->IsSeparator() )
+ {
+ if ( mh )
+ MacAppendMenu(mh, "\p-" );
+ }
+ else
+ {
+ wxAcceleratorEntry* entry = wxGetAccelFromString( item->GetText() ) ;
+
+ if ( item->GetId() == wxApp::s_macAboutMenuItemId )
+ {
+ UMASetMenuItemText( GetMenuHandle( kwxMacAppleMenuId ) , 1 , item->GetText() , wxFont::GetDefaultEncoding() );
+ UMAEnableMenuItem( GetMenuHandle( kwxMacAppleMenuId ) , 1 , true );
+ SetMenuItemCommandID( GetMenuHandle( kwxMacAppleMenuId ) , 1 , item->GetId() ) ;
+ UMASetMenuItemShortcut( GetMenuHandle( kwxMacAppleMenuId ) , 1 , entry ) ;
+ }
+ else
+ {
+ if ( mh )
+ {
+ UMAAppendMenuItem(mh, item->GetText() , wxFont::GetDefaultEncoding(), entry);
+ SetMenuItemCommandID( mh , CountMenuItems(mh) , item->GetId() ) ;
+ }
+ }
+
+ delete entry ;
+ }
+ }
+ }
+ }
+ else
+ {
+ UMASetMenuTitle( MAC_WXHMENU(menu->GetHMenu()) , m_titles[i], m_font.GetEncoding() ) ;
+ m_menus[i]->MacBeforeDisplay(false) ;
+ ::InsertMenu(MAC_WXHMENU(m_menus[i]->GetHMenu()), 0);
+ }
+ }
+ ::DrawMenuBar() ;
+ s_macInstalledMenuBar = this;