X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/5977edb9d9df0534b277dd9bd0904f0006a5b1f5..ad31e6a2dad590dc362acee9932e2567716f0e89:/src/mac/carbon/menu.cpp diff --git a/src/mac/carbon/menu.cpp b/src/mac/carbon/menu.cpp index b65b04b6fc..09cf4450c1 100644 --- a/src/mac/carbon/menu.cpp +++ b/src/mac/carbon/menu.cpp @@ -1,12 +1,12 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: menu.cpp +// Name: src/mac/carbon/menu.cpp // Purpose: wxMenu, wxMenuBar, wxMenuItem // Author: Stefan Csomor // Modified by: // Created: 1998-01-01 // RCS-ID: $Id$ // Copyright: (c) Stefan Csomor -// Licence: wxWindows licence +// Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// // ============================================================================ @@ -18,13 +18,15 @@ #include "wx/wxprec.h" -#include "wx/app.h" #include "wx/menu.h" -#include "wx/menuitem.h" -#include "wx/window.h" -#include "wx/log.h" -#include "wx/utils.h" -#include "wx/frame.h" + +#ifndef WX_PRECOMP + #include "wx/log.h" + #include "wx/app.h" + #include "wx/utils.h" + #include "wx/frame.h" + #include "wx/menuitem.h" +#endif #include "wx/mac/uma.h" @@ -38,8 +40,7 @@ IMPLEMENT_DYNAMIC_CLASS(wxMenuBar, wxEvtHandler) // the (popup) menu title has this special id static const int idMenuTitle = -3; -const short kwxMacMenuBarResource = 1 ; -const short kwxMacAppleMenuId = 1 ; +static const short kwxMacAppleMenuId = 1 ; // Find an item given the Macintosh Menu Reference @@ -160,9 +161,11 @@ bool wxMenu::DoInsertOrAppend(wxMenuItem *pItem, size_t pos) if ( pItem->IsSeparator() ) { if ( pos == (size_t)-1 ) - MacAppendMenu(MAC_WXHMENU(m_hMenu), "\p-"); + AppendMenuItemTextWithCFString( MAC_WXHMENU(m_hMenu), + CFSTR(""), kMenuItemAttrSeparator, 0,NULL); else - MacInsertMenuItem(MAC_WXHMENU(m_hMenu), "\p-" , pos); + InsertMenuItemTextWithCFString( MAC_WXHMENU(m_hMenu), + CFSTR(""), pos, kMenuItemAttrSeparator, 0); } else { @@ -176,9 +179,9 @@ bool wxMenu::DoInsertOrAppend(wxMenuItem *pItem, size_t pos) pSubMenu->MacBeforeDisplay( true ) ; if ( pos == (size_t)-1 ) - UMAAppendSubMenuItem(MAC_WXHMENU(m_hMenu), pItem->GetText(), wxFont::GetDefaultEncoding(), pSubMenu->m_macMenuId); + UMAAppendSubMenuItem(MAC_WXHMENU(m_hMenu), wxStripMenuCodes(pItem->GetText()), wxFont::GetDefaultEncoding(), pSubMenu->m_macMenuId); else - UMAInsertSubMenuItem(MAC_WXHMENU(m_hMenu), pItem->GetText(), wxFont::GetDefaultEncoding(), pos, pSubMenu->m_macMenuId); + UMAInsertSubMenuItem(MAC_WXHMENU(m_hMenu), wxStripMenuCodes(pItem->GetText()), wxFont::GetDefaultEncoding(), pos, pSubMenu->m_macMenuId); pItem->UpdateItemBitmap() ; pItem->UpdateItemStatus() ; @@ -198,9 +201,9 @@ bool wxMenu::DoInsertOrAppend(wxMenuItem *pItem, size_t pos) UMAInsertMenuItem(MAC_WXHMENU(m_hMenu), wxT("a"), wxFont::GetDefaultEncoding(), pos); pos += 1 ; } - + SetMenuItemCommandID( MAC_WXHMENU(m_hMenu) , pos , wxIdToMacCommand ( pItem->GetId() ) ) ; - SetMenuItemRefCon( MAC_WXHMENU(m_hMenu) , pos , (UInt32) pItem ) ; + SetMenuItemRefCon( MAC_WXHMENU(m_hMenu) , pos , (URefCon) pItem ) ; pItem->UpdateItemText() ; pItem->UpdateItemBitmap() ; pItem->UpdateItemStatus() ; @@ -485,12 +488,10 @@ void wxMenu::MacAfterDisplay( bool isSubMenu ) if ( isSubMenu ) ::DeleteMenu(MacGetMenuId()); - wxMenuItem* previousItem = NULL ; wxMenuItemList::compatibility_iterator node; wxMenuItem *item; - int pos ; - for (pos = 0, node = GetMenuItems().GetFirst(); node; node = node->GetNext(), pos++) + for (node = GetMenuItems().GetFirst(); node; node = node->GetNext()) { item = (wxMenuItem *)node->GetData(); wxMenu* subMenu = item->GetSubMenu() ; @@ -502,8 +503,6 @@ void wxMenu::MacAfterDisplay( bool isSubMenu ) { // no need to undo hidings } - - previousItem = item ; } } @@ -599,19 +598,19 @@ void wxMenuBar::MacInstallMenuBar() ::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 ) ); + verify_noerr( SetMenuTitleWithCFString( appleMenu , CFSTR( "\x14" ) ) ); // 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 ) ; + InsertMenuItemTextWithCFString( appleMenu, + CFSTR(""), 0, kMenuItemAttrSeparator, 0); #endif - - MacInsertMenuItem( appleMenu , "\pAbout..." , 0 ) ; + InsertMenuItemTextWithCFString( appleMenu, + CFSTR("About..."), 0, 0, 0); MacInsertMenu( appleMenu , 0 ) ; // clean-up the help menu before adding new items @@ -660,12 +659,11 @@ void wxMenuBar::MacInstallMenuBar() { 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 ) { - for (pos = 0 , node = menu->GetMenuItems().GetFirst(); node; node = node->GetNext(), pos++) + for (node = menu->GetMenuItems().GetFirst(); node; node = node->GetNext()) { item = (wxMenuItem *)node->GetData(); subMenu = item->GetSubMenu() ; @@ -691,11 +689,13 @@ void wxMenuBar::MacInstallMenuBar() if ( item->IsSeparator() ) { if ( mh ) - MacAppendMenu(mh, "\p-" ); + AppendMenuItemTextWithCFString( mh, + CFSTR(""), kMenuItemAttrSeparator, 0,NULL); } else { - wxAcceleratorEntry* entry = wxGetAccelFromString( item->GetText() ) ; + wxAcceleratorEntry* + entry = wxAcceleratorEntry::Create( item->GetText() ) ; if ( item->GetId() == wxApp::s_macAboutMenuItemId ) { @@ -705,9 +705,9 @@ void wxMenuBar::MacInstallMenuBar() { if ( mh ) { - UMAAppendMenuItem(mh, item->GetText() , wxFont::GetDefaultEncoding(), entry); + UMAAppendMenuItem(mh, wxStripMenuCodes(item->GetText()) , wxFont::GetDefaultEncoding(), entry); SetMenuItemCommandID( mh , CountMenuItems(mh) , wxIdToMacCommand ( item->GetId() ) ) ; - SetMenuItemRefCon( mh , CountMenuItems(mh) , (UInt32)item ) ; + SetMenuItemRefCon( mh , CountMenuItems(mh) , (URefCon) item ) ; } } @@ -730,11 +730,12 @@ void wxMenuBar::MacInstallMenuBar() wxMenuItem *aboutMenuItem = FindItem(wxApp::s_macAboutMenuItemId , &aboutMenu) ; if ( aboutMenuItem ) { - wxAcceleratorEntry* entry = wxGetAccelFromString( aboutMenuItem->GetText() ) ; - UMASetMenuItemText( GetMenuHandle( kwxMacAppleMenuId ) , 1 , aboutMenuItem->GetText() , wxFont::GetDefaultEncoding() ); + wxAcceleratorEntry* + entry = wxAcceleratorEntry::Create( aboutMenuItem->GetText() ) ; + UMASetMenuItemText( GetMenuHandle( kwxMacAppleMenuId ) , 1 , wxStripMenuCodes ( aboutMenuItem->GetText() ) , wxFont::GetDefaultEncoding() ); UMAEnableMenuItem( GetMenuHandle( kwxMacAppleMenuId ) , 1 , true ); SetMenuItemCommandID( GetMenuHandle( kwxMacAppleMenuId ) , 1 , kHICommandAbout ) ; - SetMenuItemRefCon(GetMenuHandle( kwxMacAppleMenuId ) , 1 , (UInt32)aboutMenuItem ) ; + SetMenuItemRefCon(GetMenuHandle( kwxMacAppleMenuId ) , 1 , (URefCon)aboutMenuItem ) ; UMASetMenuItemShortcut( GetMenuHandle( kwxMacAppleMenuId ) , 1 , entry ) ; } } @@ -819,7 +820,7 @@ wxMenu *wxMenuBar::Replace(size_t pos, wxMenu *menu, const wxString& title) { wxMenu *menuOld = wxMenuBarBase::Replace(pos, menu, title); if ( !menuOld ) - return false; + return NULL; m_titles[pos] = title;