Re: GtkTreeView: getting selection
- From: ginxd <ginxd btopenworld com>
- To: Romain Lievin <rlievin free fr>
- Cc: gtk-app-devel-list gnome org
- Subject: Re: GtkTreeView: getting selection
- Date: Fri, 29 Nov 2002 16:30:12 +0000
Romain Lievin wrote:
Hi,
I am developping the GTK+ version of the new 2.5 kernel configurator...
I am using GtkTreeModel & GtkTreeView for displaying a tree.
I would like to retrieve the row and column which have been clicked by the
user.
The code below works unless you horizontally scroll the view.
Why ?
Is there any better way for doing this ?
I would tend to make a function that returns the values you want as below:
gboolean model_get_selection(gchar **name, gchar **jid)
{
GtkTreeSelection *selection;
GtkTreeModel *model = GTK_TREE_MODEL(treestore);
GtkTreeIter iter;
if(name == NULL || jid == NULL)
{
g_warning("model_get_selection: name or JID pointers passed were
NULL");
return FALSE;
}
selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(treeview));
if(gtk_tree_selection_get_selected(selection,&model,&iter) == FALSE)
return FALSE;
gtk_tree_model_get(model, &iter,
COL_ROSTER_NAME, name,
COL_ROSTER_JID, jid,
-1);
return TRUE;
}
Note. This doesnt work for mutliple selections.
Hope it helps,
Martyn
Thanks, Romain.
[================ snippet ======================]
gboolean
on_treeview1_button_press_event (GtkWidget *widget,
GdkEventButton *event,
gpointer user_data)
{
GtkTreeView *view = GTK_TREE_VIEW (tree_wnd);
GtkTreePath *path;
GtkTreeViewColumn *column;
GtkTreeIter iter;
struct menu *menu;
gint cx, cy;
gint tx, ty;
gint wx, wy;
tx = event->x;
ty = event->y;
gtk_tree_view_tree_to_widget_coords (view, tx, ty, &wx, &wy);
gtk_tree_view_get_path_at_pos (view, wx, wy, &path, &column, &cx, &cy);
//printf("%i %i %i %i %i %i\n", tx, ty, wx, wy, cx, cy);
gtk_tree_view_get_cursor (view, &path, &column);
if(path == NULL) {
g_warning("button_press_event: path is NULL !\n");
return FALSE;
}
gtk_tree_model_get_iter (model, &iter, path);
gtk_tree_model_get (model, &iter, PTR_COLUMN, &menu, -1);
change_sym_value(menu, column2index(column));
set_node(&iter, menu, fill_row(menu));
return FALSE;
}
[================ snippet ======================]
_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list gnome org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]