blib/lib/Curses/UI/Notebook.pm

filter: Statementstmt 57.7% 204 / 353 Branchbran 39.7% 89 / 224 Conditioncond 17.1% 13 / 76 MC/DCmcdc 4.6% 2 / 43 Subroutinesub 72.0% 18 / 25 Podpod 92.8% 13 / 14 totaltotal 46.1% 339 / 735 CC 148 SCAR 67.0
CC
148
Cov
47%
draw
2652.0
mouse_button1
132.0
intellidraw
110.0
CRAP 814.3
↑ Summary blib/lib/Curses/UI/Widget.pm »
1 # ----------------------------------------------------------------------
2 # Curses::UI::Notebook
3 #
4 # Written by George A. Theall, theall@tifaware.com
5 #
6 # Copyright (c) 2004, George A. Theall. All rights reserved.
7 #
8 # This module is free software; you can redistribute it and/or modify
9 # it under the same terms as Perl itself.
10 #
11 # $Id: Notebook.pm,v 1.2 2004/10/22 21:07:27 mthies2s Exp $
12 # ----------------------------------------------------------------------
13  
14 package Curses::UI::Notebook;
15  
16 1 ▶use 5;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 1 ▶use Curses;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 1 ▶use Curses::UI::Common;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 1 ▶use Curses::UI::Widget;
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 1 ▶use vars qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
24 $VERSION
25 @ISA
26 1 );
27 1 $VERSION = '1.0001';
28 1 @ISA = qw(
29 Curses::UI::Container
30 );
31  
32 my %routines = (
33 0 ▶ 'goto_first_page' => sub { my $this = shift; $this->activate_page($this->first_page); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
34 0 ▶ 'goto_last_page' => sub { my $this = shift; $this->activate_page($this->last_page); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
35 0 ▶ 'goto_next_page' => sub { my $this = shift; $this->activate_page($this->next_page); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
36 0 ▶ 'goto_prev_page' => sub { my $this = shift; $this->activate_page($this->prev_page); },
Subroutine __ANON__: not called CC=1 SCAR=6.9
37 1 );
38 1 my %bindings = (
39 KEY_HOME() => 'goto_first_page',
40 "\cA" => 'goto_first_page',
41 KEY_END() => 'goto_last_page',
42 "\cE" => 'goto_last_page',
43 KEY_NPAGE() => 'goto_next_page',
44 "\cN" => 'goto_next_page',
45 KEY_PPAGE() => 'goto_prev_page',
46 "\cP" => 'goto_prev_page',
47 );
48  
49  
50 166 ▶sub debug_msg(;$) {
Subroutine debug_msg: called CC=6 SCAR=34.1
Pod undocumented
51 166 ▶ return unless ($Curses::UI::debug);
Branch: 1 branch
BranchTrueFalseTotal
unless $Curses::UI::debug 166 0 166
52  
53 0 my $caller = (caller(1))[3];
54 0 ▶ my $msg = shift || '';
Condition0%0/2
shift() || ''
l!l
00
MC/DC0%0/1
shift() || ''
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
55 0 ▶ my $indent = ($msg =~ /^(\s+)/ ? $1 : '');
Branch: 1 branch
BranchTrueFalseTotal
$msg =~ /^(\s+)/ ? : 0 0 0
56 0 $msg =~ s/\n/\nDEBUG: $indent/mg;
57  
58 0 ▶ warn 'DEBUG: ' .
Branch: 1 branch
BranchTrueFalseTotal
$msg ? : 0 0 0
Condition0%0/2
(caller 2)[3] || 'main'
l!l
00
MC/DC0%0/1
(caller 2)[3] || 'main'
(caller 2)[3]
Truth table0%0/2
A
A= (caller 2)[3]
Aresult
11
00
59 ($msg ?
60 "$msg in $caller" :
61 "$caller() called by " . ((caller(2))[3] || 'main')
62 ) .
63 "().\n";
64 }
65  
66  
67 2 ▶sub new($;) {
Subroutine new: called CC=8 SCAR=21.4
Pod documented
68 2 debug_msg;
69 2 my $class = shift;
70  
71 2 my %userargs = @_;
72 2 keys_to_lowercase(\%userargs);
73 # nb: support only arguments listed in @valid_args;
74 2 my @valid_args = (
75 'x', 'y', 'width', 'height',
76 'pad', 'padleft', 'padright', 'padtop', 'padbottom',
77 'ipad', 'ipadleft', 'ipadright', 'ipadtop', 'ipadbottom',
78 'wraparound',
79 'border', 'sbborder',
80 'bg', 'fg',
81 'intellidraw',
82 'onchange', 'onblur',
83 'routines', 'bindings',
84 'parent',
85 );
86 2 foreach my $arg (keys %userargs) {
87 5 ▶ unless (grep($arg eq "-$_", @valid_args)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (grep(($arg eq "-$_"), @valid_args)) 0 5 5
88 0 debug_msg " deleting invalid arg '$arg'";
89 0 delete $userargs{$arg};
90 }
91 }
92 2 my %args = (
93 -x => 0, # horizontal start position
94 -y => 0, # vertical start position
95 -width => undef, # width
96 -height => undef, # height (nb: including tabs)
97  
98 -ipadleft => 1, # left padding
99 -ipadright => 1, # right padding
100  
101 -wraparound => 1, # enable wraparound when changing pages?
102  
103 -border => 1, # border around tabs / active window
104  
105 -bg => -1, # default background color
106 -fg => -1, # default foreground color
107  
108 -intellidraw => 1,
109  
110 -routines => {%routines},
111 -bindings => {%bindings},
112  
113 %userargs,
114 );
115 2 foreach (sort keys %args) {
116 29 ▶ debug_msg " \$args{$_} = " . (defined $args{$_} ? $args{$_} : 'n/a');
Branch: 1 branch
BranchTrueFalseTotal
defined $args{$_} ? : 25 4 29
117 }
118  
119 # nb: some type of border is currently needed for tab labels.
120 2 ▶ return unless ($args{-border} or $args{-sbborder});
Branch: 1 branch
BranchTrueFalseTotal
unless $args{"-border"} or $args{"-sbborder"} 0 2 2
Condition66%2/3
$args{"-border"} or $args{"-sbborder"}
l!l&&r!l&&!r
110
MC/DC0%0/2
$args{"-border"} or $args{"-sbborder"}
$args{"-border"} $args{"-sbborder"}
Truth table66%2/3
A or B
A= $args{"-border"}B= $args{"-sbborder"}
ABresult
1X1
011
000
121  
122 # Create the widget.
123 2 debug_msg ' creating Notebook object';
124 2 my $this = $class->SUPER::new(%args);
125 2 ▶ if ($Curses::UI::ncurses_mouse) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Curses::UI::ncurses_mouse) 2 0 2
126 2 $this->set_mouse_binding(\&mouse_button1, BUTTON1_CLICKED());
127 }
128 2 @{$this->{-pages}} = (); # names of pages stored as an array.
129  
130 2 return $this;
131 }
132  
133  
134 2 ▶sub layout($) {
Subroutine layout: called CC=31 SCAR=39.9
Pod documented
135 2 debug_msg;
136 2 my $this = shift;
137  
138 # Don't wast time if we know the screen is too small.
139 2 ▶ return if ($Curses::UI::screen_too_small);
Branch: 1 branch
BranchTrueFalseTotal
if $Curses::UI::screen_too_small 0 2 2
140  
141 # Origin defaults to (0,0) relative to parent.
142 #
143 # nb: if origin is negative, treat it as an end-point and
144 # as relative to parent's end-point.
145 2 ▶ $this->{-y} = 0 unless (defined $this->{-y});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $this->{"-y"} 0 2 2
146 2 ▶ $this->{-x} = 0 unless (defined $this->{-x});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $this->{"-x"} 0 2 2
147  
148 # Expand -pad/-ipad args.
149 2 $this->process_padding;
150  
151 # Make sure there's enough space for the widget.
152 #
153 # - get parent's data.
154 2 $this->{-parentdata} = $this->{-parent}->windowparameters;
155 2 my $ph = $this->{-parentdata}->{-h};
156 2 my $pw = $this->{-parentdata}->{-w};
157 # - calculate space available to the widget.
158 2 ▶ my $avail_h = $ph - ($this->{-y} < 0 ? abs($this->{-y}+1) : $this->{-y});
Branch: 1 branch
BranchTrueFalseTotal
$this->{'-y'} < 0 ? : 0 2 2
159 2 ▶ my $avail_w = $pw - ($this->{-x} < 0 ? abs($this->{-x}+1) : $this->{-x});
Branch: 1 branch
BranchTrueFalseTotal
$this->{'-x'} < 0 ? : 0 2 2
160 2 debug_msg " available height / width = $avail_h / $avail_w";
161 # - size of widget defaults to available space.
162 2 ▶ my $h = (defined $this->{-height} ? $this->{-height} : $avail_h);
Branch: 1 branch
BranchTrueFalseTotal
defined $this->{'-height'} ? : 0 2 2
163 2 ▶ my $w = (defined $this->{-width} ? $this->{-width} : $avail_w);
Branch: 1 branch
BranchTrueFalseTotal
defined $this->{'-width'} ? : 0 2 2
164 2 debug_msg " size of widget = $h / $w";
165 # - calculate required size given borders, padding, etc.
166 my $req_h = ($this->{-border} ? 3 : 0) +
167 ($this->{-sbborder} ? 3 : 0) +
168 $this->{-padtop} +
169 2 ▶ $this->{-padbottom};
Branch: 2 branches
BranchTrueFalseTotal
$this->{'-border'} ? : 1 1 2
$this->{'-sbborder'} ? : 1 1 2
170 my $req_w = ($this->{-border} ? 2 : 0) +
171 ($this->{-sbborder} ? 2 : 0) +
172 $this->{-padleft} +
173 2 ▶ $this->{-padright};
Branch: 2 branches
BranchTrueFalseTotal
$this->{'-border'} ? : 1 1 2
$this->{'-sbborder'} ? : 1 1 2
174 2 debug_msg " required size of widget = $req_h / $req_w";
175 # - make sure widget fits given what's required and available.
176 2 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($h < $req_h or $h > $avail_h or $w < $req_w or $w > $avail_w) 0 2 2
Condition33%3/9
$h < $req_h or $h > $avail_h or $w < $req_w or $w > $avail_w
l!l&&r!l&&!r
002
$h < $req_h or $h > $avail_h or $w < $req_w
l!l&&r!l&&!r
002
$h < $req_h or $h > $avail_h
l!l&&r!l&&!r
002
MC/DC0%0/4
$h < $req_h or $h > $avail_h or $w < $req_w or $w > $avail_w
$h < $req_h $h > $avail_h $w < $req_w $w > $avail_w
Truth table20%1/5
A or B or C or D
A= $h < $req_hB= $h > $avail_hC= $w < $req_wD= $w > $avail_w
ABCDresult
1XXX1
01XX1
001X1
00011
00000
177 $h < $req_h or $h > $avail_h or
178 $w < $req_w or $w > $avail_w
179 ) {
180 0 debug_msg " screen is too small!";
181 0 $Curses::UI::screen_too_small++;
182 0 return $this;
183 }
184  
185 # Update some widget parameters.
186 #
187 # - height and width.
188 2 $this->{-h} = $h;
189 2 $this->{-w} = $w;
190 # - starting point.
191 # nb: keep in mind if origin is negative, (x,y) is an end-point
192 # relative to parent's end-point.
193 2 ▶ $this->{-realy} = $this->{-y} + ($this->{-y} >= 0 ? 0 : $ph - $h + 1);
Branch: 1 branch
BranchTrueFalseTotal
$this->{'-y'} >= 0 ? : 2 0 2
194 2 ▶ $this->{-realx} = $this->{-x} + ($this->{-x} >= 0 ? 0 : $pw - $w + 1);
Branch: 1 branch
BranchTrueFalseTotal
$this->{'-x'} >= 0 ? : 2 0 2
195  
196 # Create widget border, if desired.
197 2 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($this->{"-border"} or $this->{"-sbborder"}) 2 0 2
Condition66%2/3
$this->{"-border"} or $this->{"-sbborder"}
l!l&&r!l&&!r
110
MC/DC0%0/2
$this->{"-border"} or $this->{"-sbborder"}
$this->{"-border"} $this->{"-sbborder"}
Truth table66%2/3
A or B
A= $this->{"-border"}B= $this->{"-sbborder"}
ABresult
1X1
011
000
198 $this->{-border} or
199 $this->{-sbborder}
200 ) {
201 2 $this->{-bh} = $h - $this->{-padtop} - $this->{-padbottom};
202 2 $this->{-bw} = $w - $this->{-padleft} - $this->{-padright};
203 2 $this->{-by} = $this->{-realy} + $this->{-padtop};
204 2 $this->{-bx} = $this->{-realx} + $this->{-padleft};
205 my @args = (
206 $this->{-bh},
207 $this->{-bw},
208 $this->{-by},
209 $this->{-bx},
210 2 );
211 2 debug_msg " creating borderscr with args " . join(",", @args);
212 2 ▶ unless (
Branch: 1 branch
BranchTrueFalseTotal
unless ($this->{"-borderscr"} = $this->{"-parent"}{"-canvasscr"}->derwin(@args)) 0 2 2
213 $this->{-borderscr} = $this->{-parent}->{-canvasscr}->derwin(@args)
214 ) {
215 0 debug_msg " screen is too small for border widget!";
216 0 $Curses::UI::screen_too_small++;
217 0 return $this;
218 }
219 }
220  
221 # Create widget window itself.
222 $this->{-sh} = $this->{-bh} -
223 $this->{-ipadtop} -
224 $this->{-ipadbottom} -
225 ($this->{-border} ? 4 : 0) -
226 2 ▶ ($this->{-sbborder} ? 4 : 0);
Branch: 2 branches
BranchTrueFalseTotal
$this->{'-border'} ? : 1 1 2
$this->{'-sbborder'} ? : 1 1 2
227 $this->{-sw} = $this->{-bw} -
228 $this->{-ipadleft} -
229 $this->{-ipadright} -
230 ($this->{-border} ? 2 : 0) -
231 2 ▶ ($this->{-sbborder} ? 2 : 0);
Branch: 2 branches
BranchTrueFalseTotal
$this->{'-border'} ? : 1 1 2
$this->{'-sbborder'} ? : 1 1 2
232 $this->{-sy} = $this->{-by} +
233 $this->{-ipadtop} +
234 ($this->{-border} ? 3 : 0) +
235 2 ▶ ($this->{-sbborder} ? 3 : 0);
Branch: 2 branches
BranchTrueFalseTotal
$this->{'-border'} ? : 1 1 2
$this->{'-sbborder'} ? : 1 1 2
236 $this->{-sx} = $this->{-bx} +
237 $this->{-ipadleft} +
238 ($this->{-border} ? 1 : 0) +
239 2 ▶ ($this->{-sbborder} ? 1 : 0);
Branch: 2 branches
BranchTrueFalseTotal
$this->{'-border'} ? : 1 1 2
$this->{'-sbborder'} ? : 1 1 2
240 my @args = (
241 $this->{-sh},
242 $this->{-sw},
243 $this->{-sy},
244 $this->{-sx},
245 2 );
246 2 debug_msg " creating canvasscr with args " . join(",", @args);
247 2 $this->{-canvasscr} = $this->{-parent}->{-canvasscr}->derwin(@args);
248 2 ▶ unless (defined $this->{-canvasscr})
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $this->{"-canvasscr"}) 0 2 2
249 {
250 0 debug_msg " screen is too small for window widget!";
251 0 $Curses::UI::screen_too_small++;
252 0 return $this;
253 }
254  
255 2 ▶ unless (defined $this->{-borderscr}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $this->{"-borderscr"}) 0 2 2
256 0 $this->{-bh} = $this->{-sh};
257 0 $this->{-bw} = $this->{-sw};
258 0 $this->{-by} = $this->{-sy};
259 0 $this->{-bx} = $this->{-sx};
260 }
261 2 return $this;
262 }
263  
264  
265 0 ▶sub draw($;$) {
Subroutine draw: not called CC=51 SCAR=78.8
Pod documented
266 0 debug_msg;
267 0 my $this = shift;
268 0 ▶ my $no_doupdate = shift || 0;
Condition0%0/2
shift() || 0
l!l
00
MC/DC0%0/1
shift() || 0
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
269 0 debug_msg " \$no_doupdate = $no_doupdate";
270  
271 # Return immediately if this object is hidden or if
272 # the screen is currently too small.
273 0 ▶ return if $this->hidden;
Branch: 1 branch
BranchTrueFalseTotal
if $this->hidden 0 0 0
274 0 ▶ return if $Curses::UI::screen_too_small;
Branch: 1 branch
BranchTrueFalseTotal
if $Curses::UI::screen_too_small 0 0 0
275  
276 # Identify various pages of interest.
277 0 my $first_page = $this->first_page;
278 0 my $next_page = $this->next_page;
279 0 my $last_page = $this->last_page;
280 0 my $active_page = $this->active_page;
281  
282 # Identify page window.
283 0 my $page_win = $this->{-borderscr};
284  
285 # Hide cursor.
286 0 eval { curs_set(0) }; # not available on every system.
287  
288 # Enable colors if desired.
289 0 ▶ if ($Curses::UI::color_support) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Curses::UI::color_support) 0 0 0
290 0 debug_msg " enabling color support";
291 0 my $co = $Curses::UI::color_object;
292 my $pair = $co->get_color_pair(
293 $this->{-fg},
294 $this->{-bg}
295 0 );
296 0 $page_win->attron(COLOR_PAIR($pair));
297 }
298  
299 0 ▶ my $ch_hbar = $this->{-border} ? ACS_HLINE : '-';
Branch: 1 branch
BranchTrueFalseTotal
$this->{'-border'} ? : 0 0 0
300 0 ▶ my $ch_vbar = $this->{-border} ? ACS_VLINE : '|';
Branch: 1 branch
BranchTrueFalseTotal
$this->{'-border'} ? : 0 0 0
301 0 ▶ my $ch_tl = $this->{-border} ? ACS_ULCORNER : '+';
Branch: 1 branch
BranchTrueFalseTotal
$this->{'-border'} ? : 0 0 0
302 0 ▶ my $ch_tr = $this->{-border} ? ACS_URCORNER : '+';
Branch: 1 branch
BranchTrueFalseTotal
$this->{'-border'} ? : 0 0 0
303 0 ▶ my $ch_bl = $this->{-border} ? ACS_LLCORNER : '+';
Branch: 1 branch
BranchTrueFalseTotal
$this->{'-border'} ? : 0 0 0
304 0 ▶ my $ch_br = $this->{-border} ? ACS_LRCORNER : '+';
Branch: 1 branch
BranchTrueFalseTotal
$this->{'-border'} ? : 0 0 0
305 0 ▶ my $ch_ttee = $this->{-border} ? ACS_TTEE : '+';
Branch: 1 branch
BranchTrueFalseTotal
$this->{'-border'} ? : 0 0 0
306 0 ▶ my $ch_btee = $this->{-border} ? ACS_BTEE : '+';
Branch: 1 branch
BranchTrueFalseTotal
$this->{'-border'} ? : 0 0 0
307 0 ▶ my $ch_ltee = $this->{-border} ? ACS_LTEE : '+';
Branch: 1 branch
BranchTrueFalseTotal
$this->{'-border'} ? : 0 0 0
308 0 ▶ my $ch_rtee = $this->{-border} ? ACS_RTEE : '+';
Branch: 1 branch
BranchTrueFalseTotal
$this->{'-border'} ? : 0 0 0
309  
310 # Draw tabs along with a border if desired.
311 0 my($x, $y) = (0, 0);
312 0 ▶ $y = 1 if ($this->{-border} or $this->{-sbborder});
Branch: 1 branch
BranchTrueFalseTotal
if $this->{"-border"} or $this->{"-sbborder"} 0 0 0
Condition0%0/3
$this->{"-border"} or $this->{"-sbborder"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$this->{"-border"} or $this->{"-sbborder"}
$this->{"-border"} $this->{"-sbborder"}
Truth table0%0/3
A or B
A= $this->{"-border"}B= $this->{"-sbborder"}
ABresult
1X1
011
000
313 0 foreach my $page (@{$this->{-pages}}) {
314 0 debug_msg " drawing tab for page '$page'";
315  
316 0 ▶ if ($this->{-border} or $this->{-sbborder}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($this->{"-border"} or $this->{"-sbborder"}) 0 0 0
Condition0%0/3
$this->{"-border"} or $this->{"-sbborder"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$this->{"-border"} or $this->{"-sbborder"}
$this->{"-border"} $this->{"-sbborder"}
Truth table0%0/3
A or B
A= $this->{"-border"}B= $this->{"-sbborder"}
ABresult
1X1
011
000
317 0 debug_msg " adding left border at x=$x";
318 0 ▶ $page_win->addch(0, $x, ($page eq $first_page ? $ch_tl : $ch_ttee));
Branch: 1 branch
BranchTrueFalseTotal
$page eq $first_page ? : 0 0 0
319 0 $page_win->addch(1, $x, $ch_vbar);
320 0 ▶ $page_win->addch(2, $x,
Branch: 4 branches
BranchTrueFalseTotal
$page eq $first_page ? : 0 0 0
$page eq $active_page ? : 0 0 0
$page eq $active_page ? : 0 0 0
$page eq $next_page ? : 0 0 0
321 ($page eq $first_page ?
322 ($page eq $active_page ?
323 $ch_vbar :
324 $ch_ltee
325 ) :
326 ($page eq $active_page ?
327 $ch_br :
328 ($page eq $next_page ?
329 $ch_bl :
330 $ch_btee
331 )
332 )
333 )
334 );
335 0 ++$x;
336 }
337  
338 0 ▶ debug_msg " adding $this->{-ipadleft} space" . ($this->{-ipadright} == 1 ? "" : "s") . " of padding at x=$x";
Branch: 1 branch
BranchTrueFalseTotal
$this->{'-ipadright'} == 1 ? : 0 0 0
339 0 ▶ if ($this->{-border} or $this->{-sbborder}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($this->{'-border'} or $this->{'-sbborder'}) { } 0 0 0
Condition0%0/3
$this->{"-border"} or $this->{"-sbborder"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$this->{"-border"} or $this->{"-sbborder"}
$this->{"-border"} $this->{"-sbborder"}
Truth table0%0/3
A or B
A= $this->{"-border"}B= $this->{"-sbborder"}
ABresult
1X1
011
000
340 0 ▶ for (my $i = 0; $i < $this->{-ipadleft}; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $this->{"-ipadleft"}) 0 0 0
341 0 $page_win->addch(0, $x, $ch_hbar);
342 #
343 0 ▶ $page_win->addch(2, $x, ($page eq $active_page ? ' ' : $ch_hbar));
Branch: 1 branch
BranchTrueFalseTotal
$page eq $active_page ? : 0 0 0
344 0 ++$x;
345 }
346 }
347 else {
348 0 $x += $this->{-ipadleft};
349 }
350  
351 0 debug_msg " writing page name at x=$x";
352 0 ▶ $page_win->attron(A_REVERSE) if ($page eq $active_page);
Branch: 1 branch
BranchTrueFalseTotal
if $page eq $active_page 0 0 0
353 0 $page_win->addstr($y, $x, $page);
354 0 ▶ $page_win->attroff(A_REVERSE) if ($page eq $active_page);
Branch: 1 branch
BranchTrueFalseTotal
if $page eq $active_page 0 0 0
355 0 ▶ if ($this->{-border} or $this->{-sbborder}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($this->{'-border'} or $this->{'-sbborder'}) { } 0 0 0
Condition0%0/3
$this->{"-border"} or $this->{"-sbborder"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$this->{"-border"} or $this->{"-sbborder"}
$this->{"-border"} $this->{"-sbborder"}
Truth table0%0/3
A or B
A= $this->{"-border"}B= $this->{"-sbborder"}
ABresult
1X1
011
000
356 0 ▶ for (my $i = 0; $i < length($page); $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < length $page) 0 0 0
357 0 $page_win->addch(0, $x, $ch_hbar);
358 #
359 0 ▶ $page_win->addch(2, $x, ($page eq $active_page ? ' ' : $ch_hbar));
Branch: 1 branch
BranchTrueFalseTotal
$page eq $active_page ? : 0 0 0
360 0 ++$x;
361 }
362 }
363 else {
364 0 $x += length($page);
365 }
366  
367 0 ▶ debug_msg " adding $this->{-ipadright} space" . ($this->{-ipadright} == 1 ? "" : "s") . " of padding at x=$x";
Branch: 1 branch
BranchTrueFalseTotal
$this->{'-ipadright'} == 1 ? : 0 0 0
368 0 ▶ if ($this->{-border} or $this->{-sbborder}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($this->{'-border'} or $this->{'-sbborder'}) { } 0 0 0
Condition0%0/3
$this->{"-border"} or $this->{"-sbborder"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$this->{"-border"} or $this->{"-sbborder"}
$this->{"-border"} $this->{"-sbborder"}
Truth table0%0/3
A or B
A= $this->{"-border"}B= $this->{"-sbborder"}
ABresult
1X1
011
000
369 0 ▶ for (my $i = 0; $i < $this->{-ipadright}; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $this->{"-ipadright"}) 0 0 0
370 0 $page_win->addch(0, $x, $ch_hbar);
371 #
372 0 ▶ $page_win->addch(2, $x, ($page eq $active_page ? ' ' : $ch_hbar));
Branch: 1 branch
BranchTrueFalseTotal
$page eq $active_page ? : 0 0 0
373 0 ++$x;
374 }
375 }
376 else {
377 0 $x += $this->{-ipadright};
378 }
379  
380 0 ▶ if (($this->{-border} or $this->{-sbborder}) and $page eq $last_page) {
Branch: 1 branch
BranchTrueFalseTotal
if ($this->{"-border"} || $this->{"-sbborder"} and $page eq $last_page) 0 0 0
Condition0%0/6
$this->{"-border"} || $this->{"-sbborder"} and $page eq $last_page
!ll&&!rl&&r
000
$this->{"-border"} or $this->{"-sbborder"}
l!l&&r!l&&!r
000
MC/DC0%0/3
$this->{"-border"} || $this->{"-sbborder"} and $page eq $last_page
$this->{"-border"} $this->{"-sbborder"} $page eq $last_page
Truth table0%0/5
A or B and C
A= $this->{"-border"}B= $this->{"-sbborder"}C= $page eq $last_page
ABCresult
00X0
1X00
0100
1X11
0111
381 0 debug_msg " adding right border at x=$x";
382 0 $page_win->addch(0, $x, $ch_tr);
383 0 $page_win->addch(1, $x, $ch_vbar);
384 0 ▶ $page_win->addch(2, $x, ($page eq $active_page ? $ch_bl : $ch_btee));
Branch: 1 branch
BranchTrueFalseTotal
$page eq $active_page ? : 0 0 0
385 0 ++$x;
386 }
387 }
388 0 ▶ if ($this->{-border} or $this->{-sbborder}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($this->{"-border"} or $this->{"-sbborder"}) 0 0 0
Condition0%0/3
$this->{"-border"} or $this->{"-sbborder"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$this->{"-border"} or $this->{"-sbborder"}
$this->{"-border"} $this->{"-sbborder"}
Truth table0%0/3
A or B
A= $this->{"-border"}B= $this->{"-sbborder"}
ABresult
1X1
011
000
389 do {
390 0 $page_win->addch(2, $x, $ch_hbar);
391 0 ▶ } while (++$x < $this->{-bw}-1);
Branch: 1 branch
BranchTrueFalseTotal
++$x < $this->{"-bw"} - 1 and do { do { $page_win->addch(2, $x, $ch_hbar) } } 0 0 0
392 0 $page_win->addch(2, $x, $ch_tr);
393  
394 0 ▶ for ($y = 3; $y < $this->{-bh}-1; $y++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($y < $this->{"-bh"} - 1) 0 0 0
395 0 $page_win->addch($y, $this->{-x}, $ch_vbar);
396 0 $page_win->addch($y, $x, $ch_vbar);
397 }
398  
399 0 $page_win->addch($y, $this->{-x}, $ch_bl);
400 0 ▶ for ($x = $this->{-x}+1; $x < $this->{-bw}-1; $x++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($x < $this->{"-bw"} - 1) 0 0 0
401 0 $page_win->addch($y, $x, $ch_hbar);
402 }
403 0 $page_win->addch($y, $x, $ch_br);
404 }
405 0 $page_win->noutrefresh;
406  
407 # Draw active window.
408 0 $this->getobj($active_page)->draw($no_doupdate);
409  
410 0 ▶ doupdate unless ($no_doupdate);
Branch: 1 branch
BranchTrueFalseTotal
unless $no_doupdate 0 0 0
411 0 return $this;
412 }
413  
414  
415 # NB: we can't simply inherit intellidraw from Curses::UI::Widget
416 # since notebooks themselves contain window objects.
417 0 ▶sub intellidraw(;$) {
Subroutine intellidraw: not called CC=10 SCAR=47.0
Pod documented
418 0 debug_msg;
419 0 my $this = shift;
420  
421 0 ▶ if ($this->{-intellidraw} and !$this->hidden) {
Branch: 1 branch
BranchTrueFalseTotal
if ($this->{"-intellidraw"} and not $this->hidden) 0 0 0
Condition0%0/3
$this->{"-intellidraw"} and not $this->hidden
!ll&&!rl&&r
000
MC/DC0%0/2
$this->{"-intellidraw"} and not $this->hidden
$this->{"-intellidraw"} not $this->hidden
Truth table0%0/3
A and not(B)
A= $this->{"-intellidraw"}B= not $this->hidden
ABresult
0X0
100
111
422 # Check if parent window has modal focus or is on top of focus path.
423 0 my $parent = $this->parentwindow;
424 0 debug_msg " parent window = " . $parent;
425  
426 0 my @path = $this->root->focus_path;
427 0 debug_msg " focus_path " . join(" & ", @path);
428 # Ignore anything above our object.
429 0 ▶ while (grep($_ eq $this, @path)) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep(($_ eq $this), @path)) 0 0 0
430 0 $_ = pop(@path);
431 0 debug_msg " skipping $_ to find ourselves";
432 }
433 # Now find next window.
434 0 ▶ while (@path > 1 and !$path[-1]->isa('Curses::UI::Window')) {
Branch: 1 branch
BranchTrueFalseTotal
if (@path > 1 and not $path[-1]->isa("Curses::UI::Window")) 0 0 0
Condition0%0/3
@path > 1 and not $path[-1]->isa("Curses::UI::Window")
!ll&&!rl&&r
000
MC/DC0%0/2
@path > 1 and not $path[-1]->isa("Curses::UI::Window")
@path > 1 not $path[-1]->isa("Curses::UI::Window")
Truth table0%0/3
A and not(B)
A= @path > 1B= not $path[-1]->isa("Curses::UI::Window")
ABresult
0X0
100
111
435 0 $_ = pop(@path);
436 0 debug_msg " skipping $_ to find previous window";
437 }
438 0 ▶ debug_msg " next window = " . (@path ? $path[-1] : 'n/a');
Branch: 1 branch
BranchTrueFalseTotal
@path ? : 0 0 0
439  
440 $this->draw if (
441 $parent->{-has_modal_focus} or
442 0 ▶ (@path and $parent eq $path[-1])
Branch: 1 branch
BranchTrueFalseTotal
if $parent->{"-has_modal_focus"} or @path and $parent eq $path[-1] 0 0 0
Condition0%0/6
$parent->{"-has_modal_focus"} or @path and $parent eq $path[-1]
l!l&&r!l&&!r
000
@path and $parent eq $path[-1]
!ll&&!rl&&r
000
MC/DC0%0/3
$parent->{"-has_modal_focus"} or @path and $parent eq $path[-1]
$parent->{"-has_modal_focus"} @path $parent eq $path[-1]
Truth table0%0/4
A or B and C
A= $parent->{"-has_modal_focus"}B= @pathC= $parent eq $path[-1]
ABCresult
1XX1
0111
00X0
0100
443 );
444 }
445 0 return $this;
446 }
447  
448  
449 8 ▶sub add_page($$;) {
Subroutine add_page: called CC=12 SCAR=24.9
Pod documented
450 8 debug_msg;
451 8 my $this = shift;
452 8 ▶ my $page = shift or return;
Branch: 1 branch
BranchTrueFalseTotal
my $page = shift() or return 8 0 8
453 8 debug_msg " adding '$page' page";
454  
455 # Make sure page is not yet part of the notebook.
456 $this->root->fatalerror("The notebook already has a page named '$page'!")
457 8 ▶ if (defined $this->{-id2object}->{$page});
Branch: 1 branch
BranchTrueFalseTotal
if defined $this->{"-id2object"}{$page} 0 8 8
458  
459 # Make sure the page does not cause the 'tabs' window to overflow.
460 8 my $len = 0;
461 8 foreach my $page (@{$this->{-pages}}, $page) {
462 $len += length($page) +
463 ($this->{-ipadleft} || 0) + ($this->{-ipadright} || 0) +
464 17 ▶ ($this->{-border} || 0) + ($this->{-sbborder} || 0);
Condition75%6/8
$this->{'-ipadleft'} || 0
l!l
170
$this->{'-ipadright'} || 0
l!l
170
$this->{'-border'} || 0
l!l
116
$this->{'-sbborder'} || 0
l!l
611
MC/DC0%0/1
$this->{'-ipadleft'} || 0
$this->{'-ipadleft'}
MC/DC0%0/1
$this->{'-ipadright'} || 0
$this->{'-ipadright'}
MC/DC100%1/1
$this->{'-border'} || 0
$this->{'-border'}
MC/DC100%1/1
$this->{'-sbborder'} || 0
$this->{'-sbborder'}
Truth table50%1/2
A
A= $this->{'-ipadleft'}
Aresult
11
00
Truth table50%1/2
A
A= $this->{'-ipadright'}
Aresult
11
00
Truth table100%2/2
A
A= $this->{'-border'}
Aresult
11
00
Truth table100%2/2
A
A= $this->{'-sbborder'}
Aresult
11
00
465 }
466 8 ++$len; # nb: needed for final border char.
467 8 debug_msg " $len spaces are needed for tab labels";
468 8 ▶ if ($len > $this->{-bw}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($len > $this->{"-bw"}) 1 7 8
469 1 debug_msg " screen is too small - width is $this->{-bw}";
470 1 $Curses::UI::screen_too_small++;
471 1 return;
472 };
473  
474 # Create a window for this page using same layout as widget's canvasscr.
475 7 my %userargs = @_;
476 7 keys_to_lowercase(\%userargs);
477  
478 # grab callback arguments
479 7 foreach my $cbkey (qw/-on_activate -on_delete/) {
480 $this->{callback}{$page}{$cbkey} = delete $userargs{$cbkey}
481 14 ▶ if defined $userargs{$cbkey};
Branch: 1 branch
BranchTrueFalseTotal
if defined $userargs{$cbkey} 2 12 14
482 }
483  
484 $this->add(
485 $page, 'Window',
486  
487 -padtop => $this->{-padtop},
488 -padbottom => $this->{-padbottom},
489 -padleft => $this->{-padleft},
490 -padright => $this->{-padright},
491  
492 -ipadtop => $this->{-ipadtop},
493 -ipadbottom => $this->{-ipadbottom},
494 -ipadleft => $this->{-ipadleft},
495 -ipadright => $this->{-ipadright},
496  
497 -fg => $this->{-fg}, # nb: no color support in
498 -bg => $this->{-bg}, # Curses::UI::Window yet!
499  
500 %userargs,
501  
502 -height => $this->{-sh},
503 -width => $this->{-sw},
504 7 -y => 0, # nb: x,y are relative to canvasscr!
505 -x => 0,
506 );
507  
508 7 push(@{$this->{-pages}}, $page);
509 7 ▶ if (@{$this->{-pages}} == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$this->{'-pages'};} == 1) { } 3 4 7
510 3 $this->{-active_page} = $page;
511 }
512 else {
513 # Adding the window object alters the draw- and focusorder so
514 # we need to adjust them manually.
515 4 my $active_page = $this->active_page;
516 4 $this->set_draworder($active_page);
517 4 $this->set_focusorder($active_page);
518 }
519  
520 7 return $this->getobj($page);
521 }
522  
523  
524 4 ▶sub delete_page($$) {
Subroutine delete_page: called CC=5 SCAR=16.1
Pod documented
525 4 debug_msg;
526 4 my $this = shift;
527 4 ▶ my $page = shift or return;
Branch: 1 branch
BranchTrueFalseTotal
my $page = shift() or return 4 0 4
528  
529 # Make sure page is part of the notebook.
530 $this->root->fatalerror("The notebook widget does not have a page named '$page'!")
531 4 ▶ unless (defined $this->{-id2object}->{$page});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $this->{"-id2object"}{$page} 0 4 4
532  
533 4 debug_msg " deleting '$page' page";
534  
535 4 ▶ if (defined $this->{callback}{$page}{-on_delete}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $this->{"callback"}{$page}{"-on_delete"}) 1 3 4
536 1 debug_msg " calling delete callback for $page";
537 1 $this->{callback}{$page}{-on_delete}->($this,$page);
538 }
539  
540 4 my $active_page = $this->active_page;
541 4 @{$this->{-pages}} = grep($page ne $_, @{$this->{-pages}});
542 4 ▶ $this->activate_page($this->first_page) if ($page eq $active_page);
Branch: 1 branch
BranchTrueFalseTotal
if $page eq $active_page 3 1 4
543 4 $this->SUPER::DESTROY($page);
544  
545 4 return;
546 }
547  
548  
549 25 ▶sub active_page($) {
Subroutine active_page: called CC=3 SCAR=11.0
Pod documented
550 25 debug_msg;
551 25 my $this = shift;
552 25 ▶ return unless (@{$this->{-pages}});
Branch: 1 branch
BranchTrueFalseTotal
unless @{$this->{"-pages"};} 2 23 25
553  
554 my $page = defined $this->{-active_page} ?
555 $this->{-active_page} :
556 23 ▶ ($this->{-active_page} = '');
Branch: 1 branch
BranchTrueFalseTotal
defined $this->{'-active_page'} ? : 23 0 23
557 23 debug_msg " active page = '$page'";
558 23 return $page;
559 }
560  
561  
562 5 ▶sub first_page($) {
Subroutine first_page: called CC=2 SCAR=6.9
Pod documented
563 5 debug_msg;
564 5 my $this = shift;
565 5 ▶ return unless (@{$this->{-pages}});
Branch: 1 branch
BranchTrueFalseTotal
unless @{$this->{"-pages"};} 2 3 5
566  
567 3 my $page = ${$this->{-pages}}[0];
568 3 debug_msg " first page = '$page'";
569 3 return $page;
570 }
571  
572  
573 1 ▶sub last_page($) {
Subroutine last_page: called CC=2 SCAR=6.9
Pod documented
574 1 debug_msg;
575 1 my $this = shift;
576 1 ▶ return unless (@{$this->{-pages}});
Branch: 1 branch
BranchTrueFalseTotal
unless @{$this->{"-pages"};} 0 1 1
577  
578 1 my $page = ${$this->{-pages}}[$#{$this->{-pages}}];
579 1 debug_msg " last page = '$page'";
580 1 return $page;
581 }
582  
583  
584 2 ▶sub prev_page($) {
Subroutine prev_page: called CC=7 SCAR=19.6
Pod documented
585 2 debug_msg;
586 2 my $this = shift;
587 2 ▶ return unless (@{$this->{-pages}});
Branch: 1 branch
BranchTrueFalseTotal
unless @{$this->{"-pages"};} 0 2 2
588  
589 2 my $active_page = $this->active_page;
590 2 my $i = scalar(@{$this->{-pages}});
591 2 ▶ while (--$i >= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (--$i >= 0) 6 0 6
592 6 ▶ last if ($active_page eq ${$this->{-pages}}[$i]);
Branch: 1 branch
BranchTrueFalseTotal
if $active_page eq do { $$this{"-pages"} }->[$i] 2 4 6
593 }
594 2 ▶ return if ($i < 0);
Branch: 1 branch
BranchTrueFalseTotal
if $i < 0 0 2 2
595 $i = $i > 0 ?
596 $i-1 :
597 $this->{-wraparound} ?
598 2 ▶ $#{$this->{-pages}} :
Branch: 2 branches
BranchTrueFalseTotal
$i > 0 ? : 0 2 2
$this->{'-wraparound'} ? : 1 1 2
599 0;
600 2 my $page = ${$this->{-pages}}[$i];
601 2 debug_msg " prev page = '$page'";
602 2 return $page;
603 }
604  
605  
606 4 ▶sub next_page($) {
Subroutine next_page: called CC=7 SCAR=19.5
Pod documented
607 4 debug_msg;
608 4 my $this = shift;
609 4 ▶ return unless (@{$this->{-pages}});
Branch: 1 branch
BranchTrueFalseTotal
unless @{$this->{"-pages"};} 0 4 4
610  
611 4 my $active_page = $this->active_page;
612 4 my $i = scalar(@{$this->{-pages}});
613 4 ▶ while (--$i >= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (--$i >= 0) 6 0 6
614 6 ▶ last if ($active_page eq ${$this->{-pages}}[$i]);
Branch: 1 branch
BranchTrueFalseTotal
if $active_page eq do { $$this{"-pages"} }->[$i] 4 2 6
615 }
616 4 ▶ return if ($i < 0);
Branch: 1 branch
BranchTrueFalseTotal
if $i < 0 0 4 4
617 4 ▶ $i = $i < $#{$this->{-pages}} ?
Branch: 1 branch
BranchTrueFalseTotal
$this->{'-wraparound'} ? : 2 1 3
618 $i+1 :
619 $this->{-wraparound} ?
620 0 :
621 4 ▶ $#{$this->{-pages}};
Branch: 1 branch
BranchTrueFalseTotal
$i < $#{$$this{'-pages'};} ? : 1 3 4
622 4 my $page = ${$this->{-pages}}[$i];
623 4 debug_msg " next page = '$page'";
624 4 return $page;
625 }
626  
627  
628 7 ▶sub activate_page($$) {
Subroutine activate_page: called CC=6 SCAR=17.9
Pod documented
629 7 debug_msg;
630 7 my $this = shift;
631 7 ▶ my $page = shift or return;
Branch: 1 branch
BranchTrueFalseTotal
my $page = shift() or return 5 2 7
632  
633 # Make sure page is part of the notebook.
634 $this->root->fatalerror("The notebook widget does not have a page named '$page'!")
635 5 ▶ unless (defined $this->{-id2object}->{$page});
Branch: 1 branch
BranchTrueFalseTotal
unless defined $this->{"-id2object"}{$page} 0 5 5
636  
637 5 my $active_page = $this->active_page;
638 5 debug_msg " old active page = '$active_page'";
639  
640 5 ▶ if (defined $this->{callback}{$page}{-on_activate}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $this->{"callback"}{$page}{"-on_activate"}) 1 4 5
641 1 debug_msg " calling activate callback for $page";
642 1 $this->{callback}{$page}{-on_activate}->($this,$page);
643 }
644  
645 5 ▶ if ($active_page ne $page) {
Branch: 1 branch
BranchTrueFalseTotal
if ($active_page ne $page) 4 1 5
646 4 $active_page = $this->{-active_page} = $page;
647 4 debug_msg " new active page = '$active_page'";
648 4 $this->set_draworder($active_page);
649 4 $this->set_focusorder($active_page);
650  
651 # Redraw the notebook widget only if in curses mode.
652 4 ▶ $this->intellidraw unless isendwin;
Branch: 1 branch
BranchTrueFalseTotal
unless isendwin() 0 4 4
653 }
654 5 return $active_page;
655 }
656  
657  
658 0 ▶sub mouse_button1($$$$) {
Subroutine mouse_button1: not called CC=11 SCAR=48.8
Pod documented
659 0 debug_msg;
660 0 my $this = shift;
661 0 my $event = shift;
662 0 my $x = shift;
663 0 my $y = shift;
664  
665 0 my $ev_x = $event->{-x};
666 0 my $ev_y = $event->{-y};
667 0 debug_msg " mouse click at ($ev_x,$ev_y)";
668  
669 # Focus window if it isn't already in focus.
670 0 ▶ $this->focus if (not $this->{-focus} and $this->focusable);
Branch: 1 branch
BranchTrueFalseTotal
if not $this->{"-focus"} and $this->focusable 0 0 0
Condition0%0/3
not $this->{"-focus"} and $this->focusable
!ll&&!rl&&r
000
MC/DC0%0/2
not $this->{"-focus"} and $this->focusable
not $this->{"-focus"} $this->focusable
Truth table0%0/3
not(A) and B
A= not $this->{"-focus"}B= $this->focusable
ABresult
0X0
100
111
671  
672 # If click was in the 'tabs' window.
673 0 ▶ if ($ev_y <= ($this->{-border} + $this->{-sbborder} ? 3 : 1)) {
Branch: 2 branches
BranchTrueFalseTotal
if ($ev_y <= ($this->{'-border'} + $this->{'-sbborder'} ? 3 : 1)) { } 0 0 0
$this->{'-border'} + $this->{'-sbborder'} ? : 0 0 0
674 # Figure out which page was clicked.
675 0 my $len = 0;
676 0 foreach my $page (@{$this->{-pages}}) {
677 $len += length($page) +
678 ($this->{-ipadleft} || 0) + ($this->{-ipadright} || 0) +
679 0 ▶ ($this->{-border} || 0) + ($this->{-sbborder} || 0);
Condition0%0/8
$this->{'-ipadleft'} || 0
l!l
00
$this->{'-ipadright'} || 0
l!l
00
$this->{'-border'} || 0
l!l
00
$this->{'-sbborder'} || 0
l!l
00
MC/DC0%0/1
$this->{'-ipadleft'} || 0
$this->{'-ipadleft'}
MC/DC0%0/1
$this->{'-ipadright'} || 0
$this->{'-ipadright'}
MC/DC0%0/1
$this->{'-border'} || 0
$this->{'-border'}
MC/DC0%0/1
$this->{'-sbborder'} || 0
$this->{'-sbborder'}
Truth table0%0/2
A
A= $this->{'-ipadleft'}
Aresult
11
00
Truth table0%0/2
A
A= $this->{'-ipadright'}
Aresult
11
00
Truth table0%0/2
A
A= $this->{'-border'}
Aresult
11
00
Truth table0%0/2
A
A= $this->{'-sbborder'}
Aresult
11
00
680 0 ▶ if ($ev_x < $len) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ev_x < $len) 0 0 0
681 0 debug_msg " user clicked on tab for '$page'";
682 0 return $this->activate_page($page);
683 }
684 }
685 0 debug_msg " user didn't click on a tab label; ignored";
686 }
687 else {
688 0 my $active_page = $this->active_page;
689 0 debug_msg " user clicked on window of active page";
690 0 $this->getobj($active_page)->mouse_button1($event, $x, $y);
691 }
692 }
693  
694 1 1;
695  
696  
697 =pod
698  
699 =head1 NAME
700  
701 Curses::UI::Notebook - Create and manipulate notebook widgets.
702  
703  
704 =head1 CLASS HIERARCHY
705  
706 Curses::UI::Widget
707 |
708 +----Curses::UI::Container
709 |
710 +----Curses::UI::Notebook
711  
712  
713 =head1 SYNOPSIS
714  
715 use Curses::UI;
716 my $cui = new Curses::UI;
717 my $win = $cui->add(undef, 'Window');
718  
719 my $notebook = $win->add(undef, 'Notebook');
720 my $page1 = $notebook->add_page('page 1');
721 $page1->add(
722 undef, 'Label',
723 -x => 15,
724 -y => 6,
725 -text => "Page #1.",
726 );
727 my $page2 = $notebook->add_page('page 2');
728 $page2->add(
729 undef, 'Label',
730 -x => 15,
731 -y => 6,
732 -text => "Page #2.",
733 );
734 my $page3 = $notebook->add_page('page 3', -on_activate => \&sub );
735 $page3->add(
736 undef, 'Label',
737 -x => 15,
738 -y => 6,
739 -text => "Page #3.",
740 );
741 $notebook->focus;
742 $cui->mainloop;
743  
744  
745 =head1 DESCRIPTION
746  
747 This package implements a I<notebook widget> similar to that found in
748 Motif. A I<notebook> holds several windows, or I<pages>, only one of
749 which is visible at any given time; tabs at the top of the widget list
750 the pages that are available. In this way, a great deal of information
751 can be fit into a relatively small screen area. [Windows users might
752 recognize this as a I<tabbed dialog>.]
753  
754  
755 =head1 STANDARD OPTIONS
756  
757 B<-x>, B<-y>, B<-width>, B<-height>,
758 B<-pad>, B<-padleft>, B<-padright>, B<-padtop>, B<-padbottom>,
759 B<-ipad>, B<-ipadleft>, B<-ipadright>, B<-ipadtop>, B<-ipadbottom>,
760 B<-border>, B<-sbborder>,
761 B<-bg>, B<-fg>,
762 B<-intellidraw>,
763 B<-onchange>, B<-onblur>.
764  
765 See L<Curses::UI::Widget|Curses::UI||Widget> for a discussion of each of
766 these options.
767  
768 Note that B<-border> is enabled and both B<-ipadleft> and B<-ipadright>
769 are set to C<1> by default when creating notebook objects.
770  
771  
772 =head1 WIDGET-SPECIFIC OPTIONS
773  
774 =over 4
775  
776 =item * B<-bindings> < HASHREF >
777  
778 The keys in this hash reference are keystrokes and the values are
779 routines to which they should be bound. In the event a key is empty,
780 the corresponding routine will become the default routine that
781 B<process_bindings> applies to unmatched keystrokes it receives.
782  
783 By default, the following mappings are used:
784  
785 KEY ROUTINE
786 ------------------ ----------
787 KEY_HOME, Ctrl-A first_page
788 KEY_END, Ctrl-E last_page
789 KEY_NPAGE, Ctrl-N next_page
790 KEY_PPAGE, Ctrl-P prev_page
791  
792 =item * B<-routines> < HASHREF >
793  
794 The keys in this hash reference are routines and the values are either
795 scalar values or code references. B<process_bindings> maps keystrokes
796 to routines and then to either a scalar value, which it returns, or a
797 code reference, which it executes.
798  
799 By default, the following mappings are used:
800  
801 ROUTINE ACTION
802 ---------- -------------------------
803 first_page make first page active
804 last_page make last page active
805 next_page make next page active
806 prev_page make previous page active
807  
808 =item * B<-wraparound> < BOOLEAN >
809  
810 If BOOLEAN has a true value, wraparound is enabled. This means that
811 advancing to the next page will cycle from the last back to the first
812 page and similarly, advancing to the previous page will cycle from the
813 first back to the last page.
814  
815 By default, it is true.
816  
817 =back
818  
819  
820 =head1 METHODS
821  
822 =over 4
823  
824 =item * B<new> ( OPTIONS )
825  
826 Constructs a new notebook object using options in the hash OPTIONS.
827  
828 =item * B<layout> ( )
829  
830 Lays out the notebook object, makes sure it fits on the available
831 screen, and creates the curses windows for the border / tab labels as
832 well as the effective drawing area.
833  
834 =item * B<draw> ( BOOLEAN )
835  
836 Draws the notebook object along with the active page's window. If BOOLEAN
837 is true, the screen is not updated after drawing.
838  
839 By default, BOOLEAN is true so the screen is updated.
840  
841 =item * B<intellidraw> ( )
842  
843 =item * B<focus> ( )
844  
845 =item * B<onFocus> ( CODEREF )
846  
847 =item * B<onBlur> ( CODEREF )
848  
849 See L<Curses::UI::Widget|Curses::UI::Widget> for explanations of these
850 methods.
851  
852 =item * B<add_page> ( PAGE [ , -on_activate => sub_ref ] [, -on_delete => ] )
853  
854 Adds the specified page to the notebook object and creates an associated
855 window object. Returns the window object or undef on failure.
856  
857 Note: the add fails if the page would otherwise cause the tab window to
858 overflow or is already part of the notebook object.
859  
860 The C<-on_activate> parameter specifies an optional call-back that
861 will be invoked when the page is activated. This call-back will be
862 called with the notebook widget and page name as parameter.
863  
864 Likewise for C<-on_delete> call-back. This one is invoked when the
865 page is deleted.
866  
867 =item * B<delete_page> ( PAGE )
868  
869 Deletes the specified page from the notebook object and destroys its
870 associated window object. If the page was active, the first page is
871 made active.
872  
873 =item * B<active_page> ( )
874  
875 Returns the currently active page in the notebook object.
876  
877 =item * B<first_page> ( )
878  
879 Returns the first page in the notebook object.
880  
881 =item * B<last_page> ( )
882  
883 Returns the last page in the notebook object.
884  
885 =item * B<prev_page> ( )
886  
887 Returns the previous page in the notebook object.
888  
889 =item * B<next_page> ( )
890  
891 Returns the next page in the notebook object.
892  
893 =item * B<activate_page> ( PAGE )
894  
895 Makes the specified page in the notebook object active and returns it,
896 redrawing the notebook object in the process.
897  
898 =item * B<mouse_button1> ( )
899  
900 Processes mouse button #1 clicks. If the user left-clicks on one of the
901 tabs, B<activate_page> is called with the corresponding page to make it
902 active; otherwise, the click is passed along to the active window.
903  
904 =back
905  
906  
907 =head1 SEE ALSO
908  
909 L<Curses::UI|Curses::UI>,
910 L<Curses::UI::Container|Curses::UI::Container>,
911 L<Curses::UI::Widget|Curses::UI::Widget>
912  
913  
914 =head1 AUTHOR
915  
916 George A. Theall, E<lt>theall@tifaware.comE<gt>
917  
918  
919 =head1 COPYRIGHT AND LICENSE
920  
921 Copyright (c) 2004, George A. Theall. All rights reserved.
922  
923 This script is free software; you can redistribute it and/or modify
924 it under the same terms as Perl itself.
↑ Summary blib/lib/Curses/UI/Widget.pm »