[perl-Gtk2] Always release the previous position function in Gtk2::Menu->popup



commit f49dae3e87aeb3a5486f65cb142a2d7cde160bfb
Author: Kevin Ryde <user42 zip com au>
Date:   Wed Mar 31 19:12:30 2010 +0200

    Always release the previous position function in Gtk2::Menu->popup
    
    We already do this when we install a new position function.  Do it also when
    called with undef.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=613369

 t/GtkMenu.t   |   28 ++++++++++++++++++++++++++--
 xs/GtkMenu.xs |    1 +
 2 files changed, 27 insertions(+), 2 deletions(-)
---
diff --git a/t/GtkMenu.t b/t/GtkMenu.t
index 96c6f6d..29726f1 100644
--- a/t/GtkMenu.t
+++ b/t/GtkMenu.t
@@ -8,7 +8,7 @@
 # 	- rm
 #########################
 
-use Gtk2::TestHelper tests => 57;
+use Gtk2::TestHelper tests => 61;
 
 ok( my $menubar = Gtk2::MenuBar->new );
 
@@ -124,6 +124,30 @@ $menu->popup(undef, undef, $position_callback, "bla", 1, 0);
 $menu->popdown;
 ok(TRUE);
 
+# crib note: $position_callback sub must be a proper closure referring to a
+# variable outside itself to weaken away like this
+require Scalar::Util;
+Scalar::Util::weaken($position_callback);
+ok ($position_callback, 'popup() holds onto position_callback');
+
+my $next_position_callback_variable = 0;
+my $next_position_callback = sub { $next_position_callback_variable++;
+                                   return (50,50) };
+$menu->popup(undef, undef, $next_position_callback, undef, 1, 0);
+$menu->popdown;
+is ($position_callback, undef,
+    'next popup() drops previously held position_callback');
+
+# crib note: again $next_position_callback must refer to a variable outside
+# itself to weaken away like this
+require Scalar::Util;
+Scalar::Util::weaken($next_position_callback);
+ok ($next_position_callback, 'popup() holds onto next_position_callback');
+$menu->popup(undef, undef, undef, undef, 1, 0);
+$menu->popdown;
+is ($next_position_callback, undef,
+    'popup() with no position func drops held position_callback');
+
 # If we never entered the pos. callback, fake four tests
 unless ($i_know_you) {
 	foreach (0 .. 3) {
@@ -145,5 +169,5 @@ SKIP: {
 
 __END__
 
-Copyright (C) 2003 by the gtk2-perl team (see the file AUTHORS for the
+Copyright (C) 2003, 2010 by the gtk2-perl team (see the file AUTHORS for the
 full list).  See LICENSE for more information.
diff --git a/xs/GtkMenu.xs b/xs/GtkMenu.xs
index a4e62ec..88d9b8f 100644
--- a/xs/GtkMenu.xs
+++ b/xs/GtkMenu.xs
@@ -141,6 +141,7 @@ gtk_menu_popup (menu, parent_menu_shell, parent_menu_item, menu_pos_func, data,
 	if (!gperl_sv_is_defined (menu_pos_func)) {
 		gtk_menu_popup (menu, parent_menu_shell, parent_menu_item,
 		                NULL, NULL, button, activate_time);
+		g_object_set_data (G_OBJECT(menu), "_menu_pos_callback", NULL);
 	} else {
 		GPerlCallback * callback;
 		/* we don't need to worry about the callback arg types since



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