Re: GtkTextView->get_iter_at_location bug or user error?

On Wed, 2003-07-30 at 17:27, Beanz wrote:
What I am doing wrong? If I defined a button_press_event callback on 
a GtkTextView like:

  sub clicked {
    my $widget = $_[0];
    my $event = $_[1];
    print STDERR "Widget: $widget\nEvent: $event\n";
    my $iter = $widget->get_iter_at_location($event->x, $event->y);
    # blah, blah
    return 0;

$widget and $event are as expected, but I get a usage error:

  Usage: Gtk2::TextView::get_iter_at_location(text_view, iter, x, y) at ...

This is with 0.91. Any help much appreciated.


c api doc:

noteworthy portion:
"Retrieves the iterator at buffer coordinates x and y. Buffer
coordinates are coordinates for the entire buffer, not just the
currently-displayed portion. If you have coordinates from an event, you
have to convert those to buffer coordinates with

the c function dec looks like:
void gtk_text_view_get_iter_at_location (GtkTextView *text_view, 
GtkTextIter * iter, gint x, gint y)

between the fact that it says get and the description says "Retrieves
the iterator at buffer..." it sure as hell looks like it's mean to do
what you're trying to do. but why isn't it like everything else in gtk
and return the iter rather than have a pass by reference and a return
type of void.

i looked at the gtk2 source and tracked this function through some of
it's loads of calls and at points early on it is checking to see if iter
is non-null so that seems to mean that something is supposed to be
passed in, i.e. the iter isn't created by this call, one is passed in to

does anyone know what the behavior of this function is (supposed) to
be?  (cause i don't)

i was able to find a posting to a mailing list where someone was trying
to do something similar to you. havoc pennington (red hat) responded to
the guy's problem saying what i found above about the window/buffer
coords so that seems to be good advice. anyway, in that case he does
something like the following, (this is way simplified)

        GtkTextIter iter;

        gtk_text_view_get_iter_at_location(tv, &iter, x, y);

so it seems that the iter is pre-existing as i found, but i still
haven't a clue as to why. 

we can change the behavior of Gtk2-Perl and return a GtkTextIter from
the function as you thought would happen. i'm not seeing any way around
it from the perl level since you can't create an iter object, and pass
by reference here wouldn't be very perlish, but this doesn't sit well
with me as i don't know the reason why they implemented it this way in
the first place. perhaps this is a function that gets called A LOT and
they don't want to have to do the malloc of a GtkTextIter every time, i
don't know.

man, this was a long message, i'll make the changes to return the
GtkTextIter and commit them pending a general consensus of that being
the best thing to do so feedback those who would know. if you've got a
better idea then have at it and pass it along...


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