After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 100973 - get_cursor does not report TreeViewColumn correctly.
get_cursor does not report TreeViewColumn correctly.
Status: RESOLVED FIXED
Product: gtk+
Classification: Platform
Component: Widget: GtkTreeView
2.2.x
Other Linux
: High major
: ---
Assigned To: gtktreeview-bugs
gtktreeview-bugs
Depends on:
Blocks:
 
 
Reported: 2002-12-11 20:48 UTC by Dave Cook
Modified: 2011-02-04 16:11 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Adds a cursor_changed callback and a "Report Cursor" button to the editable_cells demo. (2.16 KB, patch)
2003-01-10 09:37 UTC, Dave Cook
none Details | Review

Description Dave Cook 2002-12-11 20:48:53 UTC
This is for v. 2.0.9.

I may misunderstand the API here, but when when I use get_cursor()
from a cursor-changed callback, I only get the right TreeViewColumn
when I'm clicking on a different row.  When clicking on different columns
in the same row, the TreeViewColumn doesn't change.  Here's my callback:

static void
cursor_changed (GtkTreeView *view, gpointer data)
{
   GtkTreePath *path;
   GtkTreeViewColumn *viewcol;
   int i;
   gint *indices;

   gtk_tree_view_get_cursor(view, &path, &viewcol);
   i = 0;
   while (viewcol!=NULL && viewcol!=gtk_tree_view_get_column(view, i))
      i++;
   indices = gtk_tree_path_get_indices(path);
   g_print("(%d, %d)\n", indices[0], i);
   gtk_tree_path_free(path);

}
Comment 1 Dave Cook 2003-01-04 22:10:52 UTC
This is still the case with gtk+ 2.2.0.  I'm upgrading the severity to
major.
Comment 2 Dave Cook 2003-01-10 09:37:17 UTC
Created attachment 13465 [details] [review]
Adds a cursor_changed callback and a "Report Cursor" button to the editable_cells demo.
Comment 3 Dave Cook 2003-01-10 09:38:14 UTC
I'm upping the priority on this one.  Not being able to determine what
column the cursor is in is somewhat debilitating for some applications.
I hope this is not too presumptious or against protocol.

Attached above is a a simple patch to the gtk+-2.2.0 dist that adds
some tests for this to the editable_cells.c demo in the demo/gtk-demo
directory. 
Comment 4 Kristian Rietveld 2003-01-14 16:03:54 UTC
Seems to happen because the focus column is changed after setting the
cursor (those two changes happen indenpent from eachother). So this is
either
(a) NOTABUG
(b) or we also need to emit cursor-changed after setting the focus-column.

jrb?
Comment 5 Dave Cook 2003-01-14 19:14:27 UTC
So there's no way to take action based on the cell the user is
editing?  I want to pop up a menu of items for that column on a key
press event.
Comment 6 Kristian Rietveld 2003-01-14 19:19:30 UTC
I think the cleanest approach in this case is writing your own cell
renderer.
Comment 7 Dave Cook 2003-01-15 11:31:28 UTC
Sigh.  I was afraid you'd say that ;}

Well, if this is NOTABUG, I'll try opening an RFE.  Writing a custom
CellRendererText in C would probably not be too hard, but doing it in
python looks like it would be pretty challenging, if it's even possible.
Comment 8 Dave Cook 2003-01-16 09:51:05 UTC
Looking back at Kristian's original explanation, I'm not sure it's
clear that this problem is not related to cursor-changed.  I modified
my test to call get_cursor on a key press so that there was no chance
of a focus change.  get_cursor will not report the cursor correctly if
the last focused cell was in the same row (you get the old cursor
position).  Do I misunderstand what cursor means in this context?  I
thought it referred to the text cursor (the one that blinks.)
Comment 9 Dave Cook 2003-01-16 12:25:13 UTC
Managed to come up with a hack that does what I need:

gboolean tree_view_get_editing_cell(GtkTreeView *view,
                                    GtkTreePath **path,
                                    GtkTreeViewColumn **column)
{
   GtkAllocation alloc;
   GtkWidget *toplevel;
   GtkWidget *focus_widget;
   gint cell_x, cell_y;

   toplevel = gtk_widget_get_toplevel(GTK_WIDGET(view));
   focus_widget = gtk_window_get_focus(GTK_WINDOW(toplevel));
   if (!(GTK_IS_ENTRY(focus_widget))) return FALSE;
   alloc = focus_widget->allocation;
   gtk_tree_view_get_path_at_pos(view, alloc.x, alloc.y, path, column,
                                 &cell_x, &cell_y);
   if (path && column) return TRUE;
   return FALSE;
}
Comment 10 Kristian Rietveld 2003-01-27 21:44:45 UTC
Fixed on HEAD/stable.