void wxMenu::RemoveAccel(wxMenuItem *item) { // recurse upwards: we should only modify m_accels of the top level // menus, not of the submenus as wxMenuBar doesn't look at them // (alternative and arguable cleaner solution would be to recurse // downwards in GetAccelCount() and CopyAccels()) if ( GetParent() ) { GetParent()->RemoveAccel(item); return; } // remove the corresponding accel from the accel table int n = FindAccel(item->GetId()); if ( n != wxNOT_FOUND ) { delete m_accels[n]; m_accels.RemoveAt(n); #if wxUSE_OWNER_DRAWN ResetMaxAccelWidth(); #endif } //else: this item doesn't have an accel, nothing to do }
void wxMenu::UpdateAccel(wxMenuItem *item) { if ( item->IsSubMenu() ) { wxMenu *submenu = item->GetSubMenu(); wxMenuItemList::compatibility_iterator node = submenu->GetMenuItems().GetFirst(); while ( node ) { UpdateAccel(node->GetData()); node = node->GetNext(); } } else if ( !item->IsSeparator() ) { // recurse upwards: we should only modify m_accels of the top level // menus, not of the submenus as wxMenuBar doesn't look at them // (alternative and arguable cleaner solution would be to recurse // downwards in GetAccelCount() and CopyAccels()) if ( GetParent() ) { GetParent()->UpdateAccel(item); return; } // find the (new) accel for this item wxAcceleratorEntry *accel = wxAcceleratorEntry::Create(item->GetItemLabel()); if ( accel ) accel->m_command = item->GetId(); // find the old one int n = FindAccel(item->GetId()); if ( n == wxNOT_FOUND ) { // no old, add new if any if ( accel ) m_accels.Add(accel); else return; // skipping RebuildAccelTable() below } else { // replace old with new or just remove the old one if no new delete m_accels[n]; if ( accel ) m_accels[n] = accel; else m_accels.RemoveAt(n); } if ( IsAttached() ) { GetMenuBar()->RebuildAccelTable(); } ResetMaxAccelWidth(); } //else: it is a separator, they can't have accels, nothing to do }
wxMenuItem* wxMenu::DoRemove( wxMenuItem* pItem ) { // // We need to find the items position in the child list // size_t nPos; wxMenuItemList::compatibility_iterator node = GetMenuItems().GetFirst(); for (nPos = 0; node; nPos++) { if (node->GetData() == pItem) break; node = node->GetNext(); } // // DoRemove() (unlike Remove) can only be called for existing item! // wxCHECK_MSG(node, NULL, wxT("bug in wxMenu::Remove logic")); #if wxUSE_ACCEL // // Remove the corresponding accel from the accel table // int n = FindAccel(pItem->GetId()); if (n != wxNOT_FOUND) { delete m_vAccels[n]; m_vAccels.RemoveAt(n); } #endif // wxUSE_ACCEL // // Remove the item from the menu // ::WinSendMsg( GetHmenu() ,MM_REMOVEITEM ,MPFROM2SHORT(pItem->GetId(), TRUE) ,(MPARAM)0 ); if (IsAttached() && GetMenuBar()->IsAttached()) { // // Otherwise, the chane won't be visible // GetMenuBar()->Refresh(); } // // And from internal data structures // return wxMenuBase::DoRemove(pItem); } // end of wxMenu::DoRemove
void AccelTableDlg::DoItemActivated() { wxDataViewItem sel = m_dvListCtrl->GetSelection(); CHECK_ITEM_RET(sel); AccelItemData* itemData = DoGetItemData(sel); if(!itemData) return; // build the selected entry MenuItemData mid = itemData->m_menuItemData; if(clKeyboardManager::Get()->PopupNewKeyboardShortcutDlg(this, mid) == wxID_OK) { // search the list for similar accelerator MenuItemData who; if(HasAccelerator(mid.accel, who)) { if(who.action == mid.action) { return; } if(wxMessageBox(wxString::Format(_("'%s' is already assigned to: '%s'\nWould you like to replace it?"), mid.accel, who.action), _("CodeLite"), wxYES_NO | wxCENTER | wxICON_QUESTION, this) != wxYES) { return; } // Remove the old entry wxDataViewItem oldItem = FindAccel(mid); if(oldItem.IsOk()) { AccelItemData* cd = DoGetItemData(oldItem); if(cd) { cd->m_menuItemData.accel.Clear(); int row = m_dvListCtrl->ItemToRow(oldItem); m_dvListCtrl->SetValue(wxString(), row, 2); MenuItemDataMap_t::iterator iter = m_accelMap.find(cd->m_menuItemData.resourceID); if(iter != m_accelMap.end()) { iter->second.accel.Clear(); // Clear the accelerator } } } } // Update the client data itemData->m_menuItemData = mid; // Update the UI int row = m_dvListCtrl->ItemToRow(sel); if(row == wxNOT_FOUND) return; m_dvListCtrl->SetValue(mid.accel, row, 2); // and update the map MenuItemDataMap_t::iterator iter = m_accelMap.find(itemData->m_menuItemData.resourceID); if(iter != m_accelMap.end()) { iter->second.accel = itemData->m_menuItemData.accel; } } }
wxMenuItem *wxMenu::DoRemove(wxMenuItem *item) { // we need to find the item's position in the child list size_t pos; wxMenuItemList::compatibility_iterator node = GetMenuItems().GetFirst(); for ( pos = 0; node; pos++ ) { if ( node->GetData() == item ) break; node = node->GetNext(); } #if wxUSE_ACCEL // remove the corresponding accel from the accel table int n = FindAccel(item->GetId()); if ( n != wxNOT_FOUND ) { delete m_accels[n]; m_accels.RemoveAt(n); #if wxUSE_OWNER_DRAWN ResetMaxAccelWidth(); #endif } //else: this item doesn't have an accel, nothing to do #endif // wxUSE_ACCEL // Update indices of radio groups. if ( m_radioData ) { bool inExistingGroup = m_radioData->UpdateOnRemoveItem(pos); wxASSERT_MSG( !inExistingGroup || item->GetKind() == wxITEM_RADIO, wxT("Removing non radio button from radio group?") ); } // remove the item from the menu if ( !::RemoveMenu(GetHmenu(), (UINT)pos, MF_BYPOSITION) ) { wxLogLastError(wxT("RemoveMenu")); } if ( IsAttached() && GetMenuBar()->IsAttached() ) { // otherwise, the change won't be visible GetMenuBar()->Refresh(); } // and from internal data structures return wxMenuBase::DoRemove(item); }
wxMenuItem *wxMenu::DoRemove(wxMenuItem *item) { // we need to find the item's position in the child list size_t pos; wxMenuItemList::compatibility_iterator node = GetMenuItems().GetFirst(); for ( pos = 0; node; pos++ ) { if ( node->GetData() == item ) break; node = node->GetNext(); } // DoRemove() (unlike Remove) can only be called for an existing item! wxCHECK_MSG( node, NULL, wxT("bug in wxMenu::Remove logic") ); #if wxUSE_ACCEL // remove the corresponding accel from the accel table int n = FindAccel(item->GetId()); if ( n != wxNOT_FOUND ) { delete m_accels[n]; m_accels.RemoveAt(n); #if wxUSE_OWNER_DRAWN ResetMaxAccelWidth(); #endif } //else: this item doesn't have an accel, nothing to do #endif // wxUSE_ACCEL // remove the item from the menu if ( !::RemoveMenu(GetHmenu(), (UINT)pos, MF_BYPOSITION) ) { wxLogLastError(wxT("RemoveMenu")); } if ( IsAttached() && GetMenuBar()->IsAttached() ) { // otherwise, the change won't be visible GetMenuBar()->Refresh(); } // and from internal data structures return wxMenuBase::DoRemove(item); }
void wxMenu::UpdateAccel(wxMenuItem *item) { if ( item->IsSubMenu() ) { wxMenu *submenu = item->GetSubMenu(); wxMenuItemList::compatibility_iterator node = submenu->GetMenuItems().GetFirst(); while ( node ) { UpdateAccel(node->GetData()); node = node->GetNext(); } } else if ( !item->IsSeparator() ) { // find the (new) accel for this item wxAcceleratorEntry *accel = wxGetAccelFromString(item->GetText()); if ( accel ) accel->m_command = item->GetId(); // find the old one int n = FindAccel(item->GetId()); if ( n == wxNOT_FOUND ) { // no old, add new if any if ( accel ) m_accels.Add(accel); else return; // skipping RebuildAccelTable() below } else { // replace old with new or just remove the old one if no new delete m_accels[n]; if ( accel ) m_accels[n] = accel; else m_accels.RemoveAt(n); } if ( IsAttached() ) { GetMenuBar()->RebuildAccelTable(); } } //else: it is a separator, they can't have accels, nothing to do }
void wxMenu::UpdateAccel( wxMenuItem* pItem ) { if (pItem->IsSubMenu()) { wxMenu* pSubmenu = pItem->GetSubMenu(); wxMenuItemList::compatibility_iterator node = pSubmenu->GetMenuItems().GetFirst(); #if defined(__INTEL_COMPILER) && 1 // VDM auto patch # pragma ivdep # pragma swp # pragma unroll #endif #if defined(__INTEL_COMPILER) && 1 /* VDM auto patch */ # pragma ivdep # pragma swp # pragma unroll # pragma prefetch # if 0 # pragma simd noassert # endif #endif /* VDM auto patch */ while (node) { UpdateAccel(node->GetData()); node = node->GetNext(); } } else if (!pItem->IsSeparator()) { // // Recurse upwards: we should only modify m_accels of the top level // menus, not of the submenus as wxMenuBar doesn't look at them // (alternative and arguable cleaner solution would be to recurse // downwards in GetAccelCount() and CopyAccels()) // if (GetParent()) { GetParent()->UpdateAccel(pItem); return; } // // Find the (new) accel for this item // wxAcceleratorEntry* pAccel = wxAcceleratorEntry::Create(pItem->GetItemLabel()); if (pAccel) pAccel->m_command = pItem->GetId(); // // Find the old one // size_t n = FindAccel(pItem->GetId()); if (n == (size_t)wxNOT_FOUND) { // // No old, add new if any // if (pAccel) m_vAccels.Add(pAccel); else return; } else { // // Replace old with new or just remove the old one if no new // delete m_vAccels[n]; if (pAccel) m_vAccels[n] = pAccel; else m_vAccels.RemoveAt(n); } if (IsAttached()) { GetMenuBar()->RebuildAccelTable(); } } } // wxMenu::UpdateAccel