Subclassing question
- From: "Martin Schlemmer" <Martin Schlemmer nwu ac za>
- To: <gtk-perl-list gnome org>
- Subject: Subclassing question
- Date: Mon, 11 May 2009 11:18:27 +0200
Hi,
I have a class that overrides Gtk2::TextBuffer's insert_text signal to disallow
adding newlines to the buffer. The problem however seems to be that when
the signal is overridden, the iterator is no longer updated causing it to be
invalid - I assume its because its no longer pass as reference.
Is there any way to do this with the current Glib::Object::Subclass interface
or perl?
Below is a simple test case - the first insert (line 42) into a normal buffer works
as expected, but the second one (line 43) fails.
Thanks,
Martin
-------------------------
package Gtk2::Ex::TextBuffer;
use strict;
use warnings;
use Gtk2 ();
use Glib::Object::Subclass
Gtk2::TextBuffer::,
signals => {
insert_text => \&__insert_text,
},
;
sub __insert_text {
my($self, $iter, $text, $length) = @_;
# Do not allow newlines
$text =~ s/[\n\r]+//mg;
if ($text) {
$self->signal_chain_from_overridden( $iter, $text, length($text) );
}
}
1;
package main;
use strict;
use warnings;
use Glib qw( TRUE FALSE );
use Gtk2 qw( -init );
my $tb1 = Gtk2::TextBuffer->new();
my $tb2 = Gtk2::Ex::TextBuffer->new();
my $iter1 = $tb1->get_start_iter();
my $iter2 = $tb2->get_start_iter();
for (my $i = 0; $i < 10; $i++) {
$tb1->insert($iter1, "line $i\n");
$tb2->insert($iter2, "line $i\n");
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]