[perl-Gtk2] Gtk2::Buildable: allow undef from GET_INTERNAL_CHILD()



commit 31ce073fb05ee8fef46c722047ca8da5c0864bf9
Author: Kevin Ryde <user42 zip com au>
Date:   Wed Nov 17 15:56:12 2010 +1100

    Gtk2::Buildable: allow undef from GET_INTERNAL_CHILD()
    
    https://bugzilla.gnome.org/show_bug.cgi?id=635112

 NEWS                  |    2 ++
 t/GtkBuildableIface.t |   37 ++++++++++++++++++++++++++++++++++++-
 xs/GtkBuildable.xs    |    8 ++++++--
 3 files changed, 44 insertions(+), 3 deletions(-)
---
diff --git a/NEWS b/NEWS
index 9147c8f..1c776e7 100644
--- a/NEWS
+++ b/NEWS
@@ -2,6 +2,8 @@ Overview of changes in the next unstable release
 ================================================
 
 * Fix length of Gtk2::Gdk::Pixbuf->get_pixels() return.
+* Allow Gtk2::Buildable implementations to return undef from
+  GET_INTERNAL_CHILD.
 
 Overview of changes in Gtk2 1.230
 =================================
diff --git a/t/GtkBuildableIface.t b/t/GtkBuildableIface.t
index 5b766c7..a5cbb9a 100644
--- a/t/GtkBuildableIface.t
+++ b/t/GtkBuildableIface.t
@@ -4,7 +4,7 @@
 use strict;
 use warnings;
 use Gtk2::TestHelper
-  tests => 89,
+  tests => 92,
   at_least_version => [2, 12, 0, 'GtkBuildable appeared in 2.12'];
 
 my $builder = Gtk2::Builder->new ();
@@ -364,3 +364,38 @@ sub SET_BUILDABLE_PROPERTY {
 
     $self->set ($name, $value);
 }
+
+# --------------------------------------------------------------------------- #
+# GET_INTERNAL_CHILD() returning undef for no such internal child
+{
+  my $get_internal_child = 0;
+  {
+    package MyWidget;
+    use Glib::Object::Subclass 'Gtk2::Widget',
+      interfaces => [ 'Gtk2::Buildable' ];
+    sub GET_INTERNAL_CHILD {
+      $get_internal_child = 1;
+      return undef;
+    }
+  }
+
+  my $builder = Gtk2::Builder->new;
+  eval {
+    $builder->add_from_string (<<'HERE');
+<interface>
+  <object class="MyWidget" id="mywidget">
+    <child internal-child="foo">
+      <object class="GObject" id="in-foo"/>
+    </child>
+  <object>
+</interface>
+HERE
+  };
+  my $err = $@;
+  is ($get_internal_child, 1,
+      'GET_INTERNAL_CHILD returning undef - iface func called');
+  isnt ($@, '',
+	'GET_INTERNAL_CHILD returning undef - builder throws an error');
+  isa_ok ($err, 'Glib::Error',
+	  'GET_INTERNAL_CHILD returning undef - builder error is a GError');
+}
diff --git a/xs/GtkBuildable.xs b/xs/GtkBuildable.xs
index d2e80bb..26bac10 100644
--- a/xs/GtkBuildable.xs
+++ b/xs/GtkBuildable.xs
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2007 by the gtk2-perl team (see the file AUTHORS)
+ * Copyright (c) 2007, 2010 by the gtk2-perl team (see the file AUTHORS)
  *
  * Licensed under the LGPL, see LICENSE file for more information.
  *
@@ -526,7 +526,7 @@ gtk2perl_buildable_get_internal_child (GtkBuildable  *buildable,
 		XPUSHs (sv_2mortal (newSVGtkBuilder (builder)));
 		XPUSHs (sv_2mortal (newSVGChar (childname)));
 		CALL_SCALAR (sv);
-		child = SvGObject (sv);
+		child = SvGObject_ornull (sv);
 		FINISH;
 	}
 
@@ -1022,6 +1022,10 @@ method if your buildable has internal children that need to be accessed from
 a UI definition.  For example, Gtk2::Dialog implements this to give access
 to its internal vbox child.
 
+If I<$childname> is unknown then return C<undef>.  (The builder will
+then generally report a GError for the UI description referring to an
+unknown child.)
+
 =back
 
 =cut



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