#KanDeLa.
#Copyright (C) 2011 Alain Barbason
#
#This file is part of KanDeLa.
#
#KanDeLa is free software: you can redistribute it and/or modify
#it under the terms of the GNU General Public License as published by
#the Free Software Foundation, either version 3 of the License, or
#(at your option) any later version.
#
#KanDeLa is distributed in the hope that it will be useful,
#but WITHOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#GNU General Public License for more details.
#
#You should have received a copy of the GNU General Public License
#along with KanDeLa.  If not, see <http://www.gnu.org/licenses/>.
#
use strict;
use warnings;
use English qw( -no_match_vars )
  ;    # todo wath's the utility ? see p161 (p165_fr) of PBP
package Toeval;
# possibility to advenced user to write a perl-tk command in .lace file
# sample put in the .lace  : -type Toeval -id 12 -string $::drawing->createOval(0,0,200,200,-outline=>"red");
use Commun;
our @ISA=qw( Commun );
our %liste;
sub getListe {    # rewrite : try to put in Commun.pm if possible.
    my $self=shift;
    return %liste;
}
sub new {
    my $classe=shift;
    my $self=$classe->SUPER::new();
    my %param=@_;
    if ($param{"-id"}) {
        $self->{ID}=$param{"-id"};
        Commun::set_id($self->{ID});
    }
    $self->{STRING}=$param{"-string"};
    my $myeval='$self->{DRAW}=' . $self->{STRING};
## no critic # todo how good programming that ?
    eval $myeval;
#print "\nsdfg", $self->{DRAW}, "\n";
#croak $EVAL_ERROR if $EVAL_ERROR; # fixme-m because : Global symbol "$EVAL_ERROR" requires explicit package
    bless($self, $classe);
    $self->draw();
    $liste{$self->id}=$self;
    $::liste{$self->{DRAW}}=$self;
    return $self;
}
sub draw {
}
sub hidden {
    foreach my $liste (values %liste) {
        $::drawing->itemconfigure($liste->{DRAW}, -state => "hidden");
    }
}
sub normal {
    foreach my $liste (values %liste) {
        $::drawing->itemconfigure($liste->{DRAW}, -state => "normal");
    }
}
sub deselectionne {
}
sub redraw {
}
sub print {
    my $self=shift;
    return "-type Toeval -id $self->{ID} -string $self->{STRING}\n";
}
1;
