GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Mon Apr 21, 2014 4:38 am

All times are UTC




Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: GtkTreeView sort function - C
PostPosted: Wed Mar 12, 2008 2:25 am 
Offline

Joined: Tue Mar 11, 2008 8:58 pm
Posts: 4
I hope somebody finds helpful this function. I use it to sort columns of a GtkTreeView:

Code:
gint sort_function (GtkTreeModel *model,GtkTreeIter *a,GtkTreeIter *b, gpointer userdata)
{
   gint sortcol = GPOINTER_TO_INT(userdata);
   gint ret = 0;
   switch (sortcol)
   {
      case SORT_COLUMN_X:
         {
            gchar *name1, *name2;
            gtk_tree_model_get(model, a, COLUMN_X &name1, -1);
            gtk_tree_model_get(model, b, COLUMN_X, &name2, -1);
            if (name1 == NULL || name2 == NULL)
            {
               if (name1 == NULL && name2 == NULL)
               break; /* both equal => ret = 0 */
               ret = (name1 == NULL) ? -1 : 1;
            }
            else
            {
               ret = g_utf8_collate(name1,name2);
            }
            g_free(name1);
            g_free(name2);
         }
         break;

      case SORT_COLUMN_Y:
         {
            gchar *name1, *name2;
            gtk_tree_model_get(model, a, SORT_COLUMN_Y, &name1, -1);
            gtk_tree_model_get(model, b, SORT_COLUMN_Y &name2, -1);
            if (name1 == NULL || name2 == NULL)
            {
               if (name1 == NULL && name2 == NULL)
               break; /* both equal => ret = 0 */
               ret = (name1 == NULL) ? -1 : 1;
            }
            else
            {
               ret = g_utf8_collate(name1,name2);
            }
            g_free(name1);
            g_free(name2);
         }
         break;

      default:
         g_return_val_if_reached(0);
     }
   return ret;
}/* sort_function */



Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group