CornerBox.pm

filter: Statementstmt 33.3% 1 / 3 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 1 / 1 Podpod n/a totaltotal 50.0% 2 / 4 CC 1 SCAR 2.6
CC
1
Cov
33%
BEGIN
1.3
CRAP 1.3
« ComboEntry.pm ↑ Summary DockFrame.pm »
1 package Tk::CornerBox;
2  
3 0 ▶use Tk::Canvas;
Subroutine BEGIN: called CC=1 SCAR=2.6
4 use Tk::Frame;
5 use Tk;
6  
7 use vars qw ($VERSION $TRIMCOUNT);
8 use base qw (Tk::Frame);
9 use strict;
10  
11 $VERSION = '0.02';
12  
13 $TRIMCOUNT = 3;
14  
15 Tk::Widget->Construct ('CornerBox');
16  
17 sub Populate
18 {
19 my $this = shift;
20  
21 $this->SUPER::Populate (@_);
22  
23 my $l_Canvas = $this->Component
24 (
25 'Canvas' => 'Canvas',
26 '-width' => 20,
27 '-height' => 20,
28 '-borderwidth' => 0,
29 '-highlightthickness' => 0,
30 );
31  
32 $l_Canvas->pack
33 (
34 '-fill' => 'both',
35 '-expand' => 'false',
36 '-padx' => 0,
37 '-pady' => 0,
38 );
39  
40 $l_Canvas->Tk::bind ('<ButtonPress-1>' => [\&Press, $this]);
41 $l_Canvas->Tk::bind ('<B1-Motion>' => [\&Resize, $this]);
42 $l_Canvas->Tk::bind ('<Configure>' => [\&Configure, $this]);
43 $this->Tk::bind ('<Enter>' => [\&Enter, $this]);
44 $this->Tk::bind ('<Leave>' => [\&Leave, $this]);
45  
46 return $this;
47 }
48  
49 sub Configure
50 {
51 my ($p_Canvas, $this) = @_;
52  
53 return unless ($this->IsMapped());
54  
55 my $l_Height = $this->height();
56 my $l_Width = $this->width();
57  
58 $p_Canvas->configure
59 (
60 '-scrollregion' => [0, 0, $l_Width, $l_Height],
61 );
62  
63 unless (defined ($this->{'m_TrimList'}))
64 {
65 my $l_HighColor = $this->Darken ($this->cget ('-background'), 150);
66 my $l_LowColor = $this->Darken ($this->cget ('-background'), 60);
67  
68 for (my $l_Index = 0; $l_Index < $TRIMCOUNT; ++$l_Index)
69 {
70 push
71 (
72 @{$this->{'m_TrimList'}},
73 $p_Canvas->create ('line', 30, 0, 0, 30, '-fill' => $l_HighColor),
74 $p_Canvas->create ('line', 30, 1, 1, 30, '-fill' => $l_LowColor),
75 );
76 }
77 }
78  
79 for (my $l_Index = 0; $l_Index <= $#{$this->{'m_TrimList'}}; $l_Index += 2)
80 {
81 my ($l_Light, $l_Dark) = @{$this->{'m_TrimList'}} [$l_Index .. ($l_Index + 1)];
82 my $l_Divisor = (($l_Index + 2) / 2) - 1;
83  
84 $p_Canvas->coords
85 (
86 $l_Light,
87 $l_Width, ($l_Height / ($TRIMCOUNT + 1)) * $l_Divisor,
88 ($l_Width / ($TRIMCOUNT + 1)) * $l_Divisor, $l_Height,
89 );
90  
91 $p_Canvas->coords
92 (
93 $l_Dark,
94 $l_Width, (($l_Height / ($TRIMCOUNT + 1)) * $l_Divisor) + 2,
95 ($l_Width / (($TRIMCOUNT + 1)) * $l_Divisor) + 2, $l_Height,
96 );
97 }
98 }
99  
100 sub Enter
101 {
102 $_[0]->{'m_Cursor'} = $_[0]->cget ('-cursor');
103 $_[0]->configure ('-cursor' => ($^O =~ /^(MSWin32|DOS)$/ ? 'size_nw_se' : 'bottom_right_corner'));
104 }
105  
106 sub Leave
107 {
108 $_[0]->configure ('-cursor' => $_[0]->{'m_Cursor'} || 'arrow');
109 }
110  
111 sub Press
112 {
113 $_[1]->{'-deltax'} = $_[1]->pointerx();
114 $_[1]->{'-deltay'} = $_[1]->pointery();
115 }
116  
117 sub Resize
118 {
119 my @l_Coordinates = split (/[+x]/, $_[1]->toplevel()->geometry());
120
121 $l_Coordinates [0] += ($_[1]->pointerx() - $_[1]->{'-deltax'});
122 $l_Coordinates [1] += ($_[1]->pointery() - $_[1]->{'-deltay'});
123  
124 $_[1]->{'-deltax'} = $_[1]->pointerx();
125 $_[1]->{'-deltay'} = $_[1]->pointery();
126  
127 $_[1]->toplevel()->geometry
128 (
129 $l_Coordinates [0].'x'.$l_Coordinates [1] # .'+'.$l_Coordinates [2].'+'.$l_Coordinates [3]
130 );
131 }
132  
133 1;
134  
135 __END__
« ComboEntry.pm ↑ Summary DockFrame.pm »