X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/43524b1583cbe798351fef03242f0990e1cfddc2..6e1609b1e0784f299933742e02c58462df809acc:/src/mac/carbon/menuitem.cpp?ds=sidebyside diff --git a/src/mac/carbon/menuitem.cpp b/src/mac/carbon/menuitem.cpp index 6065ff1b92..172c5b0ab1 100644 --- a/src/mac/carbon/menuitem.cpp +++ b/src/mac/carbon/menuitem.cpp @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////////////////// -// Name: menuitem.cpp +// Name: src/mac/carbon/menuitem.cpp // Purpose: wxMenuItem implementation // Author: Stefan Csomor // Modified by: @@ -11,9 +11,13 @@ #include "wx/wxprec.h" -#include "wx/app.h" -#include "wx/menu.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/mac/uma.h" @@ -59,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 ; @@ -72,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 @@ -86,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 ) ; @@ -95,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()) ; @@ -117,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 ; } @@ -133,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 ; } @@ -142,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 @@ -151,7 +169,6 @@ void wxMenuItem::Enable(bool bDoEnable) || ( GetId() == wxApp::s_macPreferencesMenuItemId || GetId() == wxApp::s_macExitMenuItemId || GetId() == wxApp::s_macAboutMenuItemId -#endif )) { wxMenuItemBase::Enable( bDoEnable ) ; @@ -222,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() ; } @@ -262,7 +279,7 @@ void wxMenuItem::SetRadioGroupEnd(int end) // ---------------------------------------------------------------------------- /* static */ -wxString wxMenuItemBase::GetLabelFromText(const wxString& text) +wxString wxMenuItemBase::GetLabelText(const wxString& text) { return wxStripMenuCodes(text); }