[perl-Gtk3] Add overrides for the child property methods of Gtk3::Container
- From: Torsten Schönfeld <tsch src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [perl-Gtk3] Add overrides for the child property methods of Gtk3::Container
- Date: Tue, 25 Oct 2016 15:51:17 +0000 (UTC)
commit 097ed472ef2657c33c5995eac36be7552045433c
Author: Torsten Schönfeld <kaffeetisch gmx de>
Date: Tue Oct 25 17:22:18 2016 +0200
Add overrides for the child property methods of Gtk3::Container
Gtk3::Container::add_with_properties, Gtk3::Container::child_get and
Gtk3::Container::child_set.
lib/Gtk3.pm | 46 ++++++++++++++++++++++++++++++++++++++++++++++
t/zz-GtkContainer.t | 14 +++++---------
2 files changed, 51 insertions(+), 9 deletions(-)
---
diff --git a/lib/Gtk3.pm b/lib/Gtk3.pm
index ca0d267..f52ba2a 100644
--- a/lib/Gtk3.pm
+++ b/lib/Gtk3.pm
@@ -934,6 +934,52 @@ sub Gtk3::Clipboard::set_text {
@_ == 3 ? @_ : (@_[0,1], -1)); # wants length in bytes
}
+=item * Perl reimplementations of C<Gtk3::Container::add_with_properties>,
+C<Gtk3::Container::child_get> and C<Gtk3::Container::child_set> are provided.
+
+=cut
+
+sub Gtk3::Container::add_with_properties {
+ my ($container, $widget, @rest) = @_;
+ $widget->freeze_child_notify;
+ $container->add ($widget);
+ if ($widget->get_parent) {
+ $container->child_set ($widget, @rest);
+ }
+ $widget->thaw_child_notify;
+}
+
+sub Gtk3::Container::child_get {
+ my ($container, $child, @rest) = @_;
+ my $properties = _rest_to_ref (\@rest);
+ my @values;
+ foreach my $property (@$properties) {
+ my $pspec = Gtk3::ContainerClass::find_child_property ($container, $property);
+ croak "Cannot find type information for property '$property' on $container"
+ unless defined $pspec;
+ my $value_wrapper = Glib::Object::Introspection::GValueWrapper->new (
+ $pspec->get_value_type, undef);
+ $container->child_get_property ($child, $property, $value_wrapper);
+ push @values, $value_wrapper->get_value;
+ }
+ return @values[0..$#values];
+}
+
+sub Gtk3::Container::child_set {
+ my ($container, $child, @rest) = @_;
+ my ($properties, $values) = _unpack_keys_and_values (\@rest);
+ foreach my $i (0..$#$properties) {
+ my $property = $properties->[$i];
+ my $value = $values->[$i];
+ my $pspec = Gtk3::ContainerClass::find_child_property ($container, $property);
+ croak "Cannot find type information for property '$property' on $container"
+ unless defined $pspec;
+ my $value_wrapper = Glib::Object::Introspection::GValueWrapper->new (
+ $pspec->get_value_type, $value);
+ $container->child_set_property ($child, $property, $value_wrapper);
+ }
+}
+
=item * C<Gtk3::Container::get_focus_chain> returns a list of widgets, or an
empty list.
diff --git a/t/zz-GtkContainer.t b/t/zz-GtkContainer.t
index ad3784f..c132f96 100644
--- a/t/zz-GtkContainer.t
+++ b/t/zz-GtkContainer.t
@@ -7,7 +7,7 @@ BEGIN { require './t/inc/setup.pl' }
use strict;
use warnings;
-plan tests => 28;
+plan tests => 31;
# we'll create some containers (windows and boxes are containers) and
# mess around with some of the methods to make sure they do things.
@@ -107,17 +107,15 @@ $vbox->set_reallocate_redraws(1);
ok (1);
#------------------------------------------------------------------------------
-# child_get()
-
-=for FIXME3
+# child_get(), child_set()
is_deeply ([$vbox->child_get ($entry, qw(expand fill pack-type padding position))],
- [1, 1, "start", 0, 4]);
+ [1, 1, "start", 0, 3]);
$vbox->child_set ($entry, expand => 0, position => 2);
-$vbox->child_set_property ($entry, fill => 0);
+$vbox->child_set ($entry, fill => 0);
-is_deeply ([$vbox->child_get_property ($entry, qw(expand fill pack-type padding position))],
+is_deeply ([$vbox->child_get ($entry, qw(expand fill pack-type padding position))],
[0, 0, "start", 0, 2]);
my $label = Gtk3::Label->new ("Blub");
@@ -127,8 +125,6 @@ is_deeply ([$vbox->child_get ($label, qw(pack-type position))],
["end", 4]);
$vbox->remove ($label);
-=cut
-
#------------------------------------------------------------------------------
# find_child_property()
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]