Problem withGtk3::TextView "get_iter_at_position"



Converting a gtk2 application, obtaining the iter that corresponds to a position in a textview window (get_iter_at_position) does not work - it works well in gtk2.

In Perl-Gtk2 the value of the iter is retrieved as the value returned by "get_iter_at_position" (and documented so) - and I assume that this should also be so in Perl-Gtk3. However, the return values I observe are 0 and 1 - evidenly boolean values that indicate whether a button hit is within the text (as it is with the c-original). How is the value of the iter supposed to be obtained in Perl-Gtk3?

A typical use of "get_iter-at_position" is to program button hits to fetch text from a text window - I would assume that this is quite frequently done, but I did not find any references to the problem googling.

=============== demo example

use strict;
use Glib qw/TRUE FALSE/;
use Gtk3 '-init';

my $x_window = Gtk3::Window->new ('toplevel');
$x_window->set_size_request ( 200, 200) ;

my $text_view = Gtk3::TextView->new ();
$x_window->add ($text_view);
my $x_bf = $text_view->get_buffer ();
my $x_iter = $x_bf->get_iter_at_offset (0);
$text_view->signal_connect ( 'button-press-event',
        sub {
                my ( $p_panel, $p_event ) = @_;
                my $hit_iter = $text_view->get_iter_at_position
                                ( $p_event->x, $p_event->y );
                print "@_ ".$p_event->x."  **  $hit_iter\n";
                return FALSE;
        } );

foreach ( qw ( abc efg hij ) ) { $x_bf->insert ( $x_iter, $_."\n" ); }
$x_window->show_all;
Gtk3->main;

Result printed (depending on the position, the value can also be 1)
Gtk3::TextView=HASH(0x1505b50) Gtk3::Gdk::EventButton=SCALAR(0x1edb6e0) 9.3406982421875 ** 0

printout if run with Gtk2
Gtk2::TextView=HASH(0xe8cb90) Gtk2::Gdk::Event::Button=SCALAR(0xe8cce0) 14 ** Gtk2::TextIter=SCALAR(0xe8ce90)



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