Re: GtkCList compare function?



I never used it but I know a few little things maybe it will help you...

In the API on the web site it is said that the compare function should
return :
"0 if the nodes are equal, less than 0 if the first node should come before
the second, and greater than 1 if the second come before the first. " So I
think it is the same behaviour as the strcmp function.

In the gtk_clist.c source you can find the code of the function :
void
gtk_clist_set_compare_func (GtkCList            *clist,
       GtkCListCompareFunc  cmp_func)
{
  g_return_if_fail (clist != NULL);
  g_return_if_fail (GTK_IS_CLIST (clist));

  clist->compare = (cmp_func) ? cmp_func : default_compare;
}

So if you pass NULL, then the default function will be retored :-)


And here is the code of the default compare function, in case it inspires
you:
static gint
default_compare (GtkCList      *clist,
   gconstpointer  ptr1,
   gconstpointer  ptr2)
{
  char *text1 = NULL;
  char *text2 = NULL;

  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;

  return strcmp (text1, text2);
}



Best regards,
---
Jean-Christophe Berthon

Cap Gemini -- Ernst & Young
France
Skill IS -- Image Quality
Email: Jean-Christophe Berthon cgey com
Tel: (+33) 561 31 6671


----- Original Message -----
From: "Taura Milana" <learfox furry ao net>
To: "GTK App Devel" <gtk-app-devel-list gnome org>
Sent: Friday, January 18, 2002 11:38 AM
Subject: GtkCList compare function?


Hi, I need to write a GtkCList compare function to compare
two strings that contain file sizes, I found the prototype:

typedef gint (*GtkCListCompareFunc) (GtkCList     *clist,
                                     gconstpointer ptr1,
                                     gconstpointer ptr2);

But does that mean the two gconstpointer inputs are
const gchar * pointers to null terminated strings?

What should the return value be?

Also how do I set the compare function *back* to the default?
Just pass NULL to gtk_clist_set_compare_func()?


--
Sincerely,                  ,"-_                         \|/
-Capt. Taura M.             ,   O=__                    --X--
..__                         ,_JNMNNEO=_                 /|\
OMNOUMmnne.                  {OMMNNNEEEEOO=_
UOOOBIOOOEOMMn.               'LONMMMMNNEEEOOO=.__..,,..
UUOOEUUOOOOOOOObe              '"=OMMMMWNEEEOOOOO,"=OEEEOO=,._
OOUUUIEEIOONNOIUbe.                "7OMMMMNNNNNWWEEEEOOOOOO"   "'.
EEBNNMMMNWNWWEEIMMNe.             __  7EMMMNNNNNWWWEEEEEEEOO.     " .
NNMMMMWWWMMMWEINMMMNn            "=BBEEEEMMMMMMMMNNNWWWEEOOOOO=._     .
                  http://furry.ao.net/~learfox/
_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list gnome org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list




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