[perl-Gtk2] Make Gtk2::ListStore->remove()'s return value consistent on gtk+ 2.0



commit ad47d5ccb78ea5d42c2658de241a182de168d894
Author: Kevin Ryde <user42 zip com au>
Date:   Thu Dec 17 21:53:38 2009 +0100

    Make Gtk2::ListStore->remove()'s return value consistent on gtk+ 2.0
    
    When gtk+ < 2.2, emulate the later behavior manually.
    
    Signed-off-by: Torsten Schönfeld <kaffeetisch gmx de>

 t/GtkListStore.t   |   21 +++------------------
 xs/GtkListStore.xs |   14 +++++++++-----
 2 files changed, 12 insertions(+), 23 deletions(-)
---
diff --git a/t/GtkListStore.t b/t/GtkListStore.t
index 7916627..743b4e1 100644
--- a/t/GtkListStore.t
+++ b/t/GtkListStore.t
@@ -32,8 +32,7 @@ my $path_model = Gtk2::TreePath -> new_from_string("0");
 my $iter_model;
 
 # remove returns boolean in >= 2.2.0, but false (actually, void) in 2.0.x.
-is($model -> remove($model -> get_iter($path_model)), 
-   (Gtk2->CHECK_VERSION (2, 2, 0) ? 1 : ''));
+ok($model -> remove($model -> get_iter($path_model)));
 is($model -> get($model -> get_iter($path_model), 0), "blee");
 
 $model -> clear();
@@ -137,23 +136,9 @@ ok ($iter = $store->insert (0), '$store->insert (0)');
 ok ($iter = $store->insert_before ($iter), '$store->insert_before');
 ok ($iter = $store->insert_after ($iter), '$store->insert_after');
 ok ($iter = $store->get_iter_first, '$store->get_iter_first, treemodel');
-if (!Gtk2->CHECK_VERSION (2, 2, 0)) {
-	# remove had void return in 2.0.x, and the binding for this method
-	# always returns false.  remove this special case if that method is
-	# ever fixed.
-	ok (!$store->remove ($iter), '$store->remove 1');
-} else {
-	ok ($store->remove ($iter), '$store->remove 1');
-}
+ok ($store->remove ($iter), '$store->remove 1');
 ok ($iter = $store->prepend, '$store->prepend');
-if (!Gtk2->CHECK_VERSION (2, 2, 0)) {
-	# remove had void return in 2.0.x, and the binding for this method
-	# always returns false.  remove this special case if that method is
-	# ever fixed.
-	ok (!$store->remove ($iter), '$store->remove 2');
-} else {
-	ok ($store->remove ($iter), '$store->remove 2');
-}
+ok ($store->remove ($iter), '$store->remove 2');
 
 SKIP: {
     # on RH8 with 2.0.6, i get a crash from pango xft, complaining that
diff --git a/xs/GtkListStore.xs b/xs/GtkListStore.xs
index 74b5ae5..15d392b 100644
--- a/xs/GtkListStore.xs
+++ b/xs/GtkListStore.xs
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003 by the gtk2-perl team (see the file AUTHORS)
+ * Copyright (c) 2003, 2009 by the gtk2-perl team (see the file AUTHORS)
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Library General Public
@@ -133,6 +133,10 @@ gtk_list_store_set (list_store, iter, col1, val1, ...)
 ### void gtk_list_store_set_value (GtkListStore *list_store, GtkTreeIter *iter, gint column, GValue *value)
 
 ## gboolean gtk_list_store_remove (GtkListStore *list_store, GtkTreeIter *iter)
+=for apidoc
+The return is always a boolean in the style of Gtk 2.2.x and up, even
+when running on Gtk 2.0.x.
+=cut
 gboolean
 gtk_list_store_remove (list_store, iter)
 	GtkListStore *list_store
@@ -141,11 +145,11 @@ gtk_list_store_remove (list_store, iter)
 #if GTK_CHECK_VERSION(2,2,0)
 	RETVAL = gtk_list_store_remove (list_store, iter);
 #else
-	/* void return in 2.0.x; always return FALSE from this function
-	 * in that case; FIXME the alternative is to implement the missing
-	 * functionality right here. */
+	/* void return in 2.0.x; look for stamp is zapped to 0 if no more
+	 * rows, to emulate the return value of 2.2 and up
+	 */
 	gtk_list_store_remove (list_store, iter);
-	RETVAL = FALSE;
+	RETVAL = (iter->stamp != 0);
 #endif
     OUTPUT:
 	RETVAL



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