ListBrowser/Tree.pm untested

filter: Statementstmt 0.0% 0 / 46 Branchbran 0.0% 0 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 7 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 61 CC 4 SCAR 22.2
CC
4
Cov
0%
draw
20.0
cellSize
2.0
BEGIN
2.0
CRAP 9.2
1 package Tk::ListBrowser::Tree;
2  
3 =head1 NAME
4  
5 Tk::ListBrowser::Bar - Bar organizer for Tk::ListBrowser.
6  
7 =head1 SYNOPSIS
8  
9 require Tk::ListBrowser;
10 my $ib= $window->ListBrowser(@options,
11 -arrange => 'tree'
12 )->pack;
13 $ib->add('item_1', -image => $image1, -text => $text1);
14 $ib->add('item_2', -image => $image2, -text => $text2);
15 $ib->refresh;
16  
17 =head1 DESCRIPTION
18  
19 Contains all the drawing routines for L<Tk::ListBrowser> to
20 present a hierarchical tree interface.
21  
22 No user serviceable parts inside.
23  
24 =cut
25  
26 use strict;
27 use warnings;
28 use vars qw ($VERSION);
29 $VERSION = 0.14;
30  
31 use Math::Round qw(round);
32  
33 use base qw(Tk::ListBrowser::HList);
34  
35 sub cellSize {
36 my $self = shift;
37 $self->SUPER::cellSize;
38 $self->listWidth($self->listWidth + $self->cget('-indent'));
39 }
40  
41 sub draw {
42 my ($self, $item, $x, $y, $column, $row) = @_;
43 my $indent = $self->cget('-indent');
44 $x = $self->cget('-marginleft') + $indent;
45 $self->SUPER::draw($item, $x, $y, $column, $row);
46 my $entry = $item->name;
47 my $depth = $self->calculateDepth($item);
48 $depth ++;
49 my $leftx = ($depth * $indent);
50 if ($item->hasChildren) {
51 my $ind;
52 my $c = $self->Subwidget('Canvas');
53 my @eregion = $item->getRegion;
54 my $ix = $leftx - round($indent/2);
55 my $iy = $y + round($self->cget('-cellheight')/2);
56 if ($item->opened) {
57 $ind = $c->createImage($ix, $iy,
58 -image => $self->cget('-indicatorminusimg'),
59 -tags => ['main', 'indicator', $entry],
60 );
61 } else {
62 $ind = $c->createImage($ix, $iy,
63 -image => $self->cget('-indicatorplusimg'),
64 -tags => ['main','indicator', $entry],
65 );
66 }
67 $c->bind($ind, '<ButtonRelease-1>', sub { $self->indicatorActivate($entry) });
68 $c->bind($ind, '<Button-1>', sub { $c->focus($ind) });
69 my @guides = $c->find('withtag', 'guides');
70 $c->raise('indicator', 'guides') if @guides;
71 $c->raise('indicator', 'all');
72 $item->cindicator($ind);
73 }
74 }
75  
76  
77 =head1 LICENSE
78  
79 Same as Perl.
80  
81 =head1 AUTHOR
82  
83 Hans Jeuken (hanje at cpan dot org)
84  
85 =head1 BUGS AND CAVEATS
86  
87 If you find any bugs, please report them here: L<https://github.com/haje61/Tk-ListBrowser/issues>.
88  
89 =cut
90  
91 1;