X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/83eabba429ab076322fbdddd1d011c73af814fe2..bbd92d1dbea02db8c28e9c17bfacc0563d855b25:/src/mac/carbon/menuitem.cpp diff --git a/src/mac/carbon/menuitem.cpp b/src/mac/carbon/menuitem.cpp index 0eb888060b..172c5b0ab1 100644 --- a/src/mac/carbon/menuitem.cpp +++ b/src/mac/carbon/menuitem.cpp @@ -12,12 +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) @@ -62,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 ; @@ -75,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 @@ -89,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 ) ; @@ -98,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()) ; @@ -120,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 ; } @@ -136,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 ; } @@ -145,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 @@ -154,7 +169,6 @@ void wxMenuItem::Enable(bool bDoEnable) || ( GetId() == wxApp::s_macPreferencesMenuItemId || GetId() == wxApp::s_macExitMenuItemId || GetId() == wxApp::s_macAboutMenuItemId -#endif )) { wxMenuItemBase::Enable( bDoEnable ) ; @@ -225,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() ; } @@ -265,7 +279,7 @@ void wxMenuItem::SetRadioGroupEnd(int end) // ---------------------------------------------------------------------------- /* static */ -wxString wxMenuItemBase::GetLabelFromText(const wxString& text) +wxString wxMenuItemBase::GetLabelText(const wxString& text) { return wxStripMenuCodes(text); }