[perl-Gtk3] Add more overrides for the tree objects
- From: Torsten SchÃnfeld <tsch src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [perl-Gtk3] Add more overrides for the tree objects
- Date: Sun, 13 Nov 2011 16:20:20 +0000 (UTC)
commit c513a20c421bfedb48db736fe0fd814020f1ed6a
Author: Torsten SchÃnfeld <kaffeetisch gmx de>
Date: Sun Oct 23 23:48:29 2011 +0200
Add more overrides for the tree objects
lib/Gtk3.pm | 41 +++++++++++++++++++++++++
t/overrides.t | 92 ++++++++++++++++++++++++++++++++++++++++++---------------
2 files changed, 109 insertions(+), 24 deletions(-)
---
diff --git a/lib/Gtk3.pm b/lib/Gtk3.pm
index ad01608..6e1b2c9 100644
--- a/lib/Gtk3.pm
+++ b/lib/Gtk3.pm
@@ -19,6 +19,12 @@ my @_GTK_FLATTEN_ARRAY_REF_RETURN_FOR = qw/
my @_GTK_HANDLE_SENTINEL_BOOLEAN_FOR = qw/
Gtk3::TreeModel::get_iter
Gtk3::TreeModel::get_iter_first
+ Gtk3::TreeModel::get_iter_from_string
+ Gtk3::TreeModel::iter_children
+ Gtk3::TreeModel::iter_nth_child
+ Gtk3::TreeModel::iter_parent
+ Gtk3::TreeModelFilter::convert_child_iter_to_iter
+ Gtk3::TreeModelSort::convert_child_iter_to_iter
Gtk3::TreeSelection::get_selected
/;
@@ -156,6 +162,32 @@ sub Gtk3::TreeModel::get {
return @values[0..$#values];
}
+# Not needed anymore once <https://bugzilla.gnome.org/show_bug.cgi?id=646742>
+# is fixed.
+sub Gtk3::TreeModelFilter::new {
+ my ($class, $child_model, $root) = @_;
+ Glib::Object::Introspection->invoke (
+ $_GTK_BASENAME, 'TreeModel', 'filter_new', $child_model, $root);
+}
+
+# Reroute 'get' to Gtk3::TreeModel instead of Glib::Object.
+sub Gtk3::TreeModelFilter::get {
+ return Gtk3::TreeModel::get (@_);
+}
+
+# Not needed anymore once <https://bugzilla.gnome.org/show_bug.cgi?id=646742>
+# is fixed.
+sub Gtk3::TreeModelSort::new_with_model {
+ my ($class, $child_model) = @_;
+ Glib::Object::Introspection->invoke (
+ $_GTK_BASENAME, 'TreeModel', 'sort_new_with_model', $child_model);
+}
+
+# Reroute 'get' to Gtk3::TreeModel instead of Glib::Object.
+sub Gtk3::TreeModelSort::get {
+ return Gtk3::TreeModel::get (@_);
+}
+
sub Gtk3::TreePath::new {
my ($class, @args) = @_;
my $method = (@args == 1) ? 'new_from_string' : 'new';
@@ -163,6 +195,15 @@ sub Gtk3::TreePath::new {
$_GTK_BASENAME, 'TreePath', $method, @_);
}
+sub Gtk3::TreePath::new_from_indices {
+ my ($class, @indices) = @_;
+ my $path = Gtk3::TreePath->new;
+ foreach (@indices) {
+ $path->append_index ($_);
+ }
+ return $path;
+}
+
sub Gtk3::TreeStore::new {
return _common_tree_model_new ('TreeStore', @_);
}
diff --git a/t/overrides.t b/t/overrides.t
index b716c71..d49941d 100644
--- a/t/overrides.t
+++ b/t/overrides.t
@@ -5,7 +5,7 @@ BEGIN { require './t/inc/setup.pl' };
use strict;
use warnings;
-plan tests => 29;
+plan tests => 46;
# Gtk3::CHECK_VERSION and check_version
{
@@ -51,22 +51,84 @@ plan tests => 29;
like ($@, qr/Usage/);
}
-# Gtk3::TreeModel::get_iter and get_iter_first
+# Gtk3::TreeStore::new, set and get
+{
+ my $model = Gtk3::TreeStore->new ([qw/Glib::String Glib::Int/]);
+ my $iter = $model->append (undef);
+ $model->set ($iter, [0, 1], ['Foo', 23]);
+ is_deeply ([$model->get ($iter, 0,1)], ['Foo', 23]);
+ is (scalar $model->get ($iter, 0,1), 23);
+
+ $iter = $model->append (undef);
+ $model->set ($iter, 0 => 'Bar', 1 => 42);
+ is_deeply ([$model->get ($iter, 0,1)], ['Bar', 42]);
+ is (scalar $model->get ($iter, 0,1), 42);
+
+ local $@;
+ eval { $model->set ($iter, 0) };
+ like ($@, qr/Usage/);
+}
+
+# Gtk3::TreePath::new, new_from_string, new_from_indices, get_indices
+{
+ my $path = Gtk3::TreePath->new;
+ isa_ok ($path, 'Gtk3::TreePath');
+ $path = Gtk3::TreePath->new ('1:2:3');
+ is_deeply ([$path->get_indices], [1, 2, 3]);
+ $path = Gtk3::TreePath->new_from_string ('1:2:3');
+ is_deeply ([$path->get_indices], [1, 2, 3]);
+ $path = Gtk3::TreePath->new_from_indices (1, 2, 3);
+ is_deeply ([$path->get_indices], [1, 2, 3]);
+}
+
+# Gtk3::TreeModel::get_iter, get_iter_first, get_iter_from_string
{
my $model = Gtk3::ListStore->new ('Glib::String');
my $path = Gtk3::TreePath->new_from_string ('0');
is ($model->get_iter ($path), undef);
is ($model->get_iter_first, undef);
+ is ($model->get_iter_from_string ('0'), undef);
my $iter = $model->append;
isa_ok ($model->get_iter ($path), 'Gtk3::TreeIter');
isa_ok ($model->get_iter_first, 'Gtk3::TreeIter');
+ isa_ok ($model->get_iter_from_string ('0'), 'Gtk3::TreeIter');
}
-# Gtk3::TreePath::get_indices
+# Gtk3::TreeModel::iter_children, iter_nth_child, iter_parent
{
- # my $path = Gtk3::TreePath->new_from_indices ([1, 2, 3]); # FIXME
- my $path = Gtk3::TreePath->new_from_string ('1:2:3');
- is_deeply ([$path->get_indices], [1, 2, 3]);
+ my $model = Gtk3::TreeStore->new ([qw/Glib::String/]);
+ my $parent_iter = $model->append (undef);
+ is ($model->iter_children ($parent_iter), undef);
+ is ($model->iter_nth_child ($parent_iter, 0), undef);
+ is ($model->iter_parent ($parent_iter), undef);
+ my $child_iter = $model->append ($parent_iter);
+ isa_ok ($model->iter_children ($parent_iter), 'Gtk3::TreeIter');
+ isa_ok ($model->iter_nth_child ($parent_iter, 0), 'Gtk3::TreeIter');
+ isa_ok ($model->iter_parent ($child_iter), 'Gtk3::TreeIter');
+}
+
+# Gtk3::TreeModelFilter
+{
+ my $child_model = Gtk3::TreeStore->new ([qw/Glib::String/]);
+ my $child_iter = $child_model->append (undef);
+ $child_model->set ($child_iter, 0 => 'Bla');
+ my $model = Gtk3::TreeModelFilter->new ($child_model);
+ isa_ok ($model, 'Gtk3::TreeModelFilter');
+ my $iter = $model->convert_child_iter_to_iter ($child_iter);
+ isa_ok ($iter, 'Gtk3::TreeIter');
+ is ($model->get ($iter, 0), 'Bla');
+}
+
+# Gtk3::TreeModelSort
+{
+ my $child_model = Gtk3::TreeStore->new ([qw/Glib::String/]);
+ my $child_iter = $child_model->append (undef);
+ $child_model->set ($child_iter, 0 => 'Bla');
+ my $model = Gtk3::TreeModelSort->new_with_model ($child_model);
+ isa_ok ($model, 'Gtk3::TreeModelSort');
+ my $iter = $model->convert_child_iter_to_iter ($child_iter);
+ isa_ok ($iter, 'Gtk3::TreeIter');
+ is ($model->get ($iter, 0), 'Bla');
}
# Gtk3::TreeSelection::get_selected
@@ -81,24 +143,6 @@ plan tests => 29;
isa_ok ($sel_iter, 'Gtk3::TreeIter');
}
-# Gtk3::TreeStore::new, set and get
-{
- my $model = Gtk3::TreeStore->new ([qw/Glib::String Glib::Int/]);
- my $iter = $model->append (undef);
- $model->set ($iter, [0, 1], ['Foo', 23]);
- is_deeply ([$model->get ($iter, 0,1)], ['Foo', 23]);
- is (scalar $model->get ($iter, 0,1), 23);
-
- $iter = $model->append (undef);
- $model->set ($iter, 0 => 'Bar', 1 => 42);
- is_deeply ([$model->get ($iter, 0,1)], ['Bar', 42]);
- is (scalar $model->get ($iter, 0,1), 42);
-
- local $@;
- eval { $model->set ($iter, 0) };
- like ($@, qr/Usage/);
-}
-
# Gtk3::Window::new and list_toplevels
{
my $window1 = Gtk3::Window->new ('toplevel');
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]