Skip to content

Commit

Permalink
Fix inserting multiple items to wxRearrangeList
Browse files Browse the repository at this point in the history
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 wxWidgets#17836.
  • Loading branch information
a-wi committed Apr 28, 2017
1 parent 2cf3a3d commit d5c46e8
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
1 change: 1 addition & 0 deletions docs/changes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
2 changes: 2 additions & 0 deletions include/wx/rearrangectrl.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ class WXDLLIMPEXP_CORE wxRearrangeList : public wxCheckListBox
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;

Expand Down
18 changes: 16 additions & 2 deletions src/common/rearrangectrl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit d5c46e8

Please sign in to comment.