From d5c46e87a6d7b11751333706baeeb763c8c908d4 Mon Sep 17 00:00:00 2001 From: Artur Wieczorek Date: Fri, 28 Apr 2017 23:52:24 +0200 Subject: [PATCH] Fix inserting multiple items to wxRearrangeList In wxRearrangeList implementations (like wxMSW) where DoInsertItemsInLoop() and DoInsertOneItem() are not used to insert multiple items, DoInsertItems() has to be overriden to do this insertion. See #17836. --- docs/changes.txt | 1 + include/wx/rearrangectrl.h | 2 ++ src/common/rearrangectrl.cpp | 18 ++++++++++++++++-- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/docs/changes.txt b/docs/changes.txt index 65decfa6ca..b018089c04 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -134,6 +134,7 @@ All (GUI): - Add wxStyledTextCtrl::AutoCompGetCurrentText() (NewPagodi). - Extend wxStyledTextCtrl::FindText() to return end position of matched text (NewPagodi). +- Fix adding/removing items to/from wxRearrangeList. wxGTK: diff --git a/include/wx/rearrangectrl.h b/include/wx/rearrangectrl.h index 7d6e1b0fbc..beb45df2fe 100644 --- a/include/wx/rearrangectrl.h +++ b/include/wx/rearrangectrl.h @@ -100,6 +100,8 @@ public: virtual void Check(unsigned int item, bool check = true) wxOVERRIDE; int DoInsertOneItem(const wxString& item, unsigned int pos) wxOVERRIDE; + int DoInsertItems(const wxArrayStringsAdapter& items, unsigned int pos, + void **clientData, wxClientDataType type) wxOVERRIDE; void DoDeleteOneItem(unsigned int n) wxOVERRIDE; void DoClear() wxOVERRIDE; diff --git a/src/common/rearrangectrl.cpp b/src/common/rearrangectrl.cpp index bbd9564fe3..53795c950f 100644 --- a/src/common/rearrangectrl.cpp +++ b/src/common/rearrangectrl.cpp @@ -190,11 +190,25 @@ void wxRearrangeList::OnCheck(wxCommandEvent& event) int wxRearrangeList::DoInsertOneItem(const wxString& item, unsigned int pos) { - wxCheckListBox::DoInsertOneItem(item, pos); + int ret = wxCheckListBox::DoInsertOneItem(item, pos); // Item is not checked initially. const int idx = ~m_order.size(); m_order.Insert(idx, pos); - return pos; + return ret; +} + +int wxRearrangeList::DoInsertItems(const wxArrayStringsAdapter& items, unsigned int pos, + void **clientData, wxClientDataType type) +{ + int ret = wxCheckListBox::DoInsertItems(items, pos, clientData, type); + const size_t numItems = items.GetCount(); + for ( size_t i = 0; i < numItems; i++ ) + { + // Item is not checked initially. + const int idx = ~m_order.size(); + m_order.Insert(idx, pos+i); + } + return ret; } void wxRearrangeList::DoDeleteOneItem(unsigned int n)