Re: [gtk-list] CList sorting (GtkCListCompareFunc ())



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

Rather than answering your question directly, I'll just offer
this GtkCListCompareFunc that does floating point arithmetic
comparison; the built-in function sorts in alphabetical order.

gint
arithmetic_compare (GtkCList *cl, gconstpointer ptr1, gconstpointer ptr2)
{
  const GtkCListRow *row1 = (const GtkCListRow *) ptr1;
  const GtkCListRow *row2 = (const GtkCListRow *) ptr2;
  gchar *text1 = null;
  gchar *text2 = null;
  gfloat f1, f2;

  text1 = GTK_CELL_TEXT (row1->cell[cl->sort_column])->text;
  text2 = GTK_CELL_TEXT (row2->cell[cl->sort_column])->text;

  f1 = atof (text1);
  f2 = atof (text2);

  return ((f1 < f2) ? -1 : (f1 > f2) ? 1 : 0);
}

This little function swaps between them depending on the column:

void sortbycolumn_cb (GtkWidget *cl, gint column, gpointer data)
{
  gtk_clist_set_sort_column (GTK_CLIST (clist), column);
  if (column == 1)  /*-- variable name --*/
    gtk_clist_set_compare_func (GTK_CLIST (clist), NULL);
  else
    gtk_clist_set_compare_func (GTK_CLIST (clist),
                                (GtkCListCompareFunc) arithmetic_compare);
  gtk_clist_sort (GTK_CLIST (clist));
}

Debby



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