[perl-Gtk3] Add overrides for Gtk3::InfoBar



commit 9bd01daaaaac3197be17c77b13e3222643b4fcc6
Author: Dave M <dave nerd gmail com>
Date:   Sun Jan 20 18:11:02 2013 +0100

    Add overrides for Gtk3::InfoBar

 NEWS              |    4 +-
 lib/Gtk3.pm       |   91 +++++++++++++++++++++++++++++++++--------------------
 t/zz-GtkInfoBar.t |   63 ++++++++++++++++++++++++++++++++++++
 3 files changed, 122 insertions(+), 36 deletions(-)
---
diff --git a/NEWS b/NEWS
index 0b2c34f..af7bd87 100644
--- a/NEWS
+++ b/NEWS
@@ -1,8 +1,8 @@
 {{$NEXT}}
 
 * Add overrides for Gtk3::Container.
-* Add overrides for Gtk3::Dialog, including the conversion of predefined
-  response IDs to nick names.  This is an API change.
+* Add overrides for Gtk3::Dialog and Gtk3::InfoBar, including the conversion of
+  predefined response IDs to nick names.
 * Add overrides for Gtk3::Editable.
 * Add overrides for Gtk3::FileChooserDialog.
 * Add overrides for Gtk3::RecentChooserDialog.
diff --git a/lib/Gtk3.pm b/lib/Gtk3.pm
index 7b0be27..bba6137 100644
--- a/lib/Gtk3.pm
+++ b/lib/Gtk3.pm
@@ -61,6 +61,7 @@ my @_GTK_HANDLE_SENTINEL_BOOLEAN_FOR = qw/
 my @_GTK_USE_GENERIC_SIGNAL_MARSHALLER_FOR = (
   ['Gtk3::Editable', 'insert-text'],
   ['Gtk3::Dialog',   'response',    \&Gtk3::Dialog::_gtk3_perl_response_converter],
+  ['Gtk3::InfoBar',  'response',    \&Gtk3::Dialog::_gtk3_perl_response_converter],
 );
 
 # FIXME: G:O:I should provide some general mechanism wrapping
@@ -638,22 +639,41 @@ sub Gtk3::CssProvider::load_from_data {
     $self, _unpack_unless_array_ref ($data));
 }
 
-sub Gtk3::Dialog::add_action_widget {
-  Glib::Object::Introspection->invoke (
-    $_GTK_BASENAME, 'Dialog', 'add_action_widget',
-    $_[0], $_[1], $_GTK_RESPONSE_NICK_TO_ID->($_[2]));
-}
-
-sub Gtk3::Dialog::add_button {
-  Glib::Object::Introspection->invoke (
-    $_GTK_BASENAME, 'Dialog', 'add_button',
-    $_[0], $_[1], $_GTK_RESPONSE_NICK_TO_ID->($_[2]));
-}
-
-sub Gtk3::Dialog::add_buttons {
-  my ($dialog, @rest) = @_;
-  for (my $i = 0; $i < @rest; $i += 2) {
-    $dialog->add_button ($rest[$i], $rest[$i+1]);
+# Gtk3::Dialog / Gtk3::InfoBar methods due to overlap
+{
+  no strict qw(refs);
+  foreach my $dialog_package (qw/Dialog InfoBar/) {
+    *{'Gtk3::' . $dialog_package . '::add_action_widget'} = sub {
+      Glib::Object::Introspection->invoke (
+        $_GTK_BASENAME, $dialog_package, 'add_action_widget',
+        $_[0], $_[1], $_GTK_RESPONSE_NICK_TO_ID->($_[2]));
+    };
+    *{'Gtk3::' . $dialog_package . '::add_button'} = sub {
+      Glib::Object::Introspection->invoke (
+        $_GTK_BASENAME, $dialog_package, 'add_button',
+        $_[0], $_[1], $_GTK_RESPONSE_NICK_TO_ID->($_[2]));
+    };
+    *{'Gtk3::' . $dialog_package . '::add_buttons'} = sub {
+      my ($dialog, @rest) = @_;
+      for (my $i = 0; $i < @rest; $i += 2) {
+        $dialog->add_button ($rest[$i], $rest[$i+1]);
+      }
+    };
+    *{'Gtk3::' . $dialog_package . '::response'} = sub {
+      return Glib::Object::Introspection->invoke (
+        $_GTK_BASENAME, $dialog_package, 'response',
+        $_[0], $_GTK_RESPONSE_NICK_TO_ID->($_[1]));
+    };
+    *{'Gtk3::' . $dialog_package . '::set_default_response'} = sub {
+      Glib::Object::Introspection->invoke (
+        $_GTK_BASENAME, $dialog_package, 'set_default_response',
+        $_[0], $_GTK_RESPONSE_NICK_TO_ID->($_[1]));
+    };
+    *{'Gtk3::' . $dialog_package . '::set_response_sensitive'} = sub {
+      Glib::Object::Introspection->invoke (
+        $_GTK_BASENAME, $dialog_package, 'set_response_sensitive',
+        $_[0], $_GTK_RESPONSE_NICK_TO_ID->($_[1]), $_[2]);
+    };
   }
 }
 
@@ -693,12 +713,6 @@ sub Gtk3::Dialog::new_with_buttons {
   &Gtk3::Dialog::new;
 }
 
-sub Gtk3::Dialog::response {
-  return Glib::Object::Introspection->invoke (
-    $_GTK_BASENAME, 'Dialog', 'response',
-    $_[0], $_GTK_RESPONSE_NICK_TO_ID->($_[1]));
-}
-
 sub Gtk3::Dialog::run {
   my $id = Glib::Object::Introspection->invoke (
     $_GTK_BASENAME, 'Dialog', 'run', @_);
@@ -713,18 +727,6 @@ sub Gtk3::Dialog::set_alternative_button_order {
     $dialog, [map { $_GTK_RESPONSE_NICK_TO_ID->($_) } @rest]);
 }
 
-sub Gtk3::Dialog::set_default_response {
-  Glib::Object::Introspection->invoke (
-    $_GTK_BASENAME, 'Dialog', 'set_default_response',
-    $_[0], $_GTK_RESPONSE_NICK_TO_ID->($_[1]));
-}
-
-sub Gtk3::Dialog::set_response_sensitive {
-  Glib::Object::Introspection->invoke (
-    $_GTK_BASENAME, 'Dialog', 'set_response_sensitive',
-    $_[0], $_GTK_RESPONSE_NICK_TO_ID->($_[1]), $_[2]);
-}
-
 sub Gtk3::Editable::insert_text {
   return Glib::Object::Introspection->invoke (
     $_GTK_BASENAME, 'Editable', 'insert_text',
@@ -774,6 +776,27 @@ sub Gtk3::ImageMenuItem::new {
     $_GTK_BASENAME, 'ImageMenuItem', 'new', @_);
 }
 
+sub Gtk3::InfoBar::new {
+  my ($class, @buttons) = @_;
+  if (@_ == 1) {
+    return Glib::Object::Introspection->invoke (
+      $_GTK_BASENAME, 'InfoBar', 'new', @_);
+  } elsif (@buttons % 2) {
+    croak "Usage: Gtk3::InfoBar->new_with_buttons" .
+    " (button-text => response_id, ...)\n";
+  } else {
+    my $infobar = Gtk3::InfoBar->new;
+    for (my $i = 0; $i < @buttons; $i += 2) {
+      $infobar->add_button ($buttons[$i], $buttons[$i+1]);
+    }
+    return $infobar;
+  }
+}
+
+sub Gtk3::InfoBar::new_with_buttons {
+  &Gtk3::InfoBar::new;
+}
+
 sub Gtk3::ListStore::new {
   return _common_tree_model_new ('ListStore', @_);
 }
diff --git a/t/zz-GtkInfoBar.t b/t/zz-GtkInfoBar.t
new file mode 100644
index 0000000..a739021
--- /dev/null
+++ b/t/zz-GtkInfoBar.t
@@ -0,0 +1,63 @@
+#!/usr/bin/perl
+#
+# Originally copied from Gtk2/t/GtkInfoBar.t
+#
+
+BEGIN { require './t/inc/setup.pl' }
+
+use strict;
+use warnings;
+
+plan tests => 15;
+
+ok (my $win = Gtk3::Window->new ('toplevel'));
+
+my $infobar = Gtk3::InfoBar->new;
+isa_ok ($infobar, 'Gtk3::InfoBar', 'new');
+$win->add ($infobar);
+
+isa_ok ($infobar->get_action_area, 'Gtk3::Widget', 'get_action_area');
+isa_ok ($infobar->get_content_area, 'Gtk3::Widget', 'get_content_area');
+
+isa_ok ($infobar->add_button (test3 => 3), 'Gtk3::Widget', 'add_button');
+is (button_count ($infobar), 1, 'add_button count');
+$infobar->add_buttons (test4 => 4, test5 => 5);
+is (button_count ($infobar), 3, 'add_buttons');
+
+my $button = Gtk3::Button->new ('action_widget');
+$infobar->add_action_widget ($button, 6);
+is (button_count ($infobar), 4, 'add_action_widget');
+
+my $infobar2 = Gtk3::InfoBar->new(
+	'gtk-ok' => 'ok', 'test2' => 2,
+);
+isa_ok ($infobar2, 'Gtk3::InfoBar', 'new_with_buttons');
+is (button_count ($infobar2), 2, 'new_with_buttons buttons count');
+
+$infobar->set_response_sensitive (6, Glib::FALSE);
+is ($button->is_sensitive, Glib::FALSE, 'set_response_sensitive');
+
+$infobar->set_message_type ('error');
+is ($infobar->get_message_type, 'error', '[gs]et_message_type');
+
+$infobar->set_default_response (4);
+ok (1, 'set_default_response');
+
+$infobar->signal_connect (response => sub {
+  my ($infobar,$response) = @_;
+  my $expected = $infobar->{expected_response};
+  ok ($response eq $expected, "response '$expected'");
+  1;
+});
+$infobar->response ($infobar->{expected_response} = 5);
+$infobar->response ($infobar->{expected_response} = 'ok');
+
+sub button_count {
+  my @b = $_[0]->get_action_area->get_children;
+  return scalar @b;
+}
+
+__END__
+
+Copyright (C) 2003-2013 by the gtk2-perl team (see the file AUTHORS for the
+full list).  See LICENSE for more information.



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