package MTools::Widget::MRadioBouton; # 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::MTimer; use MTools::MState; 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 = $options {g_on}; my $over = defined $options {g_over} ? $options {g_over} : $on; my $off = $options {g_off}; $self -> recordEvent ('RELEASE'); $self -> recordEvent ('PRESS'); $self -> recordProperty ('selected', 0); my @gon; push (@gon, $on); my @gover; push (@gover, $over); my @goff; push (@goff, $off); if (defined $options {g_text}) { $self -> recordProperty ('text', $options {text}); my $txt = minstance ($options {g_text}, $self); push (@gon, $txt); push (@goff, $txt); plink ([$self, 'text'], [$txt, '-text']); } $self -> mconfigure (-atomic => 1); my $timer = new MTools::MTimer (5, 1); my @gon_tmp = @gon; push (@gon_tmp, $timer); my $sw = new MTools::MSwitch ( $self, on => \@gon, on_tmp => \@gon_tmp, over => \@gover, off => \@goff, ); my $st = new MTools::MState ( current_state => 'on', events => { enter => [$self, ''], leave => [$self, ''], press => [$self, ''], press2 => [$self, 'PRESS'], release => [$self, 'RELEASE'], timeout => [$timer, 'TIME_OUT'], }, transitions => { on => { enter => { to => 'over', }, press => { to => 'off', notify => 'PRESSED', }, press2 => { to => 'off', notify => 'PRESSED', }, }, on_tmp => { press => { to => 'off', notify => 'PRESSED', }, press2 => { to => 'off', notify => 'PRESSED', }, timeout => { to => 'on', }, }, over => { leave => { to => 'on_tmp', }, press => { to => 'off', notify => 'PRESSED', }, press2 => { to => 'off', notify => 'PRESSED', }, }, off => { release => { to => 'on', notify => 'RELEASED', }, }, }, switchs => [$sw], ); $st -> binding ('PRESSED', sub { $self -> mconfigure ('selected', 1); }); $st -> binding ('RELEASED', sub { $self -> mconfigure ('selected', 0); }); $self -> propagate ($st, 'PRESSED'); return $self; } 1;