virtual bool OnDropText(wxCoord x, wxCoord y, const wxString& data) { // copy selection as it changes after the list_refresh const elements_type els = static_cast<ElementsCtrlBase*>(m_list->GetParent())->selected_elements(); if( 0 == els.size() ) return false; // no elements selected int flags = wxLIST_HITTEST_BELOW; long hit = hititem(x, y); if( hit == wxNOT_FOUND ) return false; // the drop wasn't over an existing item wxASSERT( m_list->GetItemData(hit) ); #if HAS_CMDPROC ReorderCommand *s = new ReorderCommand(_("Reorder elements")); #endif ElementBase *after = reinterpret_cast<ElementBase*>(m_list->GetItemData(hit)); // move all selected items after the one the cursor is over for( size_t rev = els.size(); rev != 0; --rev ) wxGetApp().hudfile()->move_element_after( els[rev-1], after ); #if HAS_CMDPROC s->takepost(); wxGetApp().cmds()->Submit(s); #endif // TODO simple but expensive ;) hooray (doesn't flicker on MSW, checkcheck for GTK) // Note this is already done in ReorderCommand::Do //static_cast<ElementsCtrlBase*>(m_list->GetParent())->list_refresh(wxGetApp().hudfile()->elements()); // TODO ignore EVT_LIST_ITEM_SELECTED during this loop wxGetApp().elementsctrl()->list_refresh(wxGetApp().hudfile()->elements()); for( cit_elements cit = els.begin(); cit != els.end(); ++cit ) static_cast<ElementsCtrlBase*>(m_list->GetParent())->select_item(*cit); // wxGetApp().mainframe()->elementsctrl()->OnSelectionChanged(); return true; }
bool operator==(const matrix& src) const { if (elements.size() != src.elements.size()) return false; typename elements_type::const_iterator lhs_itor = elements.begin(); typename elements_type::const_iterator rhs_itor = src.elements.begin(); while (lhs_itor != elements.end()) if (*lhs_itor++ != *rhs_itor++) return false; return true; }
void ElementsCtrlBase::list_refresh( const elements_type& elements ) { clear(); for( cit_elements cit = elements.begin(); cit != elements.end(); ++cit ) append(*cit); int collnamecount = Prefs::get().var(wxT("elements_collnamecount")).ival(); if( Prefs::get().var(wxT("elements_collections")).bval() ) { // now insert collection items wxString collname; int collcount = 0; // how many collection titles we already inserted for( size_t i=1; i < elements.size(); ++i ) { if( elements[i]->name().Left(collnamecount) == elements[i-1]->name().Left(collnamecount) && elements[i]->name().Left(collnamecount) != collname) { // we found at least two items, that's enough collname = elements[i]->name().Left(collnamecount); // how many items belong to this collection? size_t g; for( g=i-1; g < elements.size(); ++g ) { if( elements[g]->name().Left(collnamecount) != collname ) break; } // items [i-1,g-1] have same 3 starting characters // maybe they share even more? figeur out int minshare = 666; m_list->SetItem(i-1+collcount, 0, wxEmptyString, E_LIST_IMG_COLLITEM); for( size_t h=i; h <= g-1; ++h ) { m_list->SetItem(h+collcount, 0, wxEmptyString, E_LIST_IMG_COLLITEM); minshare = wxMin(she::common_start(elements[h]->name(), elements[h-1]->name()), minshare); } size_t realinsert = i; /* // also include the previous E_PARENT items. #if COLLECTION_INCLUDES_PARENT for( size_t k=i-2; k>0; --k ) { if( elements[k]->flags() & E_PARENT ) --realinsert; else break; } #endif */ // insert collection title wxListItem li; li.SetMask(wxLIST_MASK_TEXT); li.SetId(realinsert-1+collcount); li.SetFont(*wxITALIC_FONT); li.SetTextColour(ELEMENTS_COLL_COLOR); li.SetBackgroundColour(ELEMENTS_COLL_BGCOLOR); long idx = m_list->InsertItem(li); m_list->SetItem(idx, 0, wxEmptyString, E_LIST_IMG_COLLTITLE); collname = elements[i]->name().Left(minshare); she::wxTrim(collname, wxT("_")); m_list->SetItem(idx, 1, collname, -1); m_list->SetItemData(idx, 0); ++collcount; i = g-1; // skip over values we just put in a collection } } } }