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 Redundant Selection Callbacks

 
Post new topic   Reply to topic    GTK+ Forums Forum Index -> GTK+ Programming
Author Message
kharrison
Familiar Face


Joined: 03 Oct 2007
Posts: 25
Location: Virginia (Northern)

PostPosted: Wed Feb 13, 2008 11:05 am    Post subject: GtkTreeView Redundant Selection Callbacks Reply with quote

I have created a GtkTreeView (with the GTK_SELECTION_SINGLE property) and my objective is to invoke a callback function whenever a user selects a row. After a brief struggle I ALMOST have it working the way I want it to. The problem is that I get a callback when the row is "selected" (which I want), another callback when the previous row that was selected is automatically "deselected" (which I don't mind ignoring), and then finally ANOTHER callback for the row that was selected.

Here is a simplified example:
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

void create_tree_view()
{
   GtkTreeView *view = gtk_tree_view_new();
   GtkTreeSelection *selection = gtk_tree_view_get_selection( view );
   ...
   //  Set up my view and attach to GtkListStore model
   ...
   gtk_tree_selection_set_select_function
      (
           selection,
           select_row_callback,
           NULL,
           NULL
       );
   ...
} /* create_tree_view() */

gboolean select_row_callback
(
   GtkTreeSelection *selection,
   GtkTreeModel      *model,
   GtkTreePath        *path,
   gboolean                path_currently_selected,
   gpointer                  data
)
{
    GtkTreeIter iter;

    if (gtk_tree_model_get_iter(model, &iter, path))
    {
        /* Retrieve a value from the model... not really important for this example */
        gchar *value;
        gtk_tree_model_get(model, &iter, POS_0, &value, -1);

        /* Print something out to determine why this was called */
        if (!path_currently_selected)
        {
           g_print ("%s is going to be selected.\n", value);
        }
        else
        {
           g_print ("%s is going to be unselected.\n", value);
        }

        g_free(value);

} /* select_row_callback */


So my output from the above is:

Row-2 is going to be selected.
Row-1 is going to be unselected.
Row-2 is going to be selected. <== WHY??? This was already processed.

The last callback is undesirable, I have already processed the selection at this point. I guess I should add that this problem only occurs AFTER the first selection as it is related to the previous row being deselected.

I'd appreciate any input, advice, or insight.
Thanks in advance!
Kirk
Back to top
Display posts from previous:   
Post new topic   Reply to topic    GTK+ Forums Forum Index -> GTK+ Programming 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