Canvas.pm untested

filter: Statementstmt 0.0% 0 / 52 Branchbran 0.0% 0 / 2 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 0.0% 0 / 9 Podpod 0.0% 0 / 4 totaltotal 0.0% 0 / 70 CC 2 SCAR 10.3
CC
2
Cov
0%
Populate
6.0
clear
2.0
resetPrintCmd
2.0
CRAP 2.8
1 # Copyright (c) 1997-1998 Dominique Dumont. All rights reserved.
2 # This program is free software; you can redistribute it and/or
3 # modify it under the same terms as Perl itself.
4  
5 package Tk::Multi::Canvas ;
6  
7 use strict;
8  
9 use vars qw($printCmd $defaultPrintCmd $VERSION);
10  
11 use base qw(Tk::Derived Tk::Frame Tk::Multi::Any);
12  
13 $VERSION = sprintf "%d.%03d", q$Revision: 2.5 $ =~ /(\d+)\.(\d+)/;
14  
15 # Items to export into callers namespace by default. Note: do not export
16 # names by default without a very good reason. Use EXPORT_OK instead.
17 # Do not simply export all your public functions/methods/constants.
18  
19 $printCmd = $defaultPrintCmd = 'lp -opostscript' ;
20  
21 Tk::Widget->Construct('MultiCanvas');
22  
23 # Preloaded methods go here.
24  
25 # Autoload methods go after =cut, and are processed by the autosplit program.
26  
27 sub Populate
28 {
29 my ($cw,$args) = @_ ;
30 Tk::Multi::Any::normalize($cw,$args) ;
31  
32 require Tk::Label;
33 require Tk::Canvas;
34  
35 $cw->{_printCmdRef} = \$printCmd ;
36  
37 my $title = $cw->{'title'} = delete $args->{'-title'} || 'anonymous';
38  
39 my $menu = delete $args->{'-menu_button'};
40 die "Multi window $title: missing -menu_button argument\n"
41 unless defined $menu ;
42  
43 my $titleLabel = $cw->Label(-text => $title.' display')-> pack(qw/-fill x/) ;
44  
45 $menu->command(-label=>'print...', -command => [$cw, 'print' ]) ;
46 $menu->command(-label=>'clear', -command => [$cw, 'clear' ]);
47  
48 # print stuff
49 $cw->{_printToFile} = 0;
50 $cw->{_printFile} = '';
51  
52 my $slaveWindow = $cw -> Scrolled (qw/Canvas -relief sunken -bd 2/)
53 -> pack(qw/-fill both -expand 1/) ;
54  
55 my $subref = sub {$menu->Popup(-popover => 'cursor', -popanchor => 'nw')};
56 #$slaveWindow->Subwidget('scrolled') -> bind ('<Button-3>', $subref);
57 $titleLabel -> bind('<Button-3>', $subref);
58  
59 $cw->ConfigSpecs(
60 '-relief' => [$cw, undef, undef, 'raised'],
61 '-borderwidth' => [$cw, undef, undef, 2 ],
62 '-scrollbars'=> [$slaveWindow, undef, undef,'osoe'],
63 '-width' => [$slaveWindow, undef, undef, 400],
64 '-height' => [$slaveWindow, undef, undef, 200],
65 'DEFAULT' => [$slaveWindow]
66 ) ;
67 $cw->Delegates('command' => $menu,
68 'clear' => $cw,
69 DEFAULT => $slaveWindow) ;
70  
71 $cw->SUPER::Populate($args);
72 }
73  
74 sub clear
75 {
76 my $cw= shift ;
77 $cw-> delete('all') ;
78 }
79  
80 sub resetPrintCmd
81 {
82 my $cw=shift ;
83 $printCmd=$defaultPrintCmd ;
84 }
85  
86 sub printableDump
87 {
88 my $cw= shift ;
89 my $array = $cw->cget('-scrollregion') ;
90  
91 return $cw-> postscript
92 (qw/-colormode gray -pageheight 29c -pagewidth 21c/,
93 -width => $array->[2],
94 -height => $array->[3]);
95 }
96  
97 1;
98 __END__