| 1 | # Copyright 2008, 2009, 2010, 2011, 2013 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::CellRendererTextBits; | ||
| 19 | use 5.008; | ||
| 20 | use Carp; | ||
| 21 | use strict; | ||
| 22 | use warnings; | ||
| 23 | |||
| 24 | # uncomment this to run the ### lines | ||
| 25 | #use Smart::Comments; | ||
| 26 | |||
| 27 | sub renderer_edited_set_value { | ||
| 28 | my ($renderer, $dest, $column_num) = @_; | ||
| 29 | defined $column_num or croak 'No column number supplied'; | ||
| 30 | my @userdata = ($dest, $column_num); | ||
| 31 | require Scalar::Util; | ||
| 32 | Scalar::Util::weaken ($userdata[0]); | ||
| 33 | $renderer->signal_connect (edited => \&_renderer_edited_set_value_handler, | ||
| 34 | \@userdata); | ||
| 35 | } | ||
| 36 | sub _renderer_edited_set_value_handler { | ||
| 37 | my ($renderer, $pathstr, $newtext, $userdata) = @_; | ||
| 38 | my ($dest, $column_num) = @$userdata; | ||
| 39 | |||
| 40 | if ($dest->can('get_tree_view')) { | ||
| 41 | # on Gtk2::TreeViewColumn go to the Gtk2::TreeView | ||
| 42 | $dest = $dest->get_tree_view || croak 'No viewer from get_tree_view'; | ||
| 43 | } | ||
| 44 | if (my $pspec = $dest->find_property('model')) { | ||
| 45 | if ($pspec->get_value_type eq 'Gtk2::TreeModel') { | ||
| 46 | # on Gtk2::TreeView, or Gtk2::CellView, etc, go to the Gtk2::TreeModel | ||
| 47 | $dest = $dest->get('model') | ||
| 48 | || croak 'No model from get_model'; | ||
| 49 | } | ||
| 50 | } | ||
| 51 | my $path = Gtk2::TreePath->new_from_string ($pathstr); | ||
| 52 | my $iter = $dest->get_iter ($path) | ||
| 53 | || croak "Path $pathstr not found in model"; | ||
| 54 | ### renderer_edited_set_value() set_value "path=$pathstr col=$column_num" | ||
| 55 | $dest->set_value ($iter, $column_num, $newtext); | ||
| 56 | } | ||
| 57 | |||
| 58 | 1; | ||
| 59 | __END__ |