| 1 | # Copyright 2008, 2009, 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 | package App::Chart::Gtk2::Ex::NotebookLazyPages; | ||
| 18 | use 5.008; | ||
| 19 | use strict; | ||
| 20 | use warnings; | ||
| 21 | use Carp; | ||
| 22 | use Gtk2; | ||
| 23 | |||
| 24 | # uncomment this to run the ### lines | ||
| 25 | #use Smart::Comments; | ||
| 26 | |||
| 27 | sub set_init { | ||
| 28 | my ($notebook, $pagewidget, $func, $userdata) = @_; | ||
| 29 | $notebook->signal_connect ('notify::page' => \&_do_notify_page); | ||
| 30 | $pagewidget->{(__PACKAGE__)} = [ $func, $userdata ]; | ||
| 31 | } | ||
| 32 | |||
| 33 | # 'notify::page' signal handler | ||
| 34 | sub _do_notify_page { | ||
| 35 | my ($notebook) = @_; | ||
| 36 | my $pagenum = $notebook->get_current_page; | ||
| 37 | my $pagewidget = $notebook->get_nth_page ($pagenum); | ||
| 38 | |||
| 39 | if (my $aref = delete $pagewidget->{(__PACKAGE__)}) { | ||
| 40 | ### NotebookLazyPages initialize: $pagenum | ||
| 41 | my ($func, $userdata) = @$aref; | ||
| 42 | &$func ($notebook, $pagewidget, $pagenum, $userdata); | ||
| 43 | } | ||
| 44 | } | ||
| 45 | |||
| 46 | 1; | ||
| 47 | __END__ |