- Handle menubar = ::GetNewMBar( kwxMacMenuBarResource ) ;
- wxString message ;
- wxCHECK_RET( menubar != NULL, "can't read MBAR resource" );
- ::SetMenuBar( menubar ) ;
- ::DisposeHandle( menubar ) ;
-
- MenuHandle menu = ::GetMenuHandle( kwxMacAppleMenuId ) ;
- ::AppendResMenu(menu, 'DRVR');
-
- 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] == wxApp::s_macHelpMenuTitleName )
- {
- MenuHandle mh = NULL ;
- if ( HMGetHelpMenuHandle( &mh ) != noErr )
- {
- continue ;
- }
- if ( formerHelpMenuItems == 0 )
- {
- if( mh )
- formerHelpMenuItems = CountMenuItems( mh ) ;
- }
-
- 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
- {
- Str255 label ;
- wxMacBuildMenuString( label , NULL , NULL , 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 );
- // ::EnableMenuItem( GetMenuHandle( kwxMacAppleMenuId ) , 1 );
- ::EnableItem( GetMenuHandle( kwxMacAppleMenuId ) , 1 );
- }
- else
- {
- if ( mh )
- ::AppendMenu(mh, label );
- }
- }
- }
- }
- else
- {
- wxMacBuildMenuString( label, NULL , NULL , m_titles[i] , false );
- UMASetMenuTitle( menu->GetHMenu() , label ) ;
- for (pos = 0, node = menu->GetMenuItems().First(); node; node = node->Next(), pos++)
- {
- item = (wxMenuItem *)node->Data();
- subMenu = item->GetSubMenu() ;
- if (subMenu)
- {
- ::InsertMenu( subMenu->GetHMenu() , -1 ) ;
- }
- }
- ::InsertMenu(m_menus[i]->GetHMenu(), 0);
- }
- }
- ::DrawMenuBar() ;
-
- s_macInstalledMenuBar = this;
+ if ( s_macInstalledMenuBar == this )
+ return ;
+
+ MenuBarHandle menubar = NULL ;
+#if TARGET_API_MAC_OSX
+ menubar = NewHandleClear( 6 /* sizeof( MenuBarHeader ) */ ) ;
+#else
+ menubar = NewHandleClear( 12 ) ;
+ (*menubar)[3] = 0x0a ;
+#endif
+ ::SetMenuBar( menubar ) ;
+ DisposeMenuBar( menubar ) ;
+ MenuHandle appleMenu = NULL ;
+ char appleMenuTitle[3] = { 01 , kMenuAppleLogoFilledGlyph , 0 } ;
+
+ verify_noerr( CreateNewMenu( kwxMacAppleMenuId , 0 , &appleMenu ) ) ;
+ verify_noerr( SetMenuTitle( appleMenu , (ConstStr255Param) appleMenuTitle ) );
+
+ // Add About/Preferences separator only on OS X
+ // KH/RN: Separator is always present on 10.3 but not on 10.2
+ // However, the change from 10.2 to 10.3 suggests it is preferred
+#if TARGET_API_MAC_OSX
+ MacInsertMenuItem( appleMenu , "\p-" , 0 ) ;
+#endif
+
+ MacInsertMenuItem( appleMenu , "\pAbout..." , 0 ) ;
+ MacInsertMenu( appleMenu , 0 ) ;
+
+ // 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
+ wxMenuList::compatibility_iterator menuIter = m_menus.GetFirst();
+ //
+ for (size_t i = 0; i < m_menus.GetCount(); i++, menuIter = menuIter->GetNext())
+ {
+ wxMenuItemList::compatibility_iterator node;
+ wxMenuItem *item;
+ int pos ;
+ wxMenu* menu = menuIter->GetData() , *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() ) ;
+ SetMenuItemRefCon(GetMenuHandle( kwxMacAppleMenuId ) , 1 , (UInt32)item ) ;
+ UMASetMenuItemShortcut( GetMenuHandle( kwxMacAppleMenuId ) , 1 , entry ) ;
+ }
+ else
+ {
+ if ( mh )
+ {
+ UMAAppendMenuItem(mh, item->GetText() , wxFont::GetDefaultEncoding(), entry);
+ SetMenuItemCommandID( mh , CountMenuItems(mh) , item->GetId() ) ;
+ SetMenuItemRefCon( mh , CountMenuItems(mh) , (UInt32)item ) ;
+ }
+ }
+
+ delete entry ;
+ }
+ }
+ }
+ }
+ else
+ {
+ UMASetMenuTitle( MAC_WXHMENU(menu->GetHMenu()) , m_titles[i], m_font.GetEncoding() ) ;
+ menu->MacBeforeDisplay(false) ;
+ ::InsertMenu(MAC_WXHMENU(_wxMenuAt(m_menus, i)->GetHMenu()), 0);
+ }
+ }
+ ::DrawMenuBar() ;
+ s_macInstalledMenuBar = this;