//Hack to allow use (events) of wxmenu inside a tool like simpletexttool void hdDrawingView::connectPopUpMenu(wxMenu &mnu) { // Connect the main menu mnu.Connect(wxEVT_COMMAND_MENU_SELECTED, (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) &hdDrawingView::OnGenericPopupClick, NULL, this); // Connect all submenus wxMenuItem *item; wxMenuItemList list = mnu.GetMenuItems(); for (unsigned int index = 0; index < list.GetCount(); index++) { wxMenuItemList::compatibility_iterator node = list.Item(index); item = (wxMenuItem *) node->GetData(); if (item->IsSubMenu()) { wxMenu *submenu = item->GetSubMenu(); submenu->Connect(wxEVT_COMMAND_MENU_SELECTED, (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) &hdDrawingView::OnGenericPopupClick, NULL, this); } } }
bool LocationView::MouseRightDown(const Point2D& mousePt, wxMenu& popupMenu) { if(IsClicked(mousePt)) { if(popupMenu.GetMenuItems().size() == 0) { popupMenu.Append(ID_POPUP_MNU_PROPERTIES, wxT("Properties")); } return true; } return false; }
void SetMenu( wxMenu* menu, const OS_string& items, EnabledCallback enabledCallback = NULL ) { // protect the MRU so that it is only tied to one menu HELIUM_ASSERT( m_Menu == NULL || m_Menu == menu ); m_Menu = menu; m_MenuItemIDToString.clear(); // Clear out the old menu items while ( m_Menu->GetMenuItemCount() > 0 ) { m_Menu->Delete( *( m_Menu->GetMenuItems().begin() ) ); } // Build a new list of menu items from the MRU OS_string::ReverseIterator mruItr = items.ReverseBegin(); OS_string::ReverseIterator mruEnd = items.ReverseEnd(); for ( ; mruItr != mruEnd; ++mruItr ) { const tstring& item = *mruItr; wxMenuItem* menuItem = menu->Append( wxID_ANY, item.c_str() ); bool enabled = true; if ( enabledCallback ) { enabled = (*enabledCallback)( item ); } if ( enabled ) { Connect( menuItem->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( MenuMRUEvtHandler::OnMRUMenuItem ), NULL, this ); } else { menuItem->SetItemLabel( ( item + TXT( " (missing)" ) ).c_str() ); menuItem->Enable( false ); } m_MenuItemIDToString.insert( M_MenuItemIDToString::value_type( menuItem->GetId(), item ) ); } }
void RebrandingHelper::ApplyBranding(wxMenu & menu, wxString scope) { size_t separatorIndex = 0; wxMenuItemList & itemsList = menu.GetMenuItems(); for(auto itemIt = itemsList.begin(); itemIt != itemsList.end();++itemIt) { wxMenuItem * item = *itemIt; if (!item) continue; wxString name = menu.GetLabelText(item->GetId()); if (item->GetId() == wxID_SEPARATOR) { name = "Separator_"; name << separatorIndex; separatorIndex++; } wxString itemScope = scope + "." + name; if (ShouldDelete(itemScope)) menu.Destroy(item); else if (ShouldRename(itemScope)) item->SetItemLabel(GetNewName(itemScope)); } }