blib/lib/Curses/UI/Listbox.pm

filter: Statementstmt 34.9% 118 / 338 Branchbran 16.8% 26 / 154 Conditioncond 9.3% 6 / 64 MC/DCmcdc 0.0% 0 / 37 Subroutinesub 48.7% 20 / 41 Podpod 54.5% 18 / 33 totaltotal 28.1% 188 / 667 CC 104 SCAR 46.8
CC
104
Cov
27%
draw
489.1
option_check
56.0
option_select
42.0
CRAP 108.2
« lib/Curses/UI/Common.pm ↑ Summary blib/lib/Curses/UI/Progressbar.pm »
1 # ----------------------------------------------------------------------
2 # Curses::UI::Listbox
3 #
4 # (c) 2001-2002 by Maurice Makaay. All rights reserved.
5 # (c) 2003-2005 by Marcus Thiesen.
6 # This file is part of Curses::UI. Curses::UI is free software.
7 # You can redistribute it and/or modify it under the same terms
8 # as perl itself.
9 #
10 # Currently maintained by Marcus Thiesen
11 # e-mail: marcus@cpan.thiesenweb.de
12 # ----------------------------------------------------------------------
13  
14 package Curses::UI::Listbox;
15  
16 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 1 ▶use Curses;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 1 ▶use Curses::UI::Common;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 1 ▶use Curses::UI::Widget;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 1 ▶use Curses::UI::TextEntry;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 1 ▶use Curses::UI::TextViewer;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 1 ▶use Curses::UI::Searchable;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 1 require Exporter;
24  
25 1 ▶use vars qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
26 $VERSION
27 @ISA
28 @EXPORT
29 1 );
30  
31 1 $VERSION = '1.3';
32  
33 1 @ISA = qw(
34 Curses::UI::Widget Curses::UI::Common
35 Curses::UI::Searchable Exporter
36 );
37  
38 1 @EXPORT = qw(
39 maxlabelwidth
40 );
41  
42 1 my %routines = (
43 'loose-focus' => \&loose_focus,
44 'option-select' => \&option_select,
45 'option-check' => \&option_check,
46 'option-uncheck' => \&option_uncheck,
47 'option-next' => \&option_next,
48 'option-prev' => \&option_prev,
49 'option-nextpage' => \&option_nextpage,
50 'option-prevpage' => \&option_prevpage,
51 'option-first' => \&option_first,
52 'option-last' => \&option_last,
53 'search-forward' => \&search_forward,
54 'search-backward' => \&search_backward,
55 'mouse-button1' => \&mouse_button1,
56 );
57  
58 1 my %bindings = (
59 KEY_LEFT() => 'loose-focus',
60 "h" => 'loose-focus',
61 CUI_TAB() => 'loose-focus',
62 KEY_BTAB() => 'loose-focus',
63 KEY_ENTER() => 'option-select',
64 KEY_RIGHT() => 'option-select',
65 "l" => 'option-select',
66 CUI_SPACE() => 'option-select',
67 "1" => 'option-check',
68 "y" => 'option-check',
69 "0" => 'option-uncheck',
70 "n" => 'option-uncheck',
71 KEY_DOWN() => 'option-next',
72 "j" => 'option-next',
73 KEY_NPAGE() => 'option-nextpage',
74 KEY_UP() => 'option-prev',
75 "k" => 'option-prev',
76 KEY_PPAGE() => 'option-prevpage',
77 KEY_HOME() => 'option-first',
78 "\cA" => 'option-first',
79 KEY_END() => 'option-last',
80 "\cE" => 'option-last',
81 "/" => 'search-forward',
82 "?" => 'search-backward',
83 );
84  
85 sub new ()
86 1 ▶{
Subroutine new: called CC=5 SCAR=18.0
Pod documented
87 1 my $class = shift;
88  
89 1 my %userargs = @_;
90 1 keys_to_lowercase(\%userargs);
91  
92 1 my %args = (
93 -values => [], # values to show
94 -labels => {}, # optional labels for the values
95 -active => 0, # the activated value
96 -width => undef, # the width of the listbox
97 -height => undef, # the height of the listbox
98 -x => 0, # the hor. pos. rel. to parent
99 -y => 0, # the vert. pos. rel. to parent
100 -multi => 0, # multiselection possible?
101 -radio => 0, # show radio buttons? Only for ! -multi
102 -selected => undef, # the selected item
103 -wraparound => 0, # wraparound on first/last item
104 -onchange => undef, # onChange event handler
105 -onselchange=> undef, # onSelectionChange event handler
106  
107 -bg => -1,
108 -fg => -1,
109
110 %userargs,
111  
112 -routines => {%routines},
113 -bindings => {%bindings},
114  
115 -yscrpos => 0, # Value init
116 -focus => 0, # Value init
117 -nocursor => 1, # This widget does not use a cursor
118 );
119  
120 1 ▶ if ($args{-multi})
Branch: 1 branch
BranchTrueFalseTotal
if ($args{'-multi'}) { } 0 1 1
121 {
122 0 $args{-radio} = 0;
123 $args{-selected} = {}
124 0 ▶ unless ref $args{-selected} eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $args{"-selected"} eq "HASH" 0 0 0
125 0 $args{-ypos} = 0;
126 } else {
127 1 ▶ $args{-ypos} = defined $args{-selected} ? $args{-selected} : 0;
Branch: 1 branch
BranchTrueFalseTotal
defined $args{'-selected'} ? : 0 1 1
128 }
129  
130 1 my $this = $class->SUPER::new( %args );
131 1 $this->layout_content();
132  
133 1 ▶ if ($Curses::UI::ncurses_mouse) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Curses::UI::ncurses_mouse) 1 0 1
134 1 $this->set_mouse_binding('mouse-button1', BUTTON1_CLICKED());
135 1 $this->set_mouse_binding('mouse-button1', BUTTON1_DOUBLE_CLICKED());
136 }
137  
138 1 return $this;
139 }
140  
141 1 ▶sub onChange(;$) { shift()->set_event('-onchange', shift()) }
Subroutine onChange: called CC=1 SCAR=0.0
Pod documented
142  
143 0 ▶sub onSelectionChange(;$) { shift()->set_event('-onselchange', shift()) };
Subroutine onSelectionChange: not called CC=1 SCAR=6.9
Pod documented
144  
145 sub values(;$)
146 1 ▶{
Subroutine values: called CC=6 SCAR=20.2
Pod documented
147 1 my $this = shift;
148 1 my $values = shift;
149  
150 1 ▶ if (defined $values && ! ref $values) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $values and not ref $values) 0 1 1
Condition33%1/3
defined $values and not ref $values
!ll&&!rl&&r
010
MC/DC0%0/2
defined $values and not ref $values
defined $values not ref $values
Truth table33%1/3
A and not(B)
A= defined $valuesB= not ref $values
ABresult
0X0
100
111
151 0 $values = [ $values, @_ ];
152 }
153
154 1 ▶ if (defined $values and ref $values eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $values and ref $values eq "ARRAY") 1 0 1
Condition33%1/3
defined $values and ref $values eq "ARRAY"
!ll&&!rl&&r
001
MC/DC0%0/2
defined $values and ref $values eq "ARRAY"
defined $values ref $values eq "ARRAY"
Truth table33%1/3
A and B
A= defined $valuesB= ref $values eq "ARRAY"
ABresult
0X0
100
111
155 # Clear and go to first item if we get new data
156 1 $this->clear_selection();
157  
158 1 $this->{-values} = $values;
159 1 ▶ $this->option_first() if defined $values;
Branch: 1 branch
BranchTrueFalseTotal
if defined $values 1 0 1
160  
161 # Make this widget non-focusable if there are
162 # no values in it.
163 1 $this->focusable(scalar(@{$values}));
164 }
165  
166 return $this->{-values}
167 1 }
168  
169 sub insert_at()
170 0 ▶{
Subroutine insert_at: not called CC=3 SCAR=24.8
Pod documented
171
172 0 my $this = shift;
173 0 my $pos = shift;
174 0 my $values = shift;
175  
176 # Clear and go to first item if we get new data
177 0 $this->clear_selection();
178  
179 0 ▶ if (defined $values ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $values) 0 0 0
180 0 ▶ if (ref $values eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $values eq 'ARRAY') { } 0 0 0
181 0 my @newdata = (splice(@{$this->{-values}},0,$pos - 1), @{$values},
182 0 @{$this->{-values}});
183  
184 0 $this->{-values} = \@newdata;
185 } else {
186 0 my @newdata = (splice (@{$this->{-values}},0,$pos - 1), $values,
187 0 @{$this->{-values}});
188  
189 0 $this->{-values} = \@newdata;
190 }
191 }
192  
193 0 return $this->{-values};
194  
195 }
196  
197 sub labels(;$)
198 0 ▶{
Subroutine labels: not called CC=3 SCAR=24.8
Pod documented
199 0 my $this = shift;
200 0 my $labels = shift;
201  
202 0 ▶ if (defined $labels and ref $labels eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $labels and ref $labels eq "HASH") 0 0 0
Condition0%0/3
defined $labels and ref $labels eq "HASH"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $labels and ref $labels eq "HASH"
defined $labels ref $labels eq "HASH"
Truth table0%0/3
A and B
A= defined $labelsB= ref $labels eq "HASH"
ABresult
0X0
100
111
203 0 $this->{-labels} = $labels;
204 }
205 return $this->{-labels}
206 0 }
207  
208  
209 sub add_labels(;$)
210 0 ▶{
Subroutine add_labels: not called CC=3 SCAR=24.8
Pod documented
211 0 my $this = shift;
212 0 my $labels = shift;
213  
214 0 ▶ if (defined $labels and ref $labels eq 'HASH') {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $labels and ref $labels eq "HASH") 0 0 0
Condition0%0/3
defined $labels and ref $labels eq "HASH"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $labels and ref $labels eq "HASH"
defined $labels ref $labels eq "HASH"
Truth table0%0/3
A and B
A= defined $labelsB= ref $labels eq "HASH"
ABresult
0X0
100
111
215 0 map $this->{-labels}->{$_} = $labels->{$_}, keys %{$labels};
216 }
217 return $this->{-labels}
218 0 }
219  
220  
221 sub maxlabelwidth(@)
222 0 ▶{
Subroutine maxlabelwidth: not called CC=4 SCAR=30.0
Pod undocumented
223 0 my %args = @_;
224
225 0 my $maxwidth = 0;
226 0 foreach my $value (@{$args{-values}})
227 {
228 0 my $label = $value;
229 $label = $args{-labels}->{$value}
230 0 ▶ if defined $args{-labels}->{$value};
Branch: 1 branch
BranchTrueFalseTotal
if defined $args{"-labels"}{$value} 0 0 0
231 0 ▶ $maxwidth = length($label)
Branch: 1 branch
BranchTrueFalseTotal
if length $label > $maxwidth 0 0 0
232 if length($label) > $maxwidth;
233 }
234 0 return $maxwidth;
235 }
236  
237 sub layout()
238 1 ▶{
Subroutine layout: called CC=4 SCAR=16.1
Pod documented
239 1 my $this = shift;
240 1 ▶ $this->SUPER::layout() or return;
Branch: 1 branch
BranchTrueFalseTotal
$this->SUPER::layout or return 1 0 1
241
242 1 $this->layout_content;
243  
244 # Scroll up if we can and the number of visible lines
245 # is smaller than the number of available lines in the screen.
246 my $inscreen = ($this->canvasheight
247 1 - ($this->number_of_lines - $this->{-yscrpos}));
248 1 ▶ while ($this->{-yscrpos} > 0 and $inscreen < $this->canvasheight)
Branch: 1 branch
BranchTrueFalseTotal
if ($this->{"-yscrpos"} > 0 and $inscreen < $this->canvasheight) 0 1 1
Condition33%1/3
$this->{"-yscrpos"} > 0 and $inscreen < $this->canvasheight
!ll&&!rl&&r
100
MC/DC0%0/2
$this->{"-yscrpos"} > 0 and $inscreen < $this->canvasheight
$this->{"-yscrpos"} > 0 $inscreen < $this->canvasheight
Truth table33%1/3
A and B
A= $this->{"-yscrpos"} > 0B= $inscreen < $this->canvasheight
ABresult
0X0
100
111
249 {
250 0 $this->{-yscrpos}--;
251 $inscreen = ($this->canvasheight
252 0 - ($this->number_of_lines - $this->{-yscrpos}));
253 }
254  
255 1 return $this;
256 }
257  
258 sub layout_content()
259 5 ▶{
Subroutine layout_content: called CC=7 SCAR=20.8
Pod documented
260 5 my $this = shift;
261 5 ▶ return $this if $Curses::UI::screen_too_small;
Branch: 1 branch
BranchTrueFalseTotal
if $Curses::UI::screen_too_small 0 5 5
262  
263 # Check bounds for -ypos index.
264 5 $this->{-max_selected} = @{$this->{-values}} - 1;
265 $this->{-ypos} = $this->{-max_selected}
266 5 ▶ if $this->{-ypos} > $this->{-max_selected};
Branch: 1 branch
BranchTrueFalseTotal
if $this->{"-ypos"} > $this->{"-max_selected"} 5 0 5
267 5 ▶ $this->{-ypos} = 0 if $this->{-ypos} < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $this->{"-ypos"} < 0 5 0 5
268  
269 # Scroll down if needed.
270 5 my $ycur = $this->{-ypos} - $this->{-yscrpos};
271 5 ▶ if ( $ycur > ($this->canvasheight-1)) {
Branch: 2 branches
BranchTrueFalseTotal
if ($ycur > $this->canvasheight - 1) { } 0 5 5
elsif ($ycur < 0) { } 0 5 5
272 0 $this->{-yscrpos} = $this->{-ypos} - $this->canvasheight + 1;
273 }
274 # Scroll up if needed.
275 elsif ( $ycur < 0 ) {
276 0 $this->{-yscrpos} = $this->{-ypos};
277 }
278  
279  
280 5 $this->{-vscrolllen} = @{$this->{-values}};
281 5 $this->{-vscrollpos} = $this->{-yscrpos};
282 5 ▶ if ( @{$this->{-values}} <= $this->canvasheight) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$this->{"-values"};} <= $this->canvasheight) 5 0 5
283 5 undef $this->{-vscrolllen};
284 }
285  
286 5 return $this;
287 }
288  
289 sub getlabel($;)
290 0 ▶{
Subroutine getlabel: not called CC=3 SCAR=24.8
Pod undocumented
291 0 my $this = shift;
292 0 ▶ my $idx = 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
293  
294 0 my $value = $this->{-values}->[$idx];
295 0 my $label = $value;
296 $label = $this->{-labels}->{$label}
297 0 ▶ if defined $this->{-labels}->{$label};
Branch: 1 branch
BranchTrueFalseTotal
if defined $this->{"-labels"}{$label} 0 0 0
298 0 $label =~ s/\t/ /g; # do not show TABs
299
300 0 return $label;
301 }
302  
303  
304 sub get_active_value($;)
305 1 ▶{
Subroutine get_active_value: called CC=1 SCAR=0.0
Pod documented
306 1 my $this = shift;
307 1 my $id = $this->{-ypos};
308 1 my $value = $this->{'-values'}->[$id];
309 1 return $value;
310 }
311  
312 sub get_active_id($;)
313 0 ▶{
Subroutine get_active_id: not called CC=1 SCAR=6.9
Pod documented
314 0 my $this = shift;
315 0 return $this->{-ypos};;
316 }
317  
318 sub draw(;$)
319 3 ▶{
Subroutine draw: called CC=28 SCAR=61.9
Pod documented
320 3 my $this = shift;
321 3 ▶ my $no_doupdate = shift || 0;
Condition50%1/2
shift() || 0
l!l
30
MC/DC0%0/1
shift() || 0
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
322  
323 # Draw the widget
324 3 ▶ $this->SUPER::draw(1) or return $this;
Branch: 1 branch
BranchTrueFalseTotal
$this->SUPER::draw(1) or return $this 3 0 3
325  
326 3 $this->layout_content;
327  
328 # Let there be color
329 3 ▶ if ($Curses::UI::color_support) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Curses::UI::color_support) 0 3 3
330 0 my $co = $Curses::UI::color_object;
331 my $pair = $co->get_color_pair(
332 $this->{-fg},
333 0 $this->{-bg});
334  
335 0 $this->{-canvasscr}->attron(COLOR_PAIR($pair));
336  
337 }
338  
339 # No values?
340 3 ▶ if (not @{$this->{-values}})
Branch: 1 branch
BranchTrueFalseTotal
if (not @{$this->{'-values'};}) { } 3 0 3
341 {
342 3 $this->{-canvasscr}->attron(A_DIM);
343 3 $this->{-canvasscr}->addstr(0,0,'- no values -');
344 3 $this->{-canvasscr}->attroff(A_DIM);
345  
346 # There are values. Show them!
347 } else {
348 0 my $start_idx = $this->{-yscrpos};
349 0 my $end_idx = $this->{-yscrpos} + $this->canvasheight - 1;
350 $end_idx = $this->{-max_selected}
351 0 ▶ if $end_idx > $this->{-max_selected};
Branch: 1 branch
BranchTrueFalseTotal
if $end_idx > $this->{"-max_selected"} 0 0 0
352  
353 0 my $y = 0;
354 0 my $cursor_y = 0;
355 0 my $cursor_x = 0;
356 0 for my $i ($start_idx .. $end_idx)
357 {
358 # The label to print.
359 0 my $label = $this->getlabel($i);
360  
361 # Clear up label.
362 0 $label =~ s/\n|\r//g;
363  
364 # Needed space for prefix.
365 my $prefix_len =
366 0 ▶ (($this->{-multi} or $this->{-radio}) ? 4 : 0);
Branch: 1 branch
BranchTrueFalseTotal
$this->{'-multi'} || $this->{'-radio'} ? : 0 0 0
Condition0%0/3
$this->{"-multi"} or $this->{"-radio"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$this->{"-multi"} or $this->{"-radio"}
$this->{"-multi"} $this->{"-radio"}
Truth table0%0/3
A or B
A= $this->{"-multi"}B= $this->{"-radio"}
ABresult
1X1
011
000
367  
368 # Chop length if needed.
369 0 $label = $this->text_chop($label, ($this->canvaswidth-$prefix_len));
370  
371 # Show current entry in reverse mode and
372 # save cursor position.
373 0 ▶ if ($this->{-ypos} == $i and $this->{-focus})
Branch: 1 branch
BranchTrueFalseTotal
if ($this->{"-ypos"} == $i and $this->{"-focus"}) 0 0 0
Condition0%0/3
$this->{"-ypos"} == $i and $this->{"-focus"}
!ll&&!rl&&r
000
MC/DC0%0/2
$this->{"-ypos"} == $i and $this->{"-focus"}
$this->{"-ypos"} == $i $this->{"-focus"}
Truth table0%0/3
A and B
A= $this->{"-ypos"} == $iB= $this->{"-focus"}
ABresult
0X0
100
111
374 {
375 0 $this->{-canvasscr}->attron(A_REVERSE);
376 0 $cursor_y = $y;
377 0 $cursor_x = $this->canvaswidth-1;
378 }
379  
380 # Show selected element bold.
381 0 ▶ if ( ( not $this->{-multi}
Branch: 1 branch
BranchTrueFalseTotal
if (not $this->{"-multi"} and defined $this->{"-selected"} and $this->{"-selected"} == $i or $this->{"-multi"} and defined $this->{"-selected"} and $this->{"-selected"}{$i}) 0 0 0
Condition0%0/15
not $this->{"-multi"} and defined $this->{"-selected"} and $this->{"-selected"} == $i or $this->{"-multi"} and defined $this->{"-selected"} and $this->{"-selected"}{$i}
l!l&&r!l&&!r
000
not $this->{"-multi"} and defined $this->{"-selected"} and $this->{"-selected"} == $i
!ll&&!rl&&r
000
not $this->{"-multi"} and defined $this->{"-selected"}
!ll&&!rl&&r
000
$this->{"-multi"} and defined $this->{"-selected"} and $this->{"-selected"}{$i}
!ll&&!rl&&r
000
$this->{"-multi"} and defined $this->{"-selected"}
!ll&&!rl&&r
000
MC/DC0%0/6
not $this->{"-multi"} and defined $this->{"-selected"} and $this->{"-selected"} == $i or $this->{"-multi"} and defined $this->{"-selected"} and $this->{"-selected"}{$i}
not $this->{"-multi"} defined $this->{"-selected"} $this->{"-selected"} == $i $this->{"-multi"} defined $this->{"-selected"} $this->{"-selected"}{$i}
Truth table0%0/13
not(A) and B and C or D and E and F
A= not $this->{"-multi"}B= defined $this->{"-selected"}C= $this->{"-selected"} == $iD= $this->{"-multi"}E= defined $this->{"-selected"}F= $this->{"-selected"}{$i}
ABCDEFresult
111XXX1
0XX1111
10X1111
1101111
0XX0XX0
0XX10X0
0XX1100
10X0XX0
10X10X0
10X1100
1100XX0
11010X0
1101100
382 and defined $this->{-selected}
383 and $this->{-selected} == $i)
384 or ( $this->{-multi}
385 and defined $this->{-selected}
386 and $this->{-selected}->{$i}) ) {
387 0 $this->{-canvasscr}->attron(A_BOLD);
388 }
389
390 # Make full line reverse or blank
391 $this->{-canvasscr}->addstr(
392 0 $y, $prefix_len,
393 " "x($this->canvaswidth-$prefix_len)
394 );
395  
396 # Show label
397 0 $this->text_draw($y, $prefix_len, $label);
398  
399 0 $this->{-canvasscr}->attroff(A_REVERSE);
400 0 $this->{-canvasscr}->attroff(A_BOLD);
401  
402 # Place a [X] for selected value in multi mode.
403 0 ▶ $this->{-canvasscr}->attron(A_BOLD) if $this->{-focus};
Branch: 1 branch
BranchTrueFalseTotal
if $this->{"-focus"} 0 0 0
404 0 ▶ if ($this->{-multi}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($this->{'-multi'}) { } 0 0 0
elsif ($this->{'-radio'}) { } 0 0 0
405 0 ▶ if (defined $this->{-selected} and
Branch: 1 branch
BranchTrueFalseTotal
if (defined $this->{'-selected'} and $this->{'-selected'}{$i}) { } 0 0 0
Condition0%0/3
defined $this->{"-selected"} and $this->{"-selected"}{$i}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $this->{"-selected"} and $this->{"-selected"}{$i}
defined $this->{"-selected"} $this->{"-selected"}{$i}
Truth table0%0/3
A and B
A= defined $this->{"-selected"}B= $this->{"-selected"}{$i}
ABresult
0X0
100
111
406 $this->{-selected}->{$i}) {
407 0 $this->{-canvasscr}->addstr($y, 0, '[X]');
408 } else {
409 0 $this->{-canvasscr}->addstr($y, 0, '[ ]');
410 }
411 }
412  
413 # Place a <o> for selected value in radio mode.
414 elsif ($this->{-radio}) {
415 0 ▶ if (defined $this->{-selected}
Branch: 1 branch
BranchTrueFalseTotal
if (defined $this->{'-selected'} and $i == $this->{'-selected'}) { } 0 0 0
Condition0%0/3
defined $this->{"-selected"} and $i == $this->{"-selected"}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $this->{"-selected"} and $i == $this->{"-selected"}
defined $this->{"-selected"} $i == $this->{"-selected"}
Truth table0%0/3
A and B
A= defined $this->{"-selected"}B= $i == $this->{"-selected"}
ABresult
0X0
100
111
416 and $i == $this->{-selected}) {
417 0 $this->{-canvasscr}->addstr($y, 0, '<o>');
418 } else {
419 0 $this->{-canvasscr}->addstr($y, 0, '< >');
420 }
421 }
422 0 ▶ $this->{-canvasscr}->attroff(A_BOLD) if $this->{-focus};
Branch: 1 branch
BranchTrueFalseTotal
if $this->{"-focus"} 0 0 0
423  
424 0 $y++;
425 }
426  
427 0 ▶ $cursor_x = 1 if $this->{-multi} or $this->{-radio};
Branch: 1 branch
BranchTrueFalseTotal
if $this->{"-multi"} or $this->{"-radio"} 0 0 0
Condition0%0/3
$this->{"-multi"} or $this->{"-radio"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$this->{"-multi"} or $this->{"-radio"}
$this->{"-multi"} $this->{"-radio"}
Truth table0%0/3
A or B
A= $this->{"-multi"}B= $this->{"-radio"}
ABresult
1X1
011
000
428 0 $this->{-canvasscr}->move($cursor_y, $cursor_x);
429 }
430  
431 3 $this->{-canvasscr}->noutrefresh();
432 3 ▶ doupdate() unless $no_doupdate;
Branch: 1 branch
BranchTrueFalseTotal
unless $no_doupdate 0 3 3
433  
434 3 return $this;
435 }
436  
437 sub option_last()
438 0 ▶{
Subroutine option_last: not called CC=1 SCAR=6.9
Pod undocumented
439 0 my $this = shift;
440 0 $this->{-ypos} = $this->{-max_selected};
441 0 $this->run_event('-onselchange');
442 0 $this->schedule_draw(1);
443 0 return $this;
444 }
445  
446 sub option_nextpage()
447 0 ▶{
Subroutine option_nextpage: not called CC=3 SCAR=24.8
Pod undocumented
448 0 my $this = shift;
449 0 ▶ if ($this->{-ypos} >= $this->{-max_selected}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($this->{"-ypos"} >= $this->{"-max_selected"}) 0 0 0
450 0 $this->dobeep;
451 0 return $this;
452 }
453 0 ▶ if ($this->{-ypos} + $this->canvasheight - 1 >= $this->{-max_selected}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($this->{'-ypos'} + $this->canvasheight - 1 >= $this->{'-max_selected'}) { } 0 0 0
454 0 $this->{-ypos} = $this->{-max_selected};
455 } else {
456 0 $this->{-ypos} += $this->canvasheight - 1;
457 }
458 0 $this->run_event('-onselchange');
459 0 $this->schedule_draw(1);
460 0 return $this;
461 }
462  
463 sub option_prevpage()
464 0 ▶{
Subroutine option_prevpage: not called CC=3 SCAR=24.8
Pod undocumented
465 0 my $this = shift;
466 0 ▶ if ($this->{-ypos} <= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($this->{"-ypos"} <= 0) 0 0 0
467 0 $this->dobeep;
468 0 return $this;
469 }
470 0 ▶ if ($this->{-ypos} - $this->canvasheight - 1 < 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($this->{'-ypos'} - $this->canvasheight - 1 < 0) { } 0 0 0
471 0 $this->{-ypos} = 0;
472 } else {
473 0 $this->{-ypos} -= $this->canvasheight - 1;
474 }
475 0 $this->run_event('-onselchange');
476 0 $this->schedule_draw(1);
477 0 return $this;
478 }
479  
480 sub clear_selection()
481 2 ▶{
Subroutine clear_selection: called CC=4 SCAR=19.7
Pod documented
482 2 my $this = shift;
483 2 ▶ if ($this->{-multi}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($this->{'-multi'}) { } 0 2 2
484 0 my $selection = $this->{-selected};
485 0 ▶ return unless defined $selection;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $selection 0 0 0
486 0 foreach my $id (keys %$selection) {
487 0 $selection->{$id} = 0;
488 }
489 } else {
490 2 $this->{-selected} = undef;
491 }
492 2 $this->schedule_draw(1);
493 }
494  
495 sub set_selection()
496 2 ▶{
Subroutine set_selection: called CC=8 SCAR=24.7
Pod documented
497 2 my $this = shift;
498 2 my $id;
499  
500 2 foreach $id (@_) {
501 6 ▶ next if $id > @{$this->{-values}};
Branch: 1 branch
BranchTrueFalseTotal
if $id > @{$this->{"-values"};} 1 5 6
502 5 ▶ if ($this->{-multi})
Branch: 1 branch
BranchTrueFalseTotal
if ($this->{'-multi'}) { } 0 5 5
503 {
504 0 ▶ my $changed = ($this->{-selected}->{$id} ? 0 : 1);
Branch: 1 branch
BranchTrueFalseTotal
$this->{'-selected'}{$id} ? : 0 0 0
505 0 $this->{-selected}->{$id} = 1;
506 0 ▶ $this->run_event('-onchange') if $changed;
Branch: 1 branch
BranchTrueFalseTotal
if $changed 0 0 0
507 0 $this->schedule_draw(1);
508 } else {
509 my $changed = (not defined $this->{-selected} or
510 5 ▶ ($this->{-selected} != $id));
Condition66%2/3
!defined($this->{'-selected'}) || $this->{'-selected'} != $id
l!l&&r!l&&!r
140
MC/DC0%0/2
!defined($this->{'-selected'}) || $this->{'-selected'} != $id
!defined($this->{'-selected'}) $this->{'-selected'} != $id
Truth table66%2/3
not(A) || B
A= !defined($this->{'-selected'})B= $this->{'-selected'} != $id
ABresult
1X1
011
000
511 5 $this->{-selected} = $id;
512 5 ▶ $this->run_event('-onchange') if $changed;
Branch: 1 branch
BranchTrueFalseTotal
if $changed 5 0 5
513 5 $this->schedule_draw(1);
514 }
515 }
516 2 return $this;
517 }
518  
519 sub option_next()
520 0 ▶{
Subroutine option_next: not called CC=3 SCAR=24.8
Pod undocumented
521 0 my $this = shift;
522 0 ▶ if ($this->{-ypos} >= $this->{-max_selected}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($this->{'-ypos'} >= $this->{'-max_selected'}) { } 0 0 0
523 0 ▶ if ($this->{-wraparound}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($this->{'-wraparound'}) { } 0 0 0
524 0 $this->{-ypos} = 0;
525 } else {
526 0 $this->dobeep;
527 }
528 } else {
529 0 $this->{-ypos}++;
530 }
531 0 $this->layout_content;
532 0 $this->run_event('-onselchange');
533 0 $this->schedule_draw(1);
534 0 return $this;
535 }
536  
537 sub option_prev()
538 0 ▶{
Subroutine option_prev: not called CC=3 SCAR=24.8
Pod undocumented
539 0 my $this = shift;
540 0 ▶ if ($this->{-ypos} <= 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($this->{'-ypos'} <= 0) { } 0 0 0
541 0 ▶ if ($this->{-wraparound}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($this->{'-wraparound'}) { } 0 0 0
542 0 $this->{-ypos} = $this->{-max_selected};
543 } else {
544 0 $this->dobeep;
545 }
546 } else {
547 0 $this->{-ypos}--;
548 }
549 0 $this->layout_content;
550 0 $this->run_event('-onselchange');
551 0 $this->schedule_draw(1);
552 0 return $this;
553 }
554  
555 sub option_select()
556 0 ▶{
Subroutine option_select: not called CC=6 SCAR=37.4
Pod undocumented
557 0 my $this = shift;
558  
559 0 ▶ if ($this->{-multi})
Branch: 1 branch
BranchTrueFalseTotal
if ($this->{'-multi'}) { } 0 0 0
560 {
561 $this->{-selected}->{$this->{-ypos}} =
562 0 !$this->{-selected}->{$this->{-ypos}};
563 0 $this->run_event('-onselchange');
564 0 $this->run_event('-onchange');
565 0 $this->schedule_draw(1);
566 0 return $this;
567 } else {
568 my $changed = (not defined $this->{-selected} or
569 0 ▶ ($this->{-selected} != $this->{-ypos}));
Condition0%0/3
!defined($this->{'-selected'}) || $this->{'-selected'} != $this->{'-ypos'}
l!l&&r!l&&!r
000
MC/DC0%0/2
!defined($this->{'-selected'}) || $this->{'-selected'} != $this->{'-ypos'}
!defined($this->{'-selected'}) $this->{'-selected'} != $this->{'-ypos'}
Truth table0%0/3
not(A) || B
A= !defined($this->{'-selected'})B= $this->{'-selected'} != $this->{'-ypos'}
ABresult
1X1
011
000
570 0 $this->{-selected} = $this->{-ypos};
571 0 ▶ $this->run_event('-onselchange')if $changed;
Branch: 1 branch
BranchTrueFalseTotal
if $changed 0 0 0
572 0 ▶ $this->run_event('-onchange') if $changed;
Branch: 1 branch
BranchTrueFalseTotal
if $changed 0 0 0
573 0 $this->schedule_draw(1);
574 0 ▶ return ($this->{-radio} ? $this : 'LOOSE_FOCUS');
Branch: 1 branch
BranchTrueFalseTotal
$this->{'-radio'} ? : 0 0 0
575 }
576 }
577  
578 sub option_first()
579 1 ▶{
Subroutine option_first: called CC=1 SCAR=0.0
Pod undocumented
580 1 my $this = shift;
581 1 $this->{-ypos} = 0;
582 1 $this->run_event('-onselchange');
583 1 $this->schedule_draw(1);
584 1 return $this;
585 }
586  
587 sub option_check()
588 0 ▶{
Subroutine option_check: not called CC=7 SCAR=40.3
Pod undocumented
589 0 my $this = shift;
590  
591 0 ▶ if ($this->{-multi})
Branch: 1 branch
BranchTrueFalseTotal
if ($this->{'-multi'}) { } 0 0 0
592 {
593 0 ▶ my $changed = ($this->{-selected}->{$this->{-ypos}} ? 0 : 1);
Branch: 1 branch
BranchTrueFalseTotal
$this->{'-selected'}{$this->{'-ypos'}} ? : 0 0 0
594 0 $this->{-selected}->{$this->{-ypos}} = 1;
595 0 $this->{-ypos}++;
596 0 ▶ $this->run_event('-onchange') if $changed;
Branch: 1 branch
BranchTrueFalseTotal
if $changed 0 0 0
597 0 $this->schedule_draw(1);
598 0 return $this;
599 } else {
600 my $changed = (not defined $this->{-selected} or
601 0 ▶ ($this->{-selected} != $this->{-ypos}));
Condition0%0/3
!defined($this->{'-selected'}) || $this->{'-selected'} != $this->{'-ypos'}
l!l&&r!l&&!r
000
MC/DC0%0/2
!defined($this->{'-selected'}) || $this->{'-selected'} != $this->{'-ypos'}
!defined($this->{'-selected'}) $this->{'-selected'} != $this->{'-ypos'}
Truth table0%0/3
not(A) || B
A= !defined($this->{'-selected'})B= $this->{'-selected'} != $this->{'-ypos'}
ABresult
1X1
011
000
602 0 $this->{-selected} = $this->{-ypos};
603 0 ▶ $this->run_event('-onchange') if $changed;
Branch: 1 branch
BranchTrueFalseTotal
if $changed 0 0 0
604 0 $this->schedule_draw(1);
605 0 ▶ return ($this->{-radio} ? $this : undef);
Branch: 1 branch
BranchTrueFalseTotal
$this->{'-radio'} ? : 0 0 0
606 }
607 }
608  
609 sub option_uncheck()
610 0 ▶{
Subroutine option_uncheck: not called CC=4 SCAR=30.0
Pod undocumented
611 0 my $this = shift;
612 0 ▶ if ($this->{-multi})
Branch: 1 branch
BranchTrueFalseTotal
if ($this->{'-multi'}) { } 0 0 0
613 {
614 0 ▶ my $changed = ($this->{-selected}->{$this->{-ypos}} ? 1 : 0);
Branch: 1 branch
BranchTrueFalseTotal
$this->{'-selected'}{$this->{'-ypos'}} ? : 0 0 0
615 0 $this->{-selected}->{$this->{-ypos}} = 0;
616 0 ▶ $this->run_event('-onchange') if $changed;
Branch: 1 branch
BranchTrueFalseTotal
if $changed 0 0 0
617 0 $this->{-ypos}++;
618 } else {
619 0 $this->dobeep;
620 }
621 0 $this->schedule_draw(1);
622 0 return $this;
623 }
624  
625 sub mouse_button1($$$;)
626 0 ▶{
Subroutine mouse_button1: not called CC=6 SCAR=37.4
Pod undocumented
627 0 my $this = shift;
628 0 my $event = shift;
629 0 my $x = shift;
630 0 my $y = shift;
631  
632 0 ▶ return unless $this->{-focusable};
Branch: 1 branch
BranchTrueFalseTotal
unless $this->{"-focusable"} 0 0 0
633  
634 0 $this->layout_content;
635  
636 0 ▶ unless ($this->{-focus}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($this->{"-focus"}) 0 0 0
637 0 $this->focus;
638 }
639  
640 0 my $newypos = $this->{-yscrpos} + $y;
641 0 ▶ if (@{$this->{-values}} and
Branch: 1 branch
BranchTrueFalseTotal
if (@{$this->{"-values"};} and $newypos >= 0 and $newypos < @{$this->{"-values"};}) 0 0 0
Condition0%0/6
@{$this->{"-values"};} and $newypos >= 0 and $newypos < @{$this->{"-values"};}
!ll&&!rl&&r
000
@{$this->{"-values"};} and $newypos >= 0
!ll&&!rl&&r
000
MC/DC0%0/3
@{$this->{"-values"};} and $newypos >= 0 and $newypos < @{$this->{"-values"};}
@{$this->{"-values"};} $newypos >= 0 $newypos < @{$this->{"-values"};}
Truth table0%0/4
A and B and C
A= @{$this->{"-values"};}B= $newypos >= 0C= $newypos < @{$this->{"-values"};}
ABCresult
0XX0
10X0
1100
1111
642 0 $newypos >= 0 and $newypos < @{$this->{-values}}) {
643 0 $this->{-ypos} = $newypos;
644 0 $this->do_routine('option-select');
645 }
646  
647 0 $this->schedule_draw(1);
648 }
649  
650 sub get()
651 4 ▶{
Subroutine get: called CC=5 SCAR=23.7
Pod documented
652 4 my $this = shift;
653 4 ▶ return unless defined $this->{-selected};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $this->{"-selected"} 2 2 4
654 2 ▶ if ($this->{-multi}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($this->{'-multi'}) { } 0 2 2
655 0 my @values = ();
656 0 ▶ while (my ($id, $val) = each %{$this->{-selected}}) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %{$$this{"-selected"};}) 0 0 0
657 0 ▶ next unless $val;
Branch: 1 branch
BranchTrueFalseTotal
unless $val 0 0 0
658 0 push @values, $this->{-values}->[$id];
659 }
660 0 return @values;
661 } else {
662 2 return $this->{-values}->[$this->{-selected}];
663 }
664 }
665  
666 sub id()
667 0 ▶{
Subroutine id: not called CC=5 SCAR=34.0
Pod documented
668 0 my $this = shift;
669 0 ▶ return unless defined $this->{-selected};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $this->{"-selected"} 0 0 0
670 0 ▶ if ($this->{-multi}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($this->{'-multi'}) { } 0 0 0
671 0 my @values = ();
672 0 ▶ while (my ($id, $val) = each %{$this->{-selected}}) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %{$$this{"-selected"};}) 0 0 0
673 0 ▶ next unless $val;
Branch: 1 branch
BranchTrueFalseTotal
unless $val 0 0 0
674 0 push @values, $id;
675 }
676 0 return @values;
677 } else {
678 0 return $this->{-selected};
679 }
680 }
681  
682 sub get_selectedlabel()
683 0 ▶{
Subroutine get_selectedlabel: not called CC=3 SCAR=24.8
Pod undocumented
684 0 my $this = shift;
685 0 my $value = $this->get;
686 0 ▶ return unless defined $value;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 0 0 0
687 0 my $label = $this->{-labels}->{$value};
688 0 ▶ return (defined $label ? $label : $value);
Branch: 1 branch
BranchTrueFalseTotal
defined $label ? : 0 0 0
689 }
690  
691 0 ▶sub set_color_fg {
Subroutine set_color_fg: not called CC=1 SCAR=6.9
Pod undocumented
692 0 my $this = shift;
693 0 $this->{-fg} = shift;
694 0 $this->intellidraw;
695 }
696  
697 0 ▶sub set_color_bg {
Subroutine set_color_bg: not called CC=1 SCAR=6.9
Pod undocumented
698 0 my $this = shift;
699 0 $this->{-bg} = shift;
700 0 $this->intellidraw;
701 }
702  
703  
704 # ----------------------------------------------------------------------
705 # Routines for search support
706 # ----------------------------------------------------------------------
707  
708 1 ▶sub number_of_lines() { @{shift()->{-values}} }
Subroutine number_of_lines: called CC=1 SCAR=0.0
Pod documented
709 0 ▶sub getline_at_ypos($;) { shift()->getlabel(shift()) }
Subroutine getline_at_ypos: not called CC=1 SCAR=6.9
Pod documented
710  
711 1 1;
712  
713  
714 =pod
715  
716 =head1 NAME
717  
718 Curses::UI::Listbox - Create and manipulate listbox widgets
719  
720 =head1 CLASS HIERARCHY
721  
722 Curses::UI::Widget
723 Curses::UI::Searchable
724 |
725 +----Curses::UI::Listbox
726  
727  
728 =head1 SYNOPSIS
729  
730 use Curses::UI;
731 my $cui = new Curses::UI;
732 my $win = $cui->add('window_id', 'Window');
733  
734 my $listbox = $win->add(
735 'mylistbox', 'Listbox',
736 -values => [1, 2, 3],
737 -labels => { 1 => 'One',
738 2 => 'Two',
739 3 => 'Three' },
740 -radio => 1,
741 );
742  
743 $listbox->focus();
744 my $selected = $listbox->get();
745  
746  
747 =head1 DESCRIPTION
748  
749 Curses::UI::Listbox is a widget that can be used to create
750 a couple of different kinds of listboxes. These are:
751  
752 =over 4
753  
754 =item * B<default listbox>
755  
756 A list of values through which can be browsed. One of these
757 values can be selected. The selected value will be
758 highlighted. This kind of listbox looks somewhat like this:
759  
760 +------+
761 |One |
762 |Two |
763 |Three |
764 +------+
765  
766 =item * B<multi-select listbox>
767  
768 This is also a list of values, but now more than one
769 value can be selected at once. This kind of listbox
770 looks somewhat like this:
771  
772 +----------+
773 |[X] One |
774 |[ ] Two |
775 |[X] Three |
776 +----------+
777  
778 =item * B<radiobutton listbox>
779  
780 This looks a lot like the default listbox (only one
781 value can be selected), but now there is clear
782 visual feedback on which value is selected. Before
783 each value "< >" is printed. If a value is selected,
784 "<o>" is printed instead. This kind of listbox
785 looks somewhat like this:
786  
787 +----------+
788 |< > One |
789 |<o> Two |
790 |< > Three |
791 +----------+
792  
793  
794 =item * B<Listbox Markup>
795  
796 The listbox supports a primitive markup language to emphasize
797 entries:
798 <reverse>reverse text</reverse>
799 <bold>bold text</bold>
800 <underline>underlined text</underline>
801 <blink>blinking text</blink>
802 <dim>dim text</dim>
803 By using this markup tokens in the values array, you can make the
804 listbox draw the text in the according way. To enable the parser,
805 you have to create the listbox with the -htmltext option.
806  
807  
808 =back
809  
810  
811  
812  
813 =head1 STANDARD OPTIONS
814  
815 B<-parent>, B<-x>, B<-y>, B<-width>, B<-height>,
816 B<-pad>, B<-padleft>, B<-padright>, B<-padtop>, B<-padbottom>,
817 B<-ipad>, B<-ipadleft>, B<-ipadright>, B<-ipadtop>, B<-ipadbottom>,
818 B<-title>, B<-titlefullwidth>, B<-titlereverse>, B<-onfocus>,
819 B<-onblur>
820  
821 For an explanation of these standard options, see
822 L<Curses::UI::Widget|Curses::UI::Widget>.
823  
824  
825  
826  
827 =head1 WIDGET-SPECIFIC OPTIONS
828  
829 =over 4
830  
831 =item * B<-values> < ARRAYREF >
832  
833 This option sets the values to use.
834 Unless a label is set for the value (see B<-labels>),
835 this value will be shown in the list.
836  
837 =item * B<-labels> < HASHREF >
838  
839 The keys of this hash reference correspond to the values of
840 the listbox (see B<-values>). The values of the hash are the
841 labels to show in the listbox. It's not obligatory to have
842 a label defined for each value. You may even omit -labels
843 completely.
844  
845 =item * B<-selected> < INDEX >
846  
847 In case the B<-multi> option is not set, INDEX is the index
848 of the value that should be selected.
849  
850 In case the B<-multi> option is set, INDEX is a hash reference
851 in which the keys are the indices of the B<-values> which are
852 selected and the values are any true value.
853  
854 =item * B<-multi> < BOOLEAN >
855  
856 If BOOLEAN has a true value, the listbox will be a multi-select
857 listbox (see DESCRIPTION).
858  
859 =item * B<-radio> < BOOLEAN >
860  
861 If BOOLEAN has a true value, the listbox will be a radiobutton
862 listbox (see DESCRIPTION).
863  
864 =item * B<-wraparound> < BOOLEAN >
865  
866 If BOOLEAN has a true value, wraparound is enabled. This means
867 that if the listbox is on its last value and a key is pressed
868 to go to the next value, the first value will be selected.
869 Also the last value will be selected if this first value is
870 selected and "goto previous value" is pressed.
871  
872 =item * B<-onchange> < CODEREF >
873  
874 This sets the onChange event handler for the listbox widget.
875 If a new item is selected, the code in CODEREF will be executed.
876 It will get the widget reference as its argument.
877  
878 =item * B<-onselchange> < CODEREF >
879  
880 This sets the onSelectionChange event handler for the listbox widget.
881 If a new item is marked as active CODEREF will be executed.
882 It will get the widget reference as its argument.
883  
884 =item * B<-htmltext> < BOOLEAN >
885  
886 Make the Listbox parse primitive markup to change the items
887 appearance. See above.
888  
889  
890 =back
891  
892  
893  
894  
895 =head1 METHODS
896  
897 =over 4
898  
899 =item * B<new> ( OPTIONS )
900  
901 =item * B<layout> ( )
902  
903 =item * B<draw> ( BOOLEAN )
904  
905 =item * B<intellidraw> ( )
906  
907 =item * B<focus> ( )
908  
909 =item * B<onFocus> ( CODEREF )
910  
911 =item * B<onBlur> ( CODEREF )
912  
913 These are standard methods. See L<Curses::UI::Widget|Curses::UI::Widget>
914 for an explanation of these.
915  
916 =item * B<get> ( )
917  
918 This method will return the values of the currently selected items
919 in the list. If the listbox is not a multi-select listbox only one
920 value will be returned of course.
921  
922 =item * B<id> ( )
923  
924 This method will return the index of the currently selected items
925 in the list. If the listboy is not a multi-select listbox it will
926 only return one value.
927  
928 =item * B<get_active_value> ( )
929  
930 This method will return the value of the currently active (i.e
931 highlighted line).
932  
933 =item * B<get_active_id> ( )
934  
935 This method will return the index of the currently active (i.e
936 highlighted line).
937  
938 =item * B<set_selection> ( LIST )
939  
940 This method marks the items at the positions specified in LIST
941 as selected. In a multi-select listbox you can set multiple items
942 with giving multiple values, in a single-select listbox only the
943 last item in LIST will be selected
944  
945 =item * B<clear_selection> ( )
946  
947 This method clears the selected objects of a multi and radiobutton
948 listbox.
949  
950 =item * B<values> ( ARRAYREF )
951  
952 This method sets the values to use.
953  
954 =item * B<insert_at> < POS, ARRAYREF|SCALAR >
955  
956 This method adds ARRAYREF or SCALAR into the list of values at
957 pos.
958  
959 =item * B<labels> [ HASHREF ]
960  
961 This method sets the labels to use.
962  
963 =item * B<add_labels> [ HASHREF ]
964  
965 This method adds the given labels to the already defined ones.
966  
967 =item * B<onChange> ( CODEREF )
968  
969 This method can be used to set the B<-onchange> event handler
970 (see above) after initialization of the listbox.
971  
972 =item * B<onSelectionChange> ( CODEREF )
973  
974 This method can be used to set the B<-onselchange> event handler
975 (see above) after initialization of the listbox.
976  
977  
978 =back
979  
980  
981  
982  
983 =head1 DEFAULT BINDINGS
984  
985 =over 4
986  
987 =item * <B<cursor-left>>, <B<h>>, <B<tab>>
988  
989 Call the 'loose-focus' routine. This will have the widget
990 loose its focus.
991  
992 =item * <B<cursor-right>, <B<l>>, <B<enter>>, <B<space>>
993  
994 Call the 'option-select' routine. This will select the
995 active item in the listbox.
996  
997 =item * <B<1>>, <B<y>>
998  
999 Call the 'option-check' routine. If the listbox is a
1000 multi-select listbox, the active item will become checked
1001 and the next item will become active.
1002  
1003 =item * <B<0>>, <B<n>>
1004  
1005 Call the 'option-uncheck' routine. If the listbox is a
1006 multi-select listbox, the active item will become unchecked
1007 and the next item will become active.
1008  
1009 =item * <B<cursor-down>>, <B<j>>
1010  
1011 Call the 'option-next' routine. This will make the next
1012 item of the list active.
1013  
1014 =item * <B<cursor-up>>, <B<k>>
1015  
1016 Call the 'option-prev' routine. This will make the previous
1017 item of the list active.
1018  
1019 =item * <B<page-up>>
1020  
1021 Call the 'option-prevpage' routine. This will make the item
1022 on the previous page active.
1023  
1024 =item * <B<page-down>>
1025  
1026 Call the 'option-nextpage' routine. This will make the item
1027 on the next page active.
1028  
1029 =item * <B<home>>, <B<CTRL+A>>
1030  
1031 Call the 'option-first' routine. This will make the first
1032 item of the list active.
1033  
1034 =item * <B<end>>, <B<CTRL+E>>
1035  
1036 Call the 'option-last' routine. This will make the last
1037 item of the list active.
1038  
1039 =item * <B</>>
1040  
1041 Call the 'search-forward' routine. This will make a 'less'-like
1042 search system appear in the listbox. A searchstring can be
1043 entered. After that the user can search for the next occurance
1044 using the 'n' key or the previous occurance using the 'N' key.
1045  
1046 =item * <B<?>>
1047  
1048 Call the 'search-backward' routine. This will do the same as
1049 the 'search-forward' routine, only it will search in the
1050 opposite direction.
1051  
1052 =back
1053  
1054  
1055  
1056  
1057  
1058 =head1 SEE ALSO
1059  
1060 L<Curses::UI|Curses::UI>,
1061 L<Curses::UI::Widget|Curses::UI::Widget>,
1062 L<Curses::UI::Common|Curses::UI::Common>
1063  
1064  
1065  
1066  
1067 =head1 AUTHOR
1068  
1069 Copyright (c) 2001-2002 Maurice Makaay. All rights reserved.
1070  
1071 Maintained by Marcus Thiesen (marcus@cpan.thiesenweb.de)
1072  
1073 This package is free software and is provided "as is" without express
1074 or implied warranty. It may be used, redistributed and/or modified
1075 under the same terms as perl itself.
1076  
« lib/Curses/UI/Common.pm ↑ Summary blib/lib/Curses/UI/Progressbar.pm »