1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148
|
#!/usr/bin/perl -w
# $Header: /cvsroot/gtk2-perl/gtk2-perl-xs/Gtk2/t/GtkTreeSelection.t,v 1.8 2007/03/17 14:54:25 kaffeetisch Exp $
###############################################################################
use Gtk2::TestHelper tests => 29;
###############################################################################
my $model = Gtk2::ListStore -> new("Glib::String");
my $view = Gtk2::TreeView -> new($model);
my $renderer = Gtk2::CellRendererText -> new();
my $column = Gtk2::TreeViewColumn -> new_with_attributes(
"Hmm",
$renderer,
text => 0);
$view -> append_column($column);
foreach (qw(bla ble bli blo blu)) {
$model -> set($model -> append(), 0 => $_);
}
###############################################################################
my $selection = $view -> get_selection();
isa_ok($selection, "Gtk2::TreeSelection");
$selection -> select_path(Gtk2::TreePath -> new_from_string(0));
###############################################################################
$selection -> set_mode("browse");
ok($selection -> get_mode() eq "browse");
###############################################################################
isa_ok($selection -> get_tree_view(), "Gtk2::TreeView");
###############################################################################
my ($tmp_model, $tmp_iter) = $selection -> get_selected();
isa_ok($tmp_model, "Gtk2::ListStore");
isa_ok($tmp_iter, "Gtk2::TreeIter");
is($tmp_model -> get($tmp_iter, 0), "bla");
isa_ok($selection -> get_selected(), "Gtk2::TreeIter");
###############################################################################
isa_ok($selection -> get_selected_rows(), "Gtk2::TreePath");
###############################################################################
is($selection -> count_selected_rows(), 1);
my $path = Gtk2::TreePath -> new_from_string(1);
$selection -> select_path($path);
ok($selection -> path_is_selected($path));
$selection -> unselect_path($path);
ok(not $selection -> path_is_selected($path));
###############################################################################
my $iter = $model -> get_iter($path);
is($model -> get($iter, 0), "ble");
$selection -> select_iter($iter);
ok($selection -> iter_is_selected($iter));
$selection -> unselect_iter($iter);
ok(not $selection -> iter_is_selected($iter));
###############################################################################
$selection -> set_mode("multiple");
$selection -> select_all();
is($selection -> count_selected_rows(), 5);
$selection -> unselect_all();
is($selection -> count_selected_rows(), 0);
my $path_start = Gtk2::TreePath -> new_from_string(3);
my $path_end = Gtk2::TreePath -> new_from_string(4);
$selection -> select_range($path_start, $path_end);
is($selection -> count_selected_rows(), 2);
SKIP: {
skip("unselect_range is new in 2.2.x", 1)
unless Gtk2->CHECK_VERSION (2, 2, 0);
$selection -> unselect_range($path_start, $path_end);
is($selection -> count_selected_rows(), 0);
}
###############################################################################
$selection -> unselect_all();
is($selection -> get_user_data(), undef);
$selection -> set_select_function(sub {
my ($selection, $model, $path, $selected) = @_;
isa_ok($selection, "Gtk2::TreeSelection");
isa_ok($model, "Gtk2::ListStore");
isa_ok($path, "Gtk2::TreePath");
return 0;
});
is($selection -> get_user_data(), undef);
$selection -> select_path(Gtk2::TreePath -> new_from_string(1));
is($selection -> count_selected_rows(), 0);
$selection -> set_select_function(sub { return 1; }, "bla");
is($selection -> get_user_data(), "bla");
###############################################################################
$selection -> select_path(Gtk2::TreePath -> new_from_string(1));
$selection -> selected_foreach(sub {
my ($model, $path, $iter) = @_;
is($model -> get($iter, 0), "ble");
isa_ok($model, "Gtk2::ListStore");
isa_ok($path, "Gtk2::TreePath");
isa_ok($iter, "Gtk2::TreeIter");
});
###############################################################################
run_main;
__END__
Copyright (C) 2003-2005 by the gtk2-perl team (see the file AUTHORS for the
full list). See LICENSE for more information.
|