+bool wxDataViewSortedListModel::ChildRowChanged( 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::RowChanged( 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;
+}
+
+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;
+}
+
+bool wxDataViewSortedListModel::ChildRowsReordered( size_t *WXUNUSED(new_order) )
+{
+ // Nothing needs to be done. If the sort criteria
+ // of this list don't change, the order of the
+ // items of the child list isn't relevant.
+ return true;
+}
+
+bool wxDataViewSortedListModel::ChildCleared()
+{
+ return wxDataViewListModel::Cleared();
+}
+
+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 );
+
+ // Do nothing here as the change in the
+ // child model will be reported back.
+
+ return ret;
+}
+
+bool wxDataViewSortedListModel::RowAppended()
+{
+ // you can only append
+ bool ret = m_child->RowAppended();
+
+ // Do nothing here as the change in the
+ // child model will be reported back.
+
+ return ret;
+}
+
+bool wxDataViewSortedListModel::RowPrepended()
+{
+ // you can only append
+ bool ret = m_child->RowAppended();
+
+ // Do nothing here as the change in the
+ // child model will be reported back.
+
+ return ret;
+}
+
+bool wxDataViewSortedListModel::RowInserted( size_t WXUNUSED(before) )
+{
+ // you can only append
+ bool ret = m_child->RowAppended();
+
+ // Do nothing here as the change in the
+ // child model will be reported back.
+
+ 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();
+
+ // Do nothing here as the change in the
+ // child model will be reported back.
+
+ return ret;
+}
+
+// ---------------------------------------------------------