| 1 | package Tk::Multi::Text ; | ||
| 2 | |||
| 3 | use strict; | ||
| 4 | |||
| 5 | use vars qw($printCmd $defaultPrintCmd $VERSION); | ||
| 6 | |||
| 7 | use base qw(Tk::Derived Tk::Frame Tk::Multi::Any); | ||
| 8 | |||
| 9 | $VERSION = sprintf "%d.%03d", q$Revision: 2.5 $ =~ /(\d+)\.(\d+)/; | ||
| 10 | |||
| 11 | # Items to export into callers namespace by default. Note: do not export | ||
| 12 | # names by default without a very good reason. Use EXPORT_OK instead. | ||
| 13 | # Do not simply export all your public functions/methods/constants. | ||
| 14 | |||
| 15 | $printCmd = $defaultPrintCmd = 'lp -ol70 -otl66 -o12 -olm10' ; | ||
| 16 | |||
| 17 | Tk::Widget->Construct('MultiText'); | ||
| 18 | |||
| 19 | # Preloaded methods go here. | ||
| 20 | |||
| 21 | # Autoload methods go after =cut, and are processed by the autosplit program. | ||
| 22 | |||
| 23 | sub Populate | ||
| 24 | { | ||
| 25 | my ($cw,$args) = @_ ; | ||
| 26 | Tk::Multi::Any::normalize($cw,$args) ; | ||
| 27 | |||
| 28 | require Tk::Label; | ||
| 29 | require Tk::ROText; | ||
| 30 | |||
| 31 | $cw->{_printCmdRef} = \$printCmd ; | ||
| 32 | my $data = delete $args->{'-data'} ; | ||
| 33 | |||
| 34 | my $title = $cw ->{'title'} = delete $args->{'-title'} || 'anonymous'; | ||
| 35 | |||
| 36 | my $menu = delete $args->{'-menu_button'}; | ||
| 37 | die "Multi window $title: missing menu_button argument\n" | ||
| 38 | unless defined $menu ; | ||
| 39 | |||
| 40 | my $subref = sub {$menu->Popup(-popover => 'cursor', -popanchor => 'nw')}; | ||
| 41 | |||
| 42 | #$cw->bind ('<Button-3>', $subref); | ||
| 43 | #$slaveWindow->bind ('<Button-3>', $subref); | ||
| 44 | #Tk::bind($cw, '<Button-3>', $subref); | ||
| 45 | |||
| 46 | my $titleLabel = $cw->Label(-text => $title.' display')-> pack(qw/-fill x/) ; | ||
| 47 | $titleLabel -> bind('<Button-3>', $subref); | ||
| 48 | |||
| 49 | $menu->command(-label=>'print...', -command => [$cw, 'print' ]) ; | ||
| 50 | $menu->command(-label=>'clear', -command => [$cw, 'clear' ]); | ||
| 51 | |||
| 52 | # print stuff | ||
| 53 | $cw->{_printToFile} = 0; | ||
| 54 | $cw->{_printFile} = ''; | ||
| 55 | |||
| 56 | my $slaveWindow = $cw -> Scrolled ('ROText') | ||
| 57 | -> pack(qw/-fill both -expand 1/) ; | ||
| 58 | |||
| 59 | $cw->Advertise('text' => $slaveWindow) ; | ||
| 60 | |||
| 61 | $cw->ConfigSpecs( | ||
| 62 | '-relief' => [$cw], | ||
| 63 | '-borderwidth' => [$cw], | ||
| 64 | '-scrollbars'=> [$slaveWindow, undef, undef,'osoe'], | ||
| 65 | '-width' => [$slaveWindow, undef, undef, 80], | ||
| 66 | '-height' => [$slaveWindow, undef, undef, 5], | ||
| 67 | 'DEFAULT' => [$slaveWindow] | ||
| 68 | ) ; | ||
| 69 | $cw->Delegates('command' => $menu, | ||
| 70 | 'clear' => $cw, | ||
| 71 | DEFAULT => $slaveWindow) ; | ||
| 72 | |||
| 73 | # needed to avoid geometry problems with packAdjuster | ||
| 74 | #$cw->DoWhenIdle(sub{ $cw->packPropagate(0);}) ; | ||
| 75 | $cw->SUPER::Populate($args); | ||
| 76 | |||
| 77 | $cw-> insertText (@$data) if defined $data ; | ||
| 78 | $cw->yview('moveto', 1) ; # move diplay to the end | ||
| 79 | } | ||
| 80 | |||
| 81 | sub insertText | ||
| 82 | { | ||
| 83 | my $cw= shift ; | ||
| 84 | |||
| 85 | foreach (@_) | ||
| 86 | { | ||
| 87 | $cw->insert('end',$_) ; | ||
| 88 | } | ||
| 89 | $cw->yview('moveto', 1) ; | ||
| 90 | } | ||
| 91 | |||
| 92 | |||
| 93 | sub clear | ||
| 94 | { | ||
| 95 | my $cw= shift ; | ||
| 96 | |||
| 97 | $cw->delete('1.0','end') ; | ||
| 98 | } | ||
| 99 | |||
| 100 | sub printableDump | ||
| 101 | { | ||
| 102 | my $cw= shift ; | ||
| 103 | return $cw->get('0.0','end') ; | ||
| 104 | } | ||
| 105 | |||
| 106 | 1; | ||
| 107 | __END__ |