X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/670f9935630beb2123a5ca62894ae92a3f0efa4f..b3c1d21c7f6a88bd82cee5d3a64fa1bfecd50ed4:/src/mac/carbon/menuitem.cpp?ds=sidebyside diff --git a/src/mac/carbon/menuitem.cpp b/src/mac/carbon/menuitem.cpp index 44b80b1319..172c5b0ab1 100644 --- a/src/mac/carbon/menuitem.cpp +++ b/src/mac/carbon/menuitem.cpp @@ -12,13 +12,13 @@ #include "wx/wxprec.h" #include "wx/menuitem.h" +#include "wx/stockitem.h" #ifndef WX_PRECOMP #include "wx/app.h" + #include "wx/menu.h" #endif // WX_PRECOMP -#include "wx/menu.h" - #include "wx/mac/uma.h" IMPLEMENT_DYNAMIC_CLASS(wxMenuItem, wxObject) @@ -63,6 +63,13 @@ void wxMenuItem::UpdateItemBitmap() MenuHandle mhandle = MAC_WXHMENU(m_parentMenu->GetHMenu()) ; MenuItemIndex index = m_parentMenu->MacGetIndexFromItem( this ) ; + DoUpdateItemBitmap( mhandle, index ); +} + +void wxMenuItem::DoUpdateItemBitmap( WXHMENU menu, wxUint16 index) +{ + MenuHandle mhandle = (MenuHandle) menu; + if ( mhandle == NULL || index == 0) return ; @@ -76,6 +83,9 @@ void wxMenuItem::UpdateItemBitmap() if ( info.contentType == kControlContentIconRef ) SetMenuItemIconHandle( mhandle , index , kMenuIconRefType , (Handle) info.u.iconRef ) ; + else if ( info.contentType == kControlContentCGImageRef ) + SetMenuItemIconHandle( mhandle , index , + kMenuCGImageRefType , (Handle) info.u.imageRef ) ; } wxMacReleaseBitmapButton( &info ) ; #endif @@ -90,8 +100,7 @@ void wxMenuItem::UpdateItemStatus() if ( IsSeparator() ) return ; -#if TARGET_CARBON - if ( UMAGetSystemVersion() >= 0x1000 && GetId() == wxApp::s_macPreferencesMenuItemId) + if ( GetId() == wxApp::s_macPreferencesMenuItemId) { if ( !IsEnabled() ) DisableMenuCommand( NULL , kHICommandPreferences ) ; @@ -99,14 +108,13 @@ void wxMenuItem::UpdateItemStatus() EnableMenuCommand( NULL , kHICommandPreferences ) ; } - if ( UMAGetSystemVersion() >= 0x1000 && GetId() == wxApp::s_macExitMenuItemId) + if ( GetId() == wxApp::s_macExitMenuItemId) { if ( !IsEnabled() ) DisableMenuCommand( NULL , kHICommandQuit ) ; else EnableMenuCommand( NULL , kHICommandQuit ) ; } -#endif { MenuHandle mhandle = MAC_WXHMENU(m_parentMenu->GetHMenu()) ; @@ -121,7 +129,7 @@ void wxMenuItem::UpdateItemStatus() ::SetItemMark( mhandle , index , 0 ) ; // no mark UMASetMenuItemText( mhandle , index , wxStripMenuCodes(m_text) , wxFont::GetDefaultEncoding() ) ; - wxAcceleratorEntry *entry = wxGetAccelFromString( m_text ) ; + wxAcceleratorEntry *entry = wxAcceleratorEntry::Create( m_text ) ; UMASetMenuItemShortcut( mhandle , index , entry ) ; delete entry ; } @@ -137,8 +145,15 @@ void wxMenuItem::UpdateItemText() if (mhandle == NULL || index == 0) return ; - UMASetMenuItemText( mhandle , index , wxStripMenuCodes(m_text) , wxFont::GetDefaultEncoding() ) ; - wxAcceleratorEntry *entry = wxGetAccelFromString( m_text ) ; + wxString text = m_text; + if (text.IsEmpty() && !IsSeparator()) + { + wxASSERT_MSG(wxIsStockID(GetId()), wxT("A non-stock menu item with an empty label?")); + text = wxGetStockLabel(GetId(), wxSTOCK_WITH_ACCELERATOR|wxSTOCK_WITH_MNEMONIC); + } + + UMASetMenuItemText( mhandle , index , wxStripMenuCodes(text) , wxFont::GetDefaultEncoding() ) ; + wxAcceleratorEntry *entry = wxAcceleratorEntry::Create( text ) ; UMASetMenuItemShortcut( mhandle , index , entry ) ; delete entry ; } @@ -146,7 +161,6 @@ void wxMenuItem::UpdateItemText() void wxMenuItem::Enable(bool bDoEnable) { if (( m_isEnabled != bDoEnable -#if TARGET_CARBON // avoid changing menuitem state when menu is disabled // eg. BeginAppModalStateForWindow() will disable menus and ignore this change // which in turn causes m_isEnabled to become out of sync with real menuitem state @@ -155,7 +169,6 @@ void wxMenuItem::Enable(bool bDoEnable) || ( GetId() == wxApp::s_macPreferencesMenuItemId || GetId() == wxApp::s_macExitMenuItemId || GetId() == wxApp::s_macAboutMenuItemId -#endif )) { wxMenuItemBase::Enable( bDoEnable ) ; @@ -226,13 +239,13 @@ void wxMenuItem::Check(bool bDoCheck) } } -void wxMenuItem::SetText(const wxString& text) +void wxMenuItem::SetItemLabel(const wxString& text) { // don't do anything if label didn't change if ( m_text == text ) return; - wxMenuItemBase::SetText(text); + wxMenuItemBase::SetItemLabel(text); UpdateItemText() ; } @@ -266,7 +279,7 @@ void wxMenuItem::SetRadioGroupEnd(int end) // ---------------------------------------------------------------------------- /* static */ -wxString wxMenuItemBase::GetLabelFromText(const wxString& text) +wxString wxMenuItemBase::GetLabelText(const wxString& text) { return wxStripMenuCodes(text); }