[perl-Gtk3] Add overrides for Gtk3::Menu::popup and popup_for_device



commit f276a90eed4d6324956962bc659a066139856c32
Author: Torsten SchÃnfeld <kaffeetisch gmx de>
Date:   Sat Apr 21 20:46:31 2012 +0200

    Add overrides for Gtk3::Menu::popup and popup_for_device

 NEWS          |    1 +
 lib/Gtk3.pm   |   27 +++++++++++++++++++++++++++
 t/overrides.t |   14 +++++++++++++-
 3 files changed, 41 insertions(+), 1 deletions(-)
---
diff --git a/NEWS b/NEWS
index 48aa679..c8af711 100644
--- a/NEWS
+++ b/NEWS
@@ -1,6 +1,7 @@
 {{$NEXT}}
 
 * Add overrides for Gtk3::Builder and implement its connect_signals.
+* Add overrides for Gtk3::Menu::popup and popup_for_device.
 
 Overview of changes in Gtk3 0.004 [2012-03-18]
 ==============================================
diff --git a/lib/Gtk3.pm b/lib/Gtk3.pm
index b7eb5bb..fabe30c 100644
--- a/lib/Gtk3.pm
+++ b/lib/Gtk3.pm
@@ -264,6 +264,33 @@ sub Gtk3::ListStore::set {
   return _common_tree_model_set ('ListStore', @_);
 }
 
+sub Gtk3::Menu::popup {
+  my $self = shift;
+  $self->popup_for_device (undef, @_);
+}
+
+sub Gtk3::Menu::popup_for_device {
+  my ($menu, $device, $parent_menu_shell, $parent_menu_item, $func, $data, $button, $activate_time) = @_;
+  my $real_func = sub {
+    my @stuff = eval { $func->(@_) };
+    if ($@) {
+      warn "*** menu position callback ignoring error: $@";
+    }
+    if (@stuff == 3) {
+      return (@stuff);
+    } elsif (@stuff == 2) {
+      return (@stuff, Glib::FALSE); # provide a default for push_in
+    } else {
+      warn "*** menu position callback must return two integers " .
+           "(x, y) or two integers and a boolean (x, y, push_in)";
+      return (0, 0, Glib::FALSE);
+    }
+  };
+  return Glib::Object::Introspection->invoke (
+    $_GTK_BASENAME, 'Menu', 'popup_for_device',
+    $menu, $device, $parent_menu_shell, $parent_menu_item, $real_func, $data, $button, $activate_time);
+}
+
 sub Gtk3::MessageDialog::new {
   my ($class, $parent, $flags, $type, $buttons, $format, @args) = @_;
   my $dialog = Glib::Object::new ($class, message_type => $type,
diff --git a/t/overrides.t b/t/overrides.t
index 367baa5..3208f74 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 => 59;
+plan tests => 61;
 
 # Gtk3::CHECK_VERSION and check_version
 {
@@ -54,6 +54,18 @@ SKIP: {
   like ($@, qr/Usage/);
 }
 
+# Gtk3::Menu::popup and popup_for_device
+{
+  my $menu = Gtk3::Menu->new;
+  my $position_callback = sub {
+    my ($menu, $data) = @_;
+    isa_ok ($menu, "Gtk3::Menu");
+    return @$data;
+  };
+  $menu->popup (undef, undef, $position_callback, [50, 50], 1, 0);
+  $menu->popup_for_device (undef, undef, undef, $position_callback, [50, 50, Glib::TRUE], 1, 0);
+}
+
 # Gtk3::Stock
 {
   ok (grep { $_ eq 'gtk-ok' } Gtk3::Stock::list_ids ());



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