package MTools::Widget::MBouton; # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU LGPL Libray General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program 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 Library General Public License for more details. # # You should have received a copy of the GNU Library General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA, # or refer to http://www.gnu.org/copyleft/lgpl.html # ################################################################## use strict; use MTools; use MTools::GUI::MGroup; use MTools::MSwitch; use MTools::MState; use MTools::MTimer; use vars qw /@ISA/; BEGIN { @ISA = qw /MTools::GUI::MGroup/; } sub new { my ($class, %options) = @_; my $self = new MTools::GUI::MGroup ($options {parent}); bless $self, $class; my $on = minstance ($options {g_on}, $self); my $off = minstance ($options {g_off}, $self); my $over = defined $options {g_over} && $options {g_over} ne ''? minstance ($options {g_over}, $self) : $on; my $eventOn = defined $options {e_press} ? $options {e_press} : 'PRESS'; my $eventOff = defined $options {e_release} ? $options {e_release} : 'RELEASED'; my $cb = $options {call} if (defined $options {call}); $self -> recordEvent ('MAINTAIN_DOWN'); #utiliser les variables $eventOn? $self -> recordEvent ('PRESS'); $self -> recordEvent ('RELEASE'); $self -> mconfigure (-atomic => 1); my @gon; push (@gon, $on); my @goff; push (@goff, $off); my @gover; push (@gover, $over); if (defined $options {g_text} && $options {g_text} ne "") { $self -> recordProperty ('text', $options {text}); my $txt = minstance ($options {g_text}, $self); push (@gon, $txt); push (@goff, $txt); push (@gover, $txt); plink ([$self, 'text'], [$txt, '-text']); } $self -> {gp_over} = new MTools::GUI::MGroup ($self); push (@gon, $self -> {gp_over}); push (@goff, $self -> {gp_over}); push (@gover, $self -> {gp_over}); my $timer = new MTools::MTimer (5, 1); my @gon_tmp = @gon; push (@gon_tmp, $timer); my $sw = new MTools::MSwitch ( $self, 'up' => \@gon, 'up_tmp' => \@gon_tmp, 'down' => \@goff, 'over' => \@gover, 'maintain_down' => \@goff, ); my $st = new MTools::MState ( current_state => 'up', events => { press => [$self, ''], force_press => [$self, 'PRESS'], maintain => [$self, 'MAINTAIN_DOWN'], release => [$self, ''], force_release => [$self, 'RELEASE'], enter => [$self, ''], leave => [$self, ''], timeout => [$timer, 'TIME_OUT'] }, transitions => { 'up' => { 'press' => { to => 'down', notify => $eventOn, }, 'force_press' => { to => 'down', notify => $eventOn, }, 'enter' => { to => 'over', }, }, 'up_tmp' => { 'press' => { to => 'down', notify => $eventOn, }, 'force_press' => { to => 'down', notify => $eventOn, }, 'timeout' => { to => 'up', }, }, 'over' => { 'press' => { to => 'down', notify => $eventOn, }, 'force_press' => { to => 'down', notify => $eventOn, }, 'leave' => { to => 'up_tmp', } }, 'down' => { 'release' => { to => 'up', notify => $eventOff, }, 'force_release' => { to => 'up', notify => $eventOff, }, 'maintain' => { to => 'maintain_down', }, }, 'maintain_down' => { 'press' => { to => 'down', }, 'force_release' => { to => 'up', notify => $eventOff, }, }, }, switchs => [$sw], ); if (defined $cb) { $st -> binding ($eventOn, sub { executer ($cb); }); } $self -> propagate ($st, $eventOn); $self -> propagate ($st, $eventOff); delete $options {g_on} if defined $options {g_on}; delete $options {g_off} if defined $options {g_off}; delete $options {g_over} if defined $options {g_over}; delete $options {e_press} if defined $options {e_press}; delete $options {e_release} if defined $options {e_release}; delete $options {call} if defined $options {call}; delete $options {text} if defined $options {text}; delete $options {g_text} if defined $options {g_text}; delete $options {parent} if defined $options {parent}; $self -> mconfigure (%options); return $self; } 1;