void RemoveNotifier( wxDataViewModelNotifier *notifier );
// default compare function
- virtual int Compare( const wxDataViewItem &item1, const wxDataViewItem &item2 );
-
- void SetSortingColumn( unsigned int col ) { m_sortingColumn = col; }
- unsigned int GetSortingColumn() { return m_sortingColumn; }
+ virtual int Compare( const wxDataViewItem &item1, const wxDataViewItem &item2,
+ unsigned int column, bool ascending );
protected:
// the user should not delete this class directly: he should use DecRef() instead!
virtual ~wxDataViewModel() { }
wxDataViewModelNotifiers m_notifiers;
- unsigned int m_sortingColumn;
};
// ---------------------------------------------------------
// compare based on index
- virtual int Compare( const wxDataViewItem &item1, const wxDataViewItem &item2 );
+ virtual int Compare( const wxDataViewItem &item1, const wxDataViewItem &item2,
+ unsigned int column, bool ascending );
// implement base methods
// override sorting to always sort branches ascendingly
- int Compare( const wxDataViewItem &item1, const wxDataViewItem &item2 )
+ int Compare( const wxDataViewItem &item1, const wxDataViewItem &item2,
+ unsigned int column, bool ascending )
{
if (IsContainer(item1) && IsContainer(item2))
{
return litem1-litem2;
}
- return wxDataViewModel::Compare( item1, item2 );
+ return wxDataViewModel::Compare( item1, item2, column, ascending );
}
// implementation of base class virtuals to define model
wxDataViewModel::wxDataViewModel()
{
m_notifiers.DeleteContents( true );
- m_sortingColumn = 0;
}
bool wxDataViewModel::ItemAdded( const wxDataViewItem &parent, const wxDataViewItem &item )
m_notifiers.DeleteObject( notifier );
}
-int wxDataViewModel::Compare( const wxDataViewItem &item1, const wxDataViewItem &item2 )
+int wxDataViewModel::Compare( const wxDataViewItem &item1, const wxDataViewItem &item2,
+ unsigned int column, bool ascending )
{
// sort branches before leaves
bool item1_is_container = IsContainer(item1);
return -1;
wxVariant value1,value2;
- GetValue( value1, item1, m_sortingColumn );
- GetValue( value2, item2, m_sortingColumn );
+ GetValue( value1, item1, column );
+ GetValue( value2, item2, column );
+
+ if (!ascending)
+ {
+ wxVariant temp = value1;
+ value1 = value2;
+ value2 = temp;
+ }
if (value1.GetType() == wxT("string"))
{
// items must be different
unsigned long litem1 = (unsigned long) item1.GetID();
unsigned long litem2 = (unsigned long) item2.GetID();
+
+ if (!ascending)
+ return litem2-litem2;
return litem1-litem2;
}
return wxDataViewItem( m_hash[row] );
}
-int wxDataViewIndexListModel::Compare( const wxDataViewItem &item1, const wxDataViewItem &item2 )
+int wxDataViewIndexListModel::Compare( const wxDataViewItem &item1, const wxDataViewItem &item2,
+ unsigned int column, bool ascending )
{
- return GetRow(item1) - GetRow(item2);
+ if (ascending)
+ return GetRow(item1) - GetRow(item2);
+
+ return GetRow(item2) - GetRow(item1);
}
void wxDataViewIndexListModel::GetValue( wxVariant &variant,
void SetSortOrder( GtkSortType sort_order ) { m_sort_order = sort_order; }
GtkSortType GetSortOrder() { return m_sort_order; }
+
+ void SetSortColumn( unsigned int column ) { m_sort_column = column; }
+ unsigned int GetSortColumn() { return m_sort_column; }
protected:
void InitTree();
GtkWxTreeModel *m_gtk_model;
wxDataViewCtrl *m_owner;
GtkSortType m_sort_order;
+ unsigned int m_sort_column;
};
int LINKAGEMODE wxGtkTreeModelNodeCmp( void* id1, void* id2 )
{
- int ret = g_internal->GetDataViewModel()->Compare( id1, id2 );
- if (g_internal->GetSortOrder() == GTK_SORT_DESCENDING)
- return -ret;
+ int ret = g_internal->GetDataViewModel()->Compare( id1, id2,
+ g_internal->GetSortColumn(), (g_internal->GetSortOrder() == GTK_SORT_ASCENDING) );
+
return ret;
}
g_return_val_if_fail (GTK_IS_WX_TREE_MODEL (sortable), FALSE);
if (sort_column_id)
- *sort_column_id = tree_model->internal->GetDataViewModel()->GetSortingColumn();
+ *sort_column_id = tree_model->internal->GetSortColumn();
if (order)
*order = tree_model->internal->GetSortOrder();
GtkWxTreeModel *tree_model = (GtkWxTreeModel *) sortable;
g_return_if_fail (GTK_IS_WX_TREE_MODEL (sortable) );
- if ((sort_column_id == (gint) tree_model->internal->GetDataViewModel()->GetSortingColumn()) &&
+ if ((sort_column_id == (gint) tree_model->internal->GetSortColumn()) &&
(order == tree_model->internal->GetSortOrder()))
return;
- tree_model->internal->GetDataViewModel()->SetSortingColumn( sort_column_id );
+ tree_model->internal->SetSortColumn( sort_column_id );
tree_model->internal->SetSortOrder( order );
m_gtk_model = gtk_model;
m_root = NULL;
m_sort_order = GTK_SORT_ASCENDING;
+ m_sort_column = 0;
InitTree();
}