//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); } } }
//Hack to allow use (events) of wxmenu inside a tool like simpletexttool void ddDrawingView::setTextPopUpList(wxArrayString &strings, wxMenu &mnu) { //DD-TODO: choose a better id for event mnu.Disconnect(wxEVT_COMMAND_MENU_SELECTED,(wxObjectEventFunction)(wxEventFunction) (wxCommandEventFunction) &ddDrawingView::OnTextPopupClick,NULL,this); int sz = strings.size(); //to avoid warning wxMenuItem *item = NULL; wxMenu *submenu = NULL; bool isSubItem; bool subItemsDisable=false; for(int i=0 ; i < sz ; i++){ //DD-TODO: only create options for what I need, this can be improved later //String "--submenu##menu item**sub menu title" and "--subitem--" create and add items to last created submenu isSubItem=false; item=NULL; if(strings[i].Contains(wxT("--submenu"))) { if(strings[i].Contains(wxT("--disable"))) subItemsDisable=true; else subItemsDisable=false; submenu = new wxMenu(strings[i].SubString(strings[i].find(wxT("**"))+2,strings[i].length())); mnu.AppendSubMenu(submenu,strings[i].SubString(strings[i].find(wxT("##"))+2,strings[i].find(wxT("**"))-1)); } else if(strings[i].Contains(wxT("--subitem"))) { isSubItem=true; if(submenu) { if(strings[i].Contains(wxT("--checked"))) { item=submenu->AppendCheckItem(i,strings[i].SubString(strings[i].find(wxT("**"))+2,strings[i].length())); } else { item=submenu->Append(i,strings[i].SubString(strings[i].find(wxT("**"))+2,strings[i].length())); } } else { wxMessageDialog *error = new wxMessageDialog(NULL, wxT("Error setting text popup strings list"), wxT("Error!"), wxOK | wxICON_ERROR); error->ShowModal(); delete error; } } else if(strings[i].Contains(wxT("--separator--"))) { mnu.AppendSeparator(); } else if(strings[i].Contains(wxT("--checked"))) { item = mnu.AppendCheckItem(i, strings[i].SubString(strings[i].find(wxT("**"))+2,strings[i].length())); } else if(strings[i].Contains(wxT("**"))) { item = mnu.Append(i, strings[i].SubString(strings[i].find(wxT("**"))+2,strings[i].length())); } else { item = mnu.Append(i, strings[i]); } if(item && strings[i].Contains(wxT("--checked"))) { item->Check(true); } if( item && ( strings[i].Contains(wxT("--disable")) || (submenu && isSubItem && subItemsDisable) ) ) { item->Enable(false); } } //DD-TODO: create a better version of this hack mnu.Connect(wxEVT_COMMAND_MENU_SELECTED,(wxObjectEventFunction)(wxEventFunction) (wxCommandEventFunction) &ddDrawingView::OnTextPopupClick,NULL,this); }