| 1 | package Tk::PodViewer::Full; | ||
| 2 | |||
| 3 | use strict; | ||
| 4 | use warnings; | ||
| 5 | use vars qw ($VERSION); | ||
| 6 | $VERSION = 0.03; | ||
| 7 | use base qw(Tk::Derived Tk::PodViewer); | ||
| 8 | |||
| 9 | Construct Tk::Widget 'PodViewerFull'; | ||
| 10 | |||
| 11 | =head1 NAME | ||
| 12 | |||
| 13 | Tk::PodViewer::Full - Deluxe Tk::PodViewer widget. | ||
| 14 | |||
| 15 | =head1 SYNOPSIS | ||
| 16 | |||
| 17 | require Tk::PodViewer::Full | ||
| 18 | my $podviewer = $app->PodViewerFull->pack; | ||
| 19 | $podviewer->load('SomePerlFileWithPod.pm'); | ||
| 20 | |||
| 21 | =head1 DESCRIPTION | ||
| 22 | |||
| 23 | Tk::PodViewer::Full is a deluxe verstion of L<Tk::PodViewer>. | ||
| 24 | It adds a toolbar and a popable search bar. | ||
| 25 | |||
| 26 | =head1 OPTIONS | ||
| 27 | |||
| 28 | =over 4 | ||
| 29 | |||
| 30 | =item Switch: B<-nextimage> | ||
| 31 | |||
| 32 | Image to be used for the next button. | ||
| 33 | |||
| 34 | =item Switch: B<-previmage> | ||
| 35 | |||
| 36 | Image to be used for the previous button. | ||
| 37 | |||
| 38 | =item Switch: B<-zoominimage> | ||
| 39 | |||
| 40 | Image to be used for the zoom-in button. | ||
| 41 | |||
| 42 | =item Switch: B<-zoomoutimage> | ||
| 43 | |||
| 44 | Image to be used for the zoom-out button. | ||
| 45 | |||
| 46 | =item Switch: B<-zoomresetimage> | ||
| 47 | |||
| 48 | Image to be used for the zoom-reset button. | ||
| 49 | |||
| 50 | =back | ||
| 51 | |||
| 52 | =head1 ADVERTISED SUBWIDGETS | ||
| 53 | |||
| 54 | C<Searchbar> The poppable search bar. | ||
| 55 | |||
| 56 | C<Search> The entry inside the Searchbar. | ||
| 57 | |||
| 58 | C<Toolbar> The tool frame in the top. | ||
| 59 | |||
| 60 | =cut | ||
| 61 | |||
| 62 | sub Populate { | ||
| 63 | my ($self,$args) = @_; | ||
| 64 | |||
| 65 | $self->SUPER::Populate($args); | ||
| 66 | |||
| 67 | my @bpack = (-side => 'left', -padx => 2, -pady => 2); | ||
| 68 | my @bopt = (-relief => 'flat'); | ||
| 69 | my $txt = $self->Subwidget('txt'); | ||
| 70 | # my $parent = $txt->parent; | ||
| 71 | # my $toolframe = $parent->Frame->pack( | ||
| 72 | my $toolframe = $self->Frame->pack( | ||
| 73 | -before => $txt, | ||
| 74 | -fill => 'x', | ||
| 75 | -padx => 2, | ||
| 76 | -pady => 2, | ||
| 77 | ); | ||
| 78 | $self->Advertise('Toolbar', $toolframe); | ||
| 79 | |||
| 80 | #creating previous button | ||
| 81 | my $prev = $toolframe->Button(@bopt, | ||
| 82 | -text => '<- Previous', | ||
| 83 | -command => ['previous', $self], | ||
| 84 | )->pack(@bpack); | ||
| 85 | |||
| 86 | #creating next button | ||
| 87 | my $next = $toolframe->Button(@bopt, | ||
| 88 | -text => '-> Next', | ||
| 89 | -command => ['next', $self], | ||
| 90 | )->pack(@bpack); | ||
| 91 | |||
| 92 | #creating zoom in button | ||
| 93 | my $zmin = $toolframe->Button(@bopt, | ||
| 94 | -text => '+ Zoom', | ||
| 95 | -command => ['zoomIn', $self], | ||
| 96 | )->pack(@bpack); | ||
| 97 | |||
| 98 | #creating zoom out button | ||
| 99 | my $zmout = $toolframe->Button(@bopt, | ||
| 100 | -text => '- Zoom', | ||
| 101 | -command => ['zoomOut', $self], | ||
| 102 | )->pack(@bpack); | ||
| 103 | |||
| 104 | #creating zoom reset button | ||
| 105 | my $zmreset = $toolframe->Button(@bopt, | ||
| 106 | -text => '0 Zoom', | ||
| 107 | -command => ['zoomReset', $self], | ||
| 108 | )->pack(@bpack); | ||
| 109 | |||
| 110 | #create the search bar | ||
| 111 | my $searchbar = $self->Frame; | ||
| 112 | $self->Advertise('Searchbar', $searchbar); | ||
| 113 | |||
| 114 | my $case = '-case'; | ||
| 115 | my $find = ''; | ||
| 116 | my $reg = '-exact'; | ||
| 117 | $searchbar->Label( | ||
| 118 | -text => 'Find', | ||
| 119 | )->pack(@bpack); | ||
| 120 | my $search = $searchbar->Entry( | ||
| 121 | -textvariable => \$find, | ||
| 122 | )->pack(@bpack, -expand => 1, -fill => 'x'); | ||
| 123 | $self->Advertise('Search', $search); | ||
| 124 | $search->bind('<Escape>', [$self, 'searchClose']); | ||
| 125 | $search->bind('<Return>', sub { $self->FindNext('-forward', $reg, $case, $find) }); | ||
| 126 | $searchbar->Button( | ||
| 127 | -text => 'Next', | ||
| 128 | -command => sub { $self->FindNext('-forward', $reg, $case, $find) }, | ||
| 129 | )->pack(@bpack); | ||
| 130 | $searchbar->Button( | ||
| 131 | -text => 'Previous', | ||
| 132 | -command => sub { $self->FindNext('-backward', $reg, $case, $find) }, | ||
| 133 | )->pack(@bpack); | ||
| 134 | $searchbar->Button( | ||
| 135 | -text => 'All', | ||
| 136 | -command => sub { $self->FindAll($reg, $case, $find) }, | ||
| 137 | )->pack(@bpack); | ||
| 138 | $searchbar->Checkbutton( | ||
| 139 | -text => 'Case', | ||
| 140 | -onvalue => '-case', | ||
| 141 | -offvalue => '-nocase', | ||
| 142 | -variable => \$case, | ||
| 143 | )->pack(@bpack); | ||
| 144 | $searchbar->Checkbutton( | ||
| 145 | -text => 'Reg', | ||
| 146 | -onvalue => '-regexp', | ||
| 147 | -offvalue => '-exact', | ||
| 148 | -variable => \$reg, | ||
| 149 | )->pack(@bpack); | ||
| 150 | $searchbar->Button( | ||
| 151 | -text => 'Close', | ||
| 152 | -command => ['searchClose', $self], | ||
| 153 | )->pack(@bpack); | ||
| 154 | $txt->bind('<Control-f>', [$self, 'searchPop']); | ||
| 155 | |||
| 156 | $self->ConfigSpecs( | ||
| 157 | -nextimage => [{-image => $next}], | ||
| 158 | -previmage => [{-image => $prev}], | ||
| 159 | -zoominimage => [{-image => $zmin}], | ||
| 160 | -zoomoutimage => [{-image => $zmout}], | ||
| 161 | -zoomresetimage => [{-image => $zmreset}], | ||
| 162 | ); | ||
| 163 | $self->Delegates( | ||
| 164 | 'FindAll' => $txt, | ||
| 165 | 'FindNext' => $txt, | ||
| 166 | DEFAULT => $self, | ||
| 167 | ); | ||
| 168 | |||
| 169 | } | ||
| 170 | |||
| 171 | sub searchClose { | ||
| 172 | my $self = shift; | ||
| 173 | my $searchbar = $self->Subwidget('Searchbar'); | ||
| 174 | $searchbar->packForget if $searchbar->ismapped; | ||
| 175 | $self->Subwidget('txt')->focus; | ||
| 176 | } | ||
| 177 | |||
| 178 | sub searchPop { | ||
| 179 | my $self = shift; | ||
| 180 | my $searchbar = $self->Subwidget('Searchbar'); | ||
| 181 | $searchbar->pack(-fill => 'x', -padx => 2, -pady => 2) unless $searchbar->ismapped; | ||
| 182 | $self->Subwidget('Search')->focus; | ||
| 183 | } | ||
| 184 | |||
| 185 | =head1 LICENSE | ||
| 186 | |||
| 187 | Same as Perl. | ||
| 188 | |||
| 189 | =head1 AUTHOR | ||
| 190 | |||
| 191 | Hans Jeuken (hanje at cpan dot org) | ||
| 192 | |||
| 193 | =head1 TODO | ||
| 194 | |||
| 195 | =over 4 | ||
| 196 | |||
| 197 | =back | ||
| 198 | |||
| 199 | =head1 BUGS AND CAVEATS | ||
| 200 | |||
| 201 | If you find any bugs, please contact the author. | ||
| 202 | |||
| 203 | =head1 SEE ALSO | ||
| 204 | |||
| 205 | L<Tk::PodViewer> | ||
| 206 | |||
| 207 | =cut | ||
| 208 | |||
| 209 | |||
| 210 | 1; |