Re: A Question about GtkTreeSortable
- From: Iago Rubio <iago iagorubio com>
- To: gtk-app-devel-list gnome org
- Subject: Re: A Question about GtkTreeSortable
- Date: Fri, 21 Oct 2005 11:12:51 +0200
On Thu, 2005-10-20 at 17:44 +0200, Iago Rubio wrote:
[snip]
gint
your_tree_iter_compare_func (GtkTreeModel *model,
GtkTreeIter *a,
GtkTreeIter *b,
gpointer user_data)
{
GtkTreePath* path_first;
GtkTreePath* path_a;
GtkTreePath* path_b;
first_path = gtk_tree_path_new_first();
path_a = gtk_tree_model_get_path (model,a);
path_b = gtk_tree_model_get_path (model,b);
if( gtk_tree_path_compare(path_first, path_a) == 0 ){
return -1; // "a" is first so "a" always sorts before
}else if ( gtk_tree_path_compare(path_first, path_b) == 0 ){
return 1; // "b" is first so "a" always sorts after
}
Viewing searun full code I realized this implementation is bogus, as it
depends on GtkSortType.
A better implementation should be:
gint
your_tree_iter_compare_func (GtkTreeModel *model,
GtkTreeIter *a,
GtkTreeIter *b,
gpointer user_data)
{
GtkTreePath* path_first;
GtkTreePath* path_a;
GtkTreePath* path_b;
GtkSortType sort_type;
gint sortcol, retval = 0;
gtk_tree_sortable_get_sort_column_id (
GTK_TREE_SORTABLE(model),
&sortcol,
&sort_type);
first_path = gtk_tree_path_new_first();
path_a = gtk_tree_model_get_path (model,a);
path_b = gtk_tree_model_get_path (model,b);
if( sort_type == GTK_SORT_ASCENDING ){
if( gtk_tree_path_compare(path_first, path_a) == 0 )
retval = -1;
else if ( gtk_tree_path_compare(path_first, path_b) == 0 )
retval = 1;
} else {
if( gtk_tree_path_compare(path_first, path_a) == 0 )
retval = 1;
else if ( gtk_tree_path_compare(path_first, path_b) == 0 )
retval = -1;
}
if ( retval ){
gtk_tree_path_free(path_first);
gtk_tree_path_free(path_a);
gtk_tree_path_free(path_b);
return retval;
}
// none of both are first so compare them
.....
gtk_tree_path_free(path_first);
gtk_tree_path_free(path_a);
gtk_tree_path_free(path_b);
}
--
Iago Rubio
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]