Re: [gtk-list] Re: Question about sorting a CLIST
- From: Martin Norb{ck <d95mback dtek chalmers se>
- To: gtk-list redhat com
- Subject: Re: [gtk-list] Re: Question about sorting a CLIST
- Date: Tue, 16 Nov 1999 16:48:01 +0100
Tue Nov 16 1999, Martin Norb{ck ->
> Mon Nov 15 1999, Raul Dias ->
> > Hi again,
> >
> > I have two questions about sorting a clist.
> > The first one.
> >
> > Is there any other sorting type, other than ascending and descending?
> > Like numeric. Or I have to implement that in my app?
>
> I had the same problem, so I just cut'n'pasted the code from gtkclist.c
> and changed it a bit. Look at the bottom of this message.
Ooops, forgot to attach the code :) here it is:
(It could be trimmed down a bit if you don't have pixtexts)
// Used as a comparing function to sort numerically
static gint
numeric_compare (GtkCList *clist,
gconstpointer ptr1,
gconstpointer ptr2)
{
char *text1 = NULL;
char *text2 = NULL;
int val1;
int val2;
GtkCListRow *row1 = (GtkCListRow *) ptr1;
GtkCListRow *row2 = (GtkCListRow *) ptr2;
switch (row1->cell[clist->sort_column].type)
{
case GTK_CELL_TEXT:
text1 = GTK_CELL_TEXT (row1->cell[clist->sort_column])->text;
break;
case GTK_CELL_PIXTEXT:
text1 = GTK_CELL_PIXTEXT (row1->cell[clist->sort_column])->text;
break;
default:
break;
}
switch (row2->cell[clist->sort_column].type)
{
case GTK_CELL_TEXT:
text2 = GTK_CELL_TEXT (row2->cell[clist->sort_column])->text;
break;
case GTK_CELL_PIXTEXT:
text2 = GTK_CELL_PIXTEXT (row2->cell[clist->sort_column])->text;
break;
default:
break;
}
if (!text2)
return (text1 != NULL);
if (!text1)
return -1;
val1 = atoi (text1);
val2 = atoi (text2);
if (val1 > val2)
return 1;
if (val1 < val2)
return -1;
return 0;
}
--
[ http://www.dtek.chalmers.se/~d95mback/ ] [ PGP: 0x453504F1 ] [ UIN: 4439498 ]
Opinions expressed above are mine, and not those of my future employees.
Skingra er! Det finns ingenting att förstå!
PGP signature
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]