line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# Copyright (c) 2007 by Christoph Lamprecht. 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
|
|
|
|
|
|
|
# ch.l.ngre@online.de |
5
|
|
|
|
|
|
|
package Tk::GraphItems::GraphItem; |
6
|
4
|
|
|
4
|
|
23
|
use Scalar::Util qw(weaken); |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
207
|
|
7
|
|
|
|
|
|
|
|
8
|
4
|
|
|
4
|
|
25
|
use strict; |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
124
|
|
9
|
4
|
|
|
4
|
|
19
|
use warnings; |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
106
|
|
10
|
4
|
|
|
4
|
|
22
|
use Carp; |
|
4
|
|
|
|
|
12
|
|
|
4
|
|
|
|
|
233
|
|
11
|
|
|
|
|
|
|
|
12
|
4
|
|
|
4
|
|
75
|
use 5.008; |
|
4
|
|
|
|
|
13
|
|
|
4
|
|
|
|
|
4323
|
|
13
|
|
|
|
|
|
|
our $VERSION = '0.12'; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub new{ |
16
|
0
|
|
|
0
|
0
|
|
my $class = shift; |
17
|
0
|
0
|
|
|
|
|
if (ref $class) { |
18
|
0
|
|
|
|
|
|
croak "new has to be called on a class-name!"; |
19
|
|
|
|
|
|
|
} |
20
|
0
|
0
|
|
|
|
|
if (@_%2) { |
21
|
0
|
|
|
|
|
|
croak "wrong number of args! "; |
22
|
|
|
|
|
|
|
} |
23
|
0
|
|
|
|
|
|
my $self = {}; |
24
|
0
|
|
|
|
|
|
bless $self, $class; |
25
|
0
|
|
|
|
|
|
$self->initialize(@_); |
26
|
0
|
|
|
|
|
|
return $self; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
sub initialize{ |
29
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
30
|
0
|
|
|
|
|
|
$self->_register_instance; |
31
|
0
|
|
|
|
|
|
return $self; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub add_dependent{ |
36
|
0
|
|
|
0
|
0
|
|
my ($self,$dependent) = @_; |
37
|
0
|
|
|
|
|
|
$self->{dependents}{$dependent} = $dependent; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
sub add_dependent_weak{ |
40
|
0
|
|
|
0
|
0
|
|
my ($self,$dependent) = @_; |
41
|
0
|
|
|
|
|
|
$self->add_dependent($dependent); |
42
|
0
|
|
|
|
|
|
weaken($self->{dependents}{$dependent}); |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
sub remove_dependent{ |
45
|
0
|
|
|
0
|
0
|
|
my ($self,$dependent) = @_; |
46
|
0
|
|
|
|
|
|
delete $self->{dependents}{$dependent}; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub dependents{ |
50
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
51
|
0
|
|
|
|
|
|
return values %{$self->{dependents}}; |
|
0
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub _set_layer{ |
55
|
0
|
|
|
0
|
|
|
my ($self,$layer)=@_; |
56
|
0
|
|
|
|
|
|
my $can = $self->get_canvas; |
57
|
|
|
|
|
|
|
|
58
|
0
|
|
|
|
|
|
my $l_id = $can->{GraphItem_layers}[$layer]; |
59
|
0
|
0
|
|
|
|
|
unless ($can->type($l_id)){ |
60
|
0
|
|
|
|
|
|
croak "could not _set_layer. |
61
|
|
|
|
|
|
|
Canvas-item with id <$l_id> has been deleted by user. |
62
|
|
|
|
|
|
|
Be careful not to manipulate or delete Tk::GraphItems directly!" ;} |
63
|
0
|
|
|
|
|
|
$can->lower($_,$l_id)for $self->canvas_items; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub _create_canvas_layers{ |
67
|
0
|
|
|
0
|
|
|
my $self = shift; |
68
|
0
|
0
|
|
|
|
|
return if ($self->get_canvas)->{GraphItem_layers}; |
69
|
0
|
|
|
|
|
|
my $can = $self->get_canvas; |
70
|
0
|
|
|
|
|
|
my @layers; |
71
|
0
|
|
|
|
|
|
$layers[$_]= $can->createLine(10,10,10,10) for (0..2); |
72
|
0
|
|
|
|
|
|
$can->{GraphItem_layers} = \@layers; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
sub get_canvas{ |
76
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
77
|
0
|
|
|
|
|
|
$self->{canvas}; |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
sub _register_instance{ |
81
|
0
|
|
|
0
|
|
|
my $self = shift; |
82
|
0
|
|
|
|
|
|
my $can = $self->get_canvas; |
83
|
0
|
|
0
|
|
|
|
my $obj_map = $can->{GraphItemsMap}||={}; |
84
|
0
|
|
|
|
|
|
for ($self->canvas_items) { |
85
|
0
|
|
|
|
|
|
$obj_map->{$_} = $self; |
86
|
0
|
|
|
|
|
|
weaken ($obj_map->{$_}); |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
sub _bind_this_class{ |
91
|
0
|
|
|
0
|
|
|
my ($self,$event,$tag,$code) = @_; |
92
|
0
|
|
|
|
|
|
my $can = $self->{canvas}; |
93
|
0
|
0
|
|
|
|
|
if ($code) { |
94
|
|
|
|
|
|
|
$can->bind($tag,$event => sub { |
95
|
0
|
|
|
0
|
|
|
my($can) = @_; |
96
|
0
|
|
|
|
|
|
my $id= ($can->find(withtag => 'current'))[0]; |
97
|
0
|
|
|
|
|
|
my $self = _get_inst_by_id($can,$id); |
98
|
0
|
|
|
|
|
|
$code->($self); |
99
|
0
|
|
|
|
|
|
}); |
100
|
|
|
|
|
|
|
} else { |
101
|
0
|
|
|
|
|
|
$can->bind( $tag,$event,''); |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
sub _get_inst_by_id{ |
106
|
0
|
|
|
0
|
|
|
my ($can,$id) = @_; |
107
|
0
|
|
|
|
|
|
my $obj_map = $can->{GraphItemsMap}; |
108
|
0
|
|
0
|
|
|
|
return $obj_map->{$id}||undef; |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
sub DESTROY{ |
114
|
0
|
|
|
0
|
|
|
my $self = shift; |
115
|
0
|
|
|
|
|
|
my $can = $self->{canvas}; |
116
|
0
|
|
|
|
|
|
my $obj_map = $can->{GraphItemsMap}; |
117
|
|
|
|
|
|
|
#my $text = $self->text()||'a GraphItem'; |
118
|
|
|
|
|
|
|
|
119
|
0
|
|
|
|
|
|
for ($self->canvas_items) { |
120
|
0
|
|
|
|
|
|
eval{$can->delete($_)}; #if UNIVERSAL::isa($can,'Tk::Canvas'); |
|
0
|
|
|
|
|
|
|
121
|
0
|
|
|
|
|
|
delete $obj_map->{$_}; |
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
# destroy dependents...? |
124
|
0
|
|
|
|
|
|
for ($self->dependents) { |
125
|
0
|
|
|
|
|
|
eval{$_->destroy_myself} |
|
0
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
#print "destroying $text\n"; |
128
|
|
|
|
|
|
|
} |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
1; |