[Date Prev][Date Next] [Thread Prev][Thread Next]
[Thread Index]
[Date Index]
[Author Index]
TreeModelFilter modify func
- From: Kevin Ryde <user42 zip com au>
- To: gtk-perl-list gnome org
- Subject: TreeModelFilter modify func
- Date: Sat, 03 May 2008 09:26:22 +1000
Is there a trick to giving back the value in a set_modify_func function
in a TreeModelFilter? I wondered if it was/is/meant-to-be a return
value. Maybe as per below?
--- GtkTreeModelFilter.t 18 Jun 2006 23:39:53 +1000 1.8
+++ GtkTreeModelFilter.t 03 May 2008 07:40:14 +1000
@@ -1,7 +1,7 @@
#!/usr/bin/perl -w
use strict;
use Gtk2::TestHelper
- tests => 24,
+ tests => 26,
noinit => 1,
at_least_version => [2, 4, 0, "GtkTreeModelFilter is new in 2.4"];
@@ -53,6 +53,27 @@
$filter -> refilter();
$filter -> clear_cache();
+$filter = Gtk2::TreeModelFilter -> new($list, undef);
+$filter -> set_modify_func
+ (["Glib::Int", "Glib::String"],
+ sub { my ($filter, $iter, $col, $userdata) = @_;
+ my $path = $filter->get_path ($iter);
+ if ($col == 0) {
+ my ($pos) = $path->get_indices;
+ return $pos * 100 + $col;
+ }
+ if ($col == 1) {
+ return "column $col userdata $userdata path "
+ . $path->to_string;
+ }
+ }, 12345);
+
+is ($filter->get_value($filter->iter_nth_child(undef,2), 0),
+ 200);
+is ($filter->get_value($filter->get_iter_first, 1),
+ 'column 1 userdata 12345 path 0');
+
+
$filter = Gtk2::TreeModelFilter -> new($list, Gtk2::TreePath -> new_from_string("1"));
isa_ok($filter, "Gtk2::TreeModelFilter");
--- GtkTreeModelFilter.xs 10 Jan 2008 09:51:09 +1100 1.14
+++ GtkTreeModelFilter.xs 03 May 2008 09:17:13 +1000
@@ -55,8 +55,7 @@
gpointer data)
{
GPerlCallback * callback = (GPerlCallback*) data;
- SV * sv = sv_2mortal (gperl_sv_from_value (value));
- gperl_callback_invoke (callback, NULL, model, iter, sv, column);
+ gperl_callback_invoke (callback, value, model, iter, column);
}
MODULE = Gtk2::TreeModelFilter PACKAGE = Gtk2::TreeModelFilter PREFIX = gtk_tree_model_filter_
@@ -87,6 +86,17 @@
callback, (GtkDestroyNotify)gperl_callback_destroy);
## void gtk_tree_model_filter_set_modify_func (GtkTreeModelFilter *filter, gint n_columns, GType *types, GtkTreeModelFilterModifyFunc func, gpointer data, GtkDestroyNotify destroy);
+=for apidoc
+=for arg types (scalar) type name string for one column, or an arrayref of type names for multiple columns
+func is called as
+
+ sub myfunc {
+ my ($filter, $iter, $column_num, $data) = @_;
+ ...
+
+and should return the value from the filtered model that iter row and
+column number.
+=cut
void gtk_tree_model_filter_set_modify_func (GtkTreeModelFilter *filter, SV * types, SV * func=NULL, SV * data=NULL);
PREINIT:
GType * real_types = NULL;
@@ -119,10 +129,9 @@
GType param_types[4];
param_types[0] = GTK_TYPE_TREE_MODEL;
param_types[1] = GTK_TYPE_TREE_ITER;
- param_types[2] = GPERL_TYPE_SV;
- param_types[3] = G_TYPE_INT;
- callback = gperl_callback_new (func, data, 4, param_types,
- G_TYPE_NONE);
+ param_types[2] = G_TYPE_INT;
+ callback = gperl_callback_new (func, data, 3, param_types,
+ G_TYPE_VALUE);
gtk_tree_model_filter_set_modify_func
(filter, n_columns, real_types,
gtk2perl_tree_model_filter_modify_func,
[Date Prev][Date Next] [Thread Prev][Thread Next]
[Thread Index]
[Date Index]
[Author Index]