Order array has to have the same size as item list in wxRearrangeList
Number of indices stored in the internal order array has to be the same as number of the items, so whenever item is added or removed, order array has to be adjusted accordingly. Closes #17836.
This commit is contained in:
@@ -99,6 +99,10 @@ public:
|
|||||||
// Override this to keep our m_order array in sync with the real item state.
|
// Override this to keep our m_order array in sync with the real item state.
|
||||||
virtual void Check(unsigned int item, bool check = true) wxOVERRIDE;
|
virtual void Check(unsigned int item, bool check = true) wxOVERRIDE;
|
||||||
|
|
||||||
|
int DoInsertOneItem(const wxString& item, unsigned int pos) wxOVERRIDE;
|
||||||
|
void DoDeleteOneItem(unsigned int n) wxOVERRIDE;
|
||||||
|
void DoClear() wxOVERRIDE;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// swap two items at the given positions in the listbox
|
// swap two items at the given positions in the listbox
|
||||||
void Swap(int pos1, int pos2);
|
void Swap(int pos1, int pos2);
|
||||||
|
@@ -70,6 +70,7 @@ bool wxRearrangeList::Create(wxWindow *parent,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// do create the real control
|
// do create the real control
|
||||||
|
m_order.reserve(count);
|
||||||
if ( !wxCheckListBox::Create(parent, id, pos, size, itemsInOrder,
|
if ( !wxCheckListBox::Create(parent, id, pos, size, itemsInOrder,
|
||||||
style, validator, name) )
|
style, validator, name) )
|
||||||
return false;
|
return false;
|
||||||
@@ -83,10 +84,9 @@ bool wxRearrangeList::Create(wxWindow *parent,
|
|||||||
// which would also update m_order itself.
|
// which would also update m_order itself.
|
||||||
wxCheckListBox::Check(n);
|
wxCheckListBox::Check(n);
|
||||||
}
|
}
|
||||||
|
m_order[n] = order[n];
|
||||||
}
|
}
|
||||||
|
|
||||||
m_order = order;
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -188,6 +188,46 @@ void wxRearrangeList::OnCheck(wxCommandEvent& event)
|
|||||||
m_order[n] = ~m_order[n];
|
m_order[n] = ~m_order[n];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int wxRearrangeList::DoInsertOneItem(const wxString& item, unsigned int pos)
|
||||||
|
{
|
||||||
|
wxCheckListBox::DoInsertOneItem(item, pos);
|
||||||
|
// Item is not checked initially.
|
||||||
|
const int idx = ~m_order.size();
|
||||||
|
m_order.Insert(idx, pos);
|
||||||
|
return pos;
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxRearrangeList::DoDeleteOneItem(unsigned int n)
|
||||||
|
{
|
||||||
|
wxCheckListBox::DoDeleteOneItem(n);
|
||||||
|
int idxDeleted = m_order[n];
|
||||||
|
if ( idxDeleted < 0 )
|
||||||
|
idxDeleted = ~idxDeleted;
|
||||||
|
m_order.RemoveAt(n);
|
||||||
|
// Remaining items have to be reindexed.
|
||||||
|
for( size_t i = 0; i < m_order.size(); i++ )
|
||||||
|
{
|
||||||
|
int idx = m_order[i];
|
||||||
|
if ( idx < 0 )
|
||||||
|
{
|
||||||
|
idx = ~idx;
|
||||||
|
if ( idx > idxDeleted )
|
||||||
|
m_order[i] = ~(idx-1);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if ( idx > idxDeleted )
|
||||||
|
m_order[i] = idx-1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxRearrangeList::DoClear()
|
||||||
|
{
|
||||||
|
wxCheckListBox::DoClear();
|
||||||
|
m_order.Clear();
|
||||||
|
}
|
||||||
|
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
// wxRearrangeCtrl implementation
|
// wxRearrangeCtrl implementation
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
|
Reference in New Issue
Block a user