I've got two cases now, both implementing a remove() func: first in an
all-new TreeModel object, second in a subclass of TreeModelFilter.
Setting from an arrayref is good for the former, setting from another
iter is needed for the latter.

It's tempting to think of set(), or whatever name, for any boxed object,
eg. Gtk2::Gdk::Rectangle.  Except those with some malloced blocks like
Gtk2::SelectionData almost certainly can't be moved/replicated with just
memcpy.

--- GtkTreeModel.xs	07 Jul 2008 09:53:48 +1000	1.54
+++ GtkTreeModel.xs	23 Jul 2008 14:34:26 +1000	
@@ -939,6 +939,30 @@
 ## we get this from Glib::Boxed::DESTROY
 ## void gtk_tree_iter_free (GtkTreeIter *iter)
 
+=for apidoc
+Set the contents of $iter.  $from can be either another Gtk2::TreeIter
+or an "internal" arrayref form as above.
+
+Often you create a new iter instead of modifying an existing one, but
+C<set> lets you to implement things in the style of the C<remove>
+method of Gtk2::ListStore and Gtk2::TreeStore.
+
+A set can also explicitly invalidate an iter by zapping its stamp, so
+nobody can accidentally use it again.
+
+    $iter->set ([0,0,undef,undef]);
+
+=cut
+void
+set (GtkTreeIter *iter, SV *from)
+    CODE:
+	if (gperl_sv_is_array_ref (from)) {
+		iter_from_sv (iter, from);
+	} else {
+		GtkTreeIter *from_iter = SvGtkTreeIter (from);
+		memcpy (iter, from_iter, sizeof(*iter));
+	}
+
 
 MODULE = Gtk2::TreeModel	PACKAGE = Gtk2::TreeModel	PREFIX = gtk_tree_model_
 
--- GtkTreeModel.t	19 Sep 2005 01:07:22 +1000	1.6
+++ GtkTreeModel.t	23 Jul 2008 14:20:57 +1000	
@@ -1,6 +1,6 @@
 #!/usr/bin/perl -w
 use strict;
-use Gtk2::TestHelper tests => 73, noinit => 1;
+use Gtk2::TestHelper tests => 75, noinit => 1;
 
 # $Header: /cvsroot/gtk2-perl/gtk2-perl-xs/Gtk2/t/GtkTreeModel.t,v 1.6 2005/09/18 15:07:22 kaffeetisch Exp $
 
@@ -174,6 +174,26 @@
 	is($model -> get_string_from_iter($iter), "0");
 }
 
+{ my $myvar;
+  my $stamp = 123;
+  $iter = $model->get_iter_first;
+  my $aref = [$stamp, 456, undef, \$myvar];
+  $iter->set ($aref);
+  is_deeply ($iter->to_arrayref($stamp), $aref,
+             'iter->set() from an array');
+}
+{ my $myvar;
+  my $stamp = 123;
+  $iter = Gtk2::TreeIter->new_from_arrayref ([$stamp, 999, \$stamp, undef]);
+  my $aref = [$stamp, 456, undef, \$myvar];
+  my $other = Gtk2::TreeIter->new_from_arrayref ($aref);
+  $iter->set ($other);
+  is_deeply ($iter->to_arrayref($stamp), $other->to_arrayref($stamp),
+             'iter->set() from another iter');
+}
+
+
+
 ###############################################################################
 
 my ($iter_one, $iter_two);
_______________________________________________
gtk-perl-list mailing list
[email protected]
http://mail.gnome.org/mailman/listinfo/gtk-perl-list

Reply via email to