+wxDataViewSortedListModel::~wxDataViewSortedListModel()
+{
+ m_child->RemoveNotifier( m_notifierOnChild );
+}
+
+void wxDataViewSortedListModel::Resort()
+{
+ m_array.Clear();
+ size_t n = m_child->GetNumberOfRows();
+ size_t i;
+ for (i = 0; i < n; i++)
+ m_array.Add( i );
+}
+
+#if 0
+static void Dump( wxDataViewListModel *model, size_t col )
+{
+ size_t n = model->GetNumberOfRows();
+ size_t i;
+ for (i = 0; i < n; i++)
+ {
+ wxVariant variant;
+ model->GetValue( variant, col, i );
+ wxString tmp;
+ tmp = variant.GetString();
+ wxPrintf( wxT("%d: %s\n"), (int) i, tmp.c_str() );
+ }
+}
+#endif
+
+bool wxDataViewSortedListModel::ChildValueChanged( size_t col, size_t row )
+{
+ size_t i;
+ size_t len = m_array.GetCount();
+
+ // Remove and readd sorted. Find out at which
+ // position it was and where it ended.
+ size_t start_pos = 0,end_pos = 0;
+ for (i = 0; i < len; i++)
+ if (m_array[i] == row)
+ {
+ start_pos = i;
+ break;
+ }
+ m_array.RemoveAt( start_pos );
+ m_array.Add( row );
+
+ for (i = 0; i < len; i++)
+ if (m_array[i] == row)
+ {
+ end_pos = i;
+ break;
+ }
+
+ if (end_pos == start_pos)
+ return wxDataViewListModel::ValueChanged( col, start_pos );
+
+ // Create an array where order[old] -> new_pos, so that
+ // if nothing changed order[0] -> 0 etc.
+ size_t *order = new size_t[ len ];
+ // Fill up initial values.
+ for (i = 0; i < len; i++)
+ order[i] = i;
+
+ if (start_pos < end_pos)
+ {
+ for (i = start_pos; i < end_pos; i++)
+ order[i] = order[i+1];
+ order[end_pos] = start_pos;
+ }
+ else
+ {
+ for (i = end_pos; i > start_pos; i--)
+ order[i] = order[i-1];
+ order[start_pos] = end_pos;
+ }
+
+ wxDataViewListModel::RowsReordered( order );
+
+ delete [] order;
+
+ return true;
+}
+
+size_t wxDataViewSortedListModel::GetNumberOfRows()
+{
+ return m_array.GetCount();
+}
+
+size_t wxDataViewSortedListModel::GetNumberOfCols()
+{
+ return m_child->GetNumberOfCols();
+}
+
+wxString wxDataViewSortedListModel::GetColType( size_t col )
+{
+ return m_child->GetColType( col );
+}
+
+void wxDataViewSortedListModel::GetValue( wxVariant &variant, size_t col, size_t row )
+{
+ size_t child_row = m_array[row];
+ m_child->GetValue( variant, col, child_row );
+}
+
+bool wxDataViewSortedListModel::SetValue( wxVariant &variant, size_t col, size_t row )
+{
+ size_t child_row = m_array[row];
+ bool ret = m_child->SetValue( variant, col, child_row );
+
+ // Resort in ::ChildValueChanged() which gets reported back.
+
+ return ret;
+}
+
+bool wxDataViewSortedListModel::RowAppended()
+{
+ // you can only append
+ bool ret = m_child->RowAppended();
+
+ // report RowInsrted
+
+ return ret;
+}
+
+bool wxDataViewSortedListModel::RowPrepended()
+{
+ // you can only append
+ bool ret = m_child->RowAppended();
+
+ // report RowInsrted
+
+ return ret;
+}
+
+bool wxDataViewSortedListModel::RowInserted( size_t WXUNUSED(before) )
+{
+ // you can only append
+ bool ret = m_child->RowAppended();
+
+ // report different RowInsrted
+
+ return ret;
+}
+
+bool wxDataViewSortedListModel::RowDeleted( size_t row )
+{
+ size_t child_row = m_array[row];
+
+ bool ret = m_child->RowDeleted( child_row );
+
+ // Do nothing here as the change in the
+ // child model will be reported back.
+
+ return ret;
+}
+
+bool wxDataViewSortedListModel::RowChanged( size_t row )
+{
+ size_t child_row = m_array[row];
+ bool ret = m_child->RowChanged( child_row );
+
+ // Do nothing here as the change in the
+ // child model will be reported back.
+
+ return ret;
+}
+
+bool wxDataViewSortedListModel::ValueChanged( size_t col, size_t row )
+{
+ size_t child_row = m_array[row];
+ bool ret = m_child->ValueChanged( col, child_row );
+
+ // Do nothing here as the change in the
+ // child model will be reported back.
+
+ return ret;
+}
+
+bool wxDataViewSortedListModel::RowsReordered( size_t *WXUNUSED(new_order) )
+{
+ // We sort them ourselves.
+
+ return false;
+}
+
+bool wxDataViewSortedListModel::Cleared()
+{
+ bool ret = m_child->Cleared();
+
+ wxDataViewListModel::Cleared();
+
+ return ret;
+}
+
+// ---------------------------------------------------------