| 1 | package Tk::ListBrowser::Row; | ||
| 2 | |||
| 3 | =head1 NAME | ||
| 4 | |||
| 5 | Tk::ListBrowser::Row - Row organizer for Tk::ListBrowser. | ||
| 6 | |||
| 7 | =head1 SYNOPSIS | ||
| 8 | |||
| 9 | require Tk::ListBrowser; | ||
| 10 | my $ib= $window->ListBrowser(@options, | ||
| 11 | -arrange => 'row' | ||
| 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 row organized manner. | ||
| 21 | |||
| 22 | No user serviceable parts inside. | ||
| 23 | |||
| 24 | =cut | ||
| 25 | |||
| 26 | use strict; | ||
| 27 | use warnings; | ||
| 28 | use vars qw($VERSION $AUTOLOAD); | ||
| 29 | $VERSION = 0.15; | ||
| 30 | use Carp; | ||
| 31 | use Math::Round; | ||
| 32 | |||
| 33 | sub new { | ||
| 34 | my ($class, $lb) = @_; | ||
| 35 | carp 'You did not specify a list browser' unless defined $lb; | ||
| 36 | |||
| 37 | my $self = { | ||
| 38 | LISTBROWSER => $lb, | ||
| 39 | }; | ||
| 40 | bless $self, $class; | ||
| 41 | return $self | ||
| 42 | } | ||
| 43 | |||
| 44 | sub AUTOLOAD { | ||
| 45 | my $self = shift; | ||
| 46 | return if $AUTOLOAD =~ /::DESTROY$/; | ||
| 47 | $AUTOLOAD =~ s/^.*:://; | ||
| 48 | return $self->{LISTBROWSER}->$AUTOLOAD(@_); | ||
| 49 | } | ||
| 50 | |||
| 51 | sub draw { | ||
| 52 | my ($self, $item, $x, $y, $column, $row) = @_; | ||
| 53 | $item->draw($x, $y, $column, $row, $self->cget('-itemtype')); | ||
| 54 | $item->drawAnchor if $item->anchored; | ||
| 55 | } | ||
| 56 | |||
| 57 | sub listbrowser { return $_[0]->{LISTBROWSER} } | ||
| 58 | |||
| 59 | sub nextPosition { | ||
| 60 | my ($self, $x, $y, $column, $row) = @_; | ||
| 61 | my $cellheight = $self->cget('-cellheight'); | ||
| 62 | my $cellwidth = $self->cget('-cellwidth'); | ||
| 63 | my $newx = $x + ($cellwidth * 2); | ||
| 64 | my ($cwidth, $cheight) = $self->canvasSize; | ||
| 65 | if ($newx >= $cwidth) { | ||
| 66 | $x = $self->cget('-marginleft'); | ||
| 67 | $y = $y + $cellheight + 1; | ||
| 68 | $column = 0; | ||
| 69 | $row ++; | ||
| 70 | } else { | ||
| 71 | $x = $x + $cellwidth + 1; | ||
| 72 | $column ++; | ||
| 73 | } | ||
| 74 | return ($x, $y, $column, $row) | ||
| 75 | } | ||
| 76 | |||
| 77 | sub scroll { | ||
| 78 | return 'vertical' | ||
| 79 | } | ||
| 80 | |||
| 81 | sub startXY { | ||
| 82 | my $self = shift; | ||
| 83 | $self->{STARTXY} = [@_] if @_; | ||
| 84 | my $sxy = $self->{STARTXY}; | ||
| 85 | return ($self->cget('-marginleft'), $self->cget('-margintop')) unless defined $sxy; | ||
| 86 | return @$sxy | ||
| 87 | } | ||
| 88 | |||
| 89 | sub type { | ||
| 90 | return 'row' | ||
| 91 | } | ||
| 92 | |||
| 93 | =head1 LICENSE | ||
| 94 | |||
| 95 | Same as Perl. | ||
| 96 | |||
| 97 | =head1 AUTHOR | ||
| 98 | |||
| 99 | Hans Jeuken (hanje at cpan dot org) | ||
| 100 | |||
| 101 | =head1 BUGS AND CAVEATS | ||
| 102 | |||
| 103 | If you find any bugs, please report them here: L<https://github.com/haje61/Tk-ListBrowser/issues>. | ||
| 104 | |||
| 105 | =cut | ||
| 106 | |||
| 107 | 1; |