GTK+ Forums Forum Index GTK+ Forums
Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

GtkTreeView sort function - C

 
Post new topic   Reply to topic    GTK+ Forums Forum Index -> GTK+ Example Code
Author Message
guillermohurta



Joined: 11 Mar 2008
Posts: 4

PostPosted: Wed Mar 12, 2008 2:25 am    Post subject: GtkTreeView sort function - C Reply with quote

I hope somebody finds helpful this function. I use it to sort columns of a GtkTreeView:

Code: (Plaintext)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54

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 */

Back to top
Display posts from previous:   
Post new topic   Reply to topic    GTK+ Forums Forum Index -> GTK+ Example Code All times are GMT
Page 1 of 1

 


Powered by phpBB © 2001, 2005 phpBB Group
CodeBB 1.0 Beta 2
Protected by Anti-Spam ACP