X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/876262caf1dd81b0e3d9a0c81c10879f6fb256e8..f9133b32002a600cb48dd05fbcce1ab3ed684dba:/src/common/menucmn.cpp diff --git a/src/common/menucmn.cpp b/src/common/menucmn.cpp index e6368d779a..5422c06677 100644 --- a/src/common/menucmn.cpp +++ b/src/common/menucmn.cpp @@ -81,6 +81,15 @@ wxMenuItemBase::~wxMenuItemBase() #if wxUSE_ACCEL +static inline bool CompareAccelString(const wxString& str, const wxChar *accel) +{ +#if wxUSE_INTL + return str == accel || str == wxGetTranslation(accel); +#else + return str == accel; +#endif +} + // return wxAcceleratorEntry for the given menu string or NULL if none // specified wxAcceleratorEntry *wxGetAccelFromString(const wxString& label) @@ -94,11 +103,11 @@ wxAcceleratorEntry *wxGetAccelFromString(const wxString& label) wxString current; for ( size_t n = (size_t)posTab + 1; n < label.Len(); n++ ) { if ( (label[n] == '+') || (label[n] == '-') ) { - if ( current == _("ctrl") || current == _T("ctrl") ) + if ( CompareAccelString(current, wxTRANSLATE("ctrl")) ) accelFlags |= wxACCEL_CTRL; - else if ( current == _("alt") || current == _T("alt") ) + else if ( CompareAccelString(current, wxTRANSLATE("alt")) ) accelFlags |= wxACCEL_ALT; - else if ( current == _("shift") || current == _T("shift") ) + else if ( CompareAccelString(current, wxTRANSLATE("shift")) ) accelFlags |= wxACCEL_SHIFT; else { // we may have "Ctrl-+", for example, but we still want to @@ -276,10 +285,6 @@ void wxMenuBase::Init(long style) m_style = style; m_clientData = (void *)NULL; m_eventHandler = this; - -#if wxUSE_MENU_CALLBACK - m_callback = (wxFunction) NULL; -#endif // wxUSE_MENU_CALLBACK } wxMenuBase::~wxMenuBase() @@ -310,6 +315,7 @@ bool wxMenuBase::DoAppend(wxMenuItem *item) wxCHECK_MSG( item, FALSE, wxT("invalid item in wxMenu::Append()") ); m_items.Append(item); + item->SetMenu((wxMenu*)this); if ( item->IsSubMenu() ) { AddSubMenu(item->GetSubMenu()); @@ -343,6 +349,7 @@ bool wxMenuBase::DoInsert(size_t pos, wxMenuItem *item) wxCHECK_MSG( node, FALSE, wxT("invalid index in wxMenu::Insert()") ); m_items.Insert(node, item); + item->SetMenu((wxMenu*)this); if ( item->IsSubMenu() ) { AddSubMenu(item->GetSubMenu()); @@ -371,6 +378,7 @@ wxMenuItem *wxMenuBase::DoRemove(wxMenuItem *item) m_items.DeleteNode(node); // item isn't attached to anything any more + item->SetMenu((wxMenu *)NULL); wxMenu *submenu = item->GetSubMenu(); if ( submenu ) { @@ -508,6 +516,15 @@ wxMenuItem *wxMenuBase::FindChildItem(int id, size_t *ppos) const return item; } +// find by position +wxMenuItem* wxMenuBase::FindItemByPosition(size_t position) const +{ + wxCHECK_MSG( position < m_items.GetCount(), NULL, + _T("wxMenu::FindItemByPosition(): invalid menu index") ); + + return m_items.Item( position )->GetData(); +} + // ---------------------------------------------------------------------------- // wxMenu helpers used by derived classes // ---------------------------------------------------------------------------- @@ -536,7 +553,7 @@ void wxMenuBase::UpdateUI(wxEvtHandler* source) if ( source->ProcessEvent(event) ) { - // if anything changed, update the chanegd attribute + // if anything changed, update the changed attribute if (event.GetSetText()) SetLabel(id, event.GetText()); if (event.GetSetChecked()) @@ -549,7 +566,7 @@ void wxMenuBase::UpdateUI(wxEvtHandler* source) if ( item->GetSubMenu() ) item->GetSubMenu()->UpdateUI(source); } - //else: item is a separator (which don't process update UI events) + //else: item is a separator (which doesn't process update UI events) node = node->GetNext(); } @@ -563,15 +580,6 @@ bool wxMenuBase::SendEvent(int id, int checked) bool processed = FALSE; -#if wxUSE_MENU_CALLBACK - // Try a callback - if (m_callback) - { - (void)(*(m_callback))(*this, event); - processed = TRUE; - } -#endif // wxUSE_MENU_CALLBACK - // Try the menu's event handler if ( !processed ) {