ListBrowser/HList.pm untested

filter: Statementstmt 0.0% 0 / 63 Branchbran 0.0% 0 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 10 Podpod 0.0% 0 / 5 totaltotal 0.0% 0 / 86 CC 5 SCAR 20.4
CC
5
Cov
0%
draw
20.0
maxIndent
6.0
new
2.0
CRAP 7.7
1 package Tk::ListBrowser::HList;
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 => 'hlist'
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 list 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.16;
30  
31 use Math::Round qw(round);
32  
33 use base qw(Tk::ListBrowser::List);
34  
35 sub new {
36 my $class = shift;
37 my $self = $class->SUPER::new(@_);
38 $self->{STACK} = [];
39 return $self;
40 }
41  
42 sub calculateDepth {
43 my ($self, $item) = @_;
44 my $name = $item->name;
45 my $i = 0;
46 my $sep = quotemeta($self->cget('-separator'));
47 while ($name =~ /$sep/g) { $i ++ }
48 return $i
49 }
50  
51 sub draw {
52 my ($self, $item, $x, $y, $column, $row) = @_;
53  
54 #calculate indent
55 my $indentsize = $self->cget('-indent');
56 $x = $self->cget('-marginleft');
57 $x = $x + $indentsize if ref $self eq 'Tk::ListBrowser::Tree';
58 my $entry = $item->name;
59 my $sep = quotemeta($self->cget('-separator'));
60 my $depth = $self->calculateDepth($item);
61 $x = $x + ($depth * $indentsize);
62  
63 #draw entry
64 $self->SUPER::draw($item, $x, $y, $column, $row);
65
66 #draw guides
67 my $parent = $self->infoParent($entry);
68 if (defined $parent) {
69 my $c = $self->Subwidget('Canvas');
70 my @eregion = $item->getRegion;
71 my $p = $self->get($parent);
72 my @pregion = $p->region;
73 # my $half = 8;
74  
75 #draw horizontal guide
76 my $hx1 = $x - round($indentsize/2);
77 my $hy1 = $y + round($self->cget('-cellheight')/2);
78 my $hx2 = $x;
79 my $hy2 = $hy1;
80 my $guideh = $c->createLine($hx1, $hy1, $hx2, $hy2,
81 -fill => $self->cget('-guidecolor'),
82 -tags => ['main', 'guides'],
83 );
84 $item->cguideH($guideh);
85 # $c->lower($guideh);
86  
87 #draw vertical guide
88 my $vx1 = $hx1;
89 my $vy1 = $p->rectY + $self->cget('-cellheight');
90 my $vx2 = $vx1;
91 my $vy2 = $hy1;
92 my $guidev = $c->createLine($vx1, $vy1, $vx2, $vy2,
93 -fill => $self->cget('-guidecolor'),
94 -tags => ['main', 'guides'],
95 );
96 $item->cguideV($guidev);
97  
98 my @sel = $c->find('withtag', 'sel');
99 $c->raise('guides', 'sel') if @sel;
100 }
101 }
102  
103 sub getPool {
104 my $self = shift;
105 return $self->getAll;
106 }
107  
108 sub maxIndent {
109 my $self = shift;
110 $self->{MAXINDENT} = shift if @_;
111 return $self->{MAXINDENT}
112 }
113  
114 =head1 LICENSE
115  
116 Same as Perl.
117  
118 =head1 AUTHOR
119  
120 Hans Jeuken (hanje at cpan dot org)
121  
122 =head1 BUGS AND CAVEATS
123  
124 If you find any bugs, please report them here: L<https://github.com/haje61/Tk-ListBrowser/issues>.
125  
126  
127 =cut
128  
129 1;