| 1 | # Copyright 2010 Kevin Ryde | ||
| 2 | |||
| 3 | # This file is part of Chart. | ||
| 4 | # | ||
| 5 | # Chart is free software; you can redistribute it and/or modify it under the | ||
| 6 | # terms of the GNU General Public License as published by the Free Software | ||
| 7 | # Foundation; either version 3, or (at your option) any later version. | ||
| 8 | # | ||
| 9 | # Chart is distributed in the hope that it will be useful, but WITHOUT ANY | ||
| 10 | # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | ||
| 11 | # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more | ||
| 12 | # details. | ||
| 13 | # | ||
| 14 | # You should have received a copy of the GNU General Public License along | ||
| 15 | # with Chart. If not, see <http://www.gnu.org/licenses/>. | ||
| 16 | |||
| 17 | |||
| 18 | package App::Chart::Gtk2::Ex::TreeModelBits; | ||
| 19 | use 5.010; | ||
| 20 | use strict; | ||
| 21 | use warnings; | ||
| 22 | use Gtk2; | ||
| 23 | |||
| 24 | # return a new iter which is the last child under the given $iter | ||
| 25 | # $iter can be undef to get the last top-level | ||
| 26 | # if there's no children under $iter the return is undef | ||
| 27 | sub _model_iter_last_child { | ||
| 28 | my ($model, $iter) = @_; | ||
| 29 | my $nchildren = $model->iter_n_children ($iter); | ||
| 30 | |||
| 31 | # $n==-1 returns undef already | ||
| 32 | # if ($nchildren == 0) { return undef; } | ||
| 33 | |||
| 34 | return $model->iter_nth_child ($iter, $nchildren - 1); | ||
| 35 | } | ||
| 36 | |||
| 37 | 1; | ||
| 38 | __END__ |