GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Wed Oct 22, 2014 9:38 pm

All times are UTC




Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: GtkTreeView Redundant Selection Callbacks
PostPosted: Wed Feb 13, 2008 11:05 am 
Offline
Familiar Face

Joined: Wed Oct 03, 2007 12:28 pm
Posts: 25
Location: Virginia (Northern)
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=]
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 */
[/code]

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


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: Google [Bot], Yahoo [Bot] 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:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group