Re: GtkTreeView problem



Hi,

Laszlo Kovacs <laszlo kovacs Sun COM> writes:

> I have to write a piece of code that returns the widget that the user
> clicked on and the coordinates where the click happened relative to
> the widget.
> 
> I had something that caught the button press event, took the
> coordinates from it and called gtk_get_event_widget() on the event to
> get the widget.

The widget that got the button_press event is passed to your signal
handler as the first parameter.

> This worked well until I hit into GtkTreeView. The problem is that
> GtkTreeViewColumn has a window and it sets the parent GtkTreeView as
> this window's user data. As gtk_get_event_widget() takes the gdk
> window from the event and queries its user data to get the widget the
> above algorithm does not work anymore as the coordinates are given
> relative to the GtkTreeViewColumn's window while the widget returned
> is the GtkTreeView. I also noticed that the docs call
> GtkTreeViewColumn an "object", is this a widget or not?

GtkTreeView is a widget, the rows and columns are not individual
widgets. If you need to find the cell a user clicked on, you can use
gtk_tree_view_get_path_at_pos() to translate from the button_press
event coordinates to a GtkTreePath.

> If this is not a bug in gtk+ then I need some different
> approach. Something like ignoring the event coordinates and getting
> the mouse pointer relative to the GtkTreeView widget's window (using
> gdk_window_get_pointer()) would probably help, but is this the right
> approach or I am missing the point completely?

You are looking for the solutions in GDK although the answers are a
few levels higher. Generally, you shouldn't have to deal much with the
GDK API unless you are drawing things yourself.


Sven



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]