| 1 | package Tk::ListBrowser::List; | ||
| 2 | |||
| 3 | =head1 NAME | ||
| 4 | |||
| 5 | Tk::ListBrowser::List - List organizer for Tk::ListBrowser. | ||
| 6 | |||
| 7 | =head1 SYNOPSIS | ||
| 8 | |||
| 9 | require Tk::ListBrowser; | ||
| 10 | my $ib= $window->ListBrowser(@options, | ||
| 11 | -arrange => 'list' | ||
| 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 | draw and navigate the list in a list organized manner. | ||
| 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 base qw(Tk::ListBrowser::Row); | ||
| 32 | |||
| 33 | |||
| 34 | sub draw { | ||
| 35 | my ($self, $item, $x, $y, $column, $row) = @_; | ||
| 36 | $item->draw($x, $y, $column, $row, $self->cget('-itemtype')); | ||
| 37 | my $entry = $item->name; | ||
| 38 | my $cx; | ||
| 39 | my $last; | ||
| 40 | my @columns = $self->columnList; | ||
| 41 | for (@columns) { | ||
| 42 | my $col = $self->columnGet($_); | ||
| 43 | if (defined $cx) { | ||
| 44 | $cx = $cx + $last->cget('-cellwidth') + 1; | ||
| 45 | } else { | ||
| 46 | $cx = $self->listWidth + 1 + $self->cget('-marginleft'); | ||
| 47 | } | ||
| 48 | $last = $col; | ||
| 49 | my $i = $self->itemGet($entry, $_); | ||
| 50 | $i = $self->itemCreate($entry, $_) unless defined $i; | ||
| 51 | $i->draw($cx, $y, $column, $row, $col->cget('-itemtype')); | ||
| 52 | } | ||
| 53 | $item->drawAnchor if $item->anchored; | ||
| 54 | } | ||
| 55 | |||
| 56 | sub listHeight { | ||
| 57 | my $self = shift; | ||
| 58 | $self->{LISTHEIGHT} = shift if @_; | ||
| 59 | return $self->{LISTHEIGHT} | ||
| 60 | } | ||
| 61 | |||
| 62 | sub maxIndent { | ||
| 63 | return 0 | ||
| 64 | } | ||
| 65 | |||
| 66 | sub nextPosition { | ||
| 67 | my ($self, $x, $y, $column, $row) = @_; | ||
| 68 | my $cellheight = $self->cget('-cellheight'); | ||
| 69 | $y = $y + $cellheight + 1; | ||
| 70 | $row ++; | ||
| 71 | return ($x, $y, $column, $row) | ||
| 72 | } | ||
| 73 | |||
| 74 | sub refresh { | ||
| 75 | my $self = shift; | ||
| 76 | |||
| 77 | #calculate sizes of side columns | ||
| 78 | my @columns = $self->columnList; | ||
| 79 | for (@columns) { | ||
| 80 | my $col = $self->columnGet($_)->cellSize; | ||
| 81 | } | ||
| 82 | |||
| 83 | $self->SUPER::refresh; | ||
| 84 | |||
| 85 | @columns = reverse @columns; | ||
| 86 | my $c = $self->Subwidget('Canvas'); | ||
| 87 | while (@columns) { | ||
| 88 | my $last = shift @columns; | ||
| 89 | my $tag; | ||
| 90 | my $prev = $columns[0]; | ||
| 91 | if (defined $prev) { | ||
| 92 | my $col = $self->columnGet($prev); | ||
| 93 | $tag = $col->crect; | ||
| 94 | } else { | ||
| 95 | $tag = 'main' | ||
| 96 | } | ||
| 97 | my $rlast = $self->columnGet($last)->crect; | ||
| 98 | $c->lower($tag, $rlast); | ||
| 99 | } | ||
| 100 | $self->headerPlace; | ||
| 101 | } | ||
| 102 | |||
| 103 | sub scroll { | ||
| 104 | return 'vertical' | ||
| 105 | } | ||
| 106 | |||
| 107 | sub startXY { | ||
| 108 | my $self = shift; | ||
| 109 | my ($x, $y) = $self->SUPER::startXY; | ||
| 110 | $y = $y + $self->cget('-headerheight') if $self->headerAvailable; | ||
| 111 | return ($x, $y) | ||
| 112 | } | ||
| 113 | |||
| 114 | sub type { | ||
| 115 | return 'list' | ||
| 116 | } | ||
| 117 | |||
| 118 | =head1 LICENSE | ||
| 119 | |||
| 120 | Same as Perl. | ||
| 121 | |||
| 122 | =head1 AUTHOR | ||
| 123 | |||
| 124 | Hans Jeuken (hanje at cpan dot org) | ||
| 125 | |||
| 126 | =head1 TODO | ||
| 127 | |||
| 128 | =over 4 | ||
| 129 | |||
| 130 | =back | ||
| 131 | |||
| 132 | =head1 BUGS AND CAVEATS | ||
| 133 | |||
| 134 | If you find any bugs, please report them here: L<https://github.com/haje61/Tk-ListBrowser/issues>. | ||
| 135 | |||
| 136 | =cut | ||
| 137 | |||
| 138 | 1; |