RE: [gtk-list] Re: gtk_clist_set_sort_column (?)



the sort_column you may specify is mainly useful for the default_sort
provided by the
same gtk_clist. if you want to provide your own (like *MyStrcmp*),
then you can also check the list->row_column inside your code and it's not
a bad idea...
now if your MyStrcmp is actually a strcmp.. just use the default sort as it
does exactly
what you want... if your MyStrcmp compare strings a different way,
say you have
gint MyStrcmp(gchar *t1, gchar *t2)
{
    g_return_val_if_fail(t1, 0);
    g_return_val_if_fail(t2, 0);

    return(atoi(t2)-atoi(t1));
}
(for instance)

then you'd do something like this :
     gtk_clist_set_compare_func(GTK_CLIST(main_clist),
     (GtkCListCompareFunc)MyStrcmpSort);

and have:

static gint MyStrcmpSort(GtkCList      *list,
         GtkCListRow *row1,
         GtkCListRow *row2)
{
     /* ok it's not too clean, ou should check if the cell is text or
pixtext and potentially use
        GTK_CELL_PICTEXT(blahblah)->text, but you got the idea)  */
    return(MyStrcmp(GTK_CELL_TEXT(row1->cell[list->sort_column])->text,
    GTK_CELL_TEXT(row2->cell[list->sort_column])->text));
}

good luck...

Olivier.


>You are misunderstanding what gtk_clist_set_sort_column() does...
>One thing you should understand is that the CList is a list of ROWS.  Not
columns.
>
>Your data exists as a group of rows.  When you change set_sort_column()
>all you are doing is telling the CList what column to use to sort the ROWS.
>The whole row, and nothing but the row...  To manipulate columns
>independantly of row, you should have that data in a seperate CList.
>If the contents of column 3 are not associated with col's 1 and 2, then
they
>should not be in the same CList.
>
>-Steve
>
>> Hi,
>>
>> I am kinda phreak'n out here, all I want to do is sort <n> column of my
>> clist I made.  It keeps on sorting column 0 (first column) no matter what
>> I do. Using gtk version 1.2.5.
>>
>> Code snippet (trying to sort column 4 or any column minus 0):
>>
>>    gtk_clist_set_sort_column(GTK_CLIST(main_clist), 3);
>>    gtk_clist_set_sort_type(GTK_CLIST(main_clist), GTK_SORT_ASCENDING);
>>    gtk_clist_set_compare_func(GTK_CLIST(main_clist),
>> (GtkCListCompareFunc)MyStrcmp);
>>     gtk_clist_set_auto_sort(GTK_CLIST(main_clist), TRUE);
>>
>> Did I miss/mess up something?
>>
>> Paul
>>




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]