aboutsummaryrefslogtreecommitdiff
path: root/src/MTools/Widget/MBouton.pm
diff options
context:
space:
mode:
Diffstat (limited to 'src/MTools/Widget/MBouton.pm')
-rw-r--r--src/MTools/Widget/MBouton.pm180
1 files changed, 180 insertions, 0 deletions
diff --git a/src/MTools/Widget/MBouton.pm b/src/MTools/Widget/MBouton.pm
new file mode 100644
index 0000000..73c0fc0
--- /dev/null
+++ b/src/MTools/Widget/MBouton.pm
@@ -0,0 +1,180 @@
+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::MGroup;
+use MTools::MSwitch;
+use MTools::MState;
+use MTools::MTimer;
+
+use vars qw /@ISA/;
+
+BEGIN
+{
+ @ISA = qw /MTools::MGroup/;
+}
+
+sub new {
+ my ($class, %options) = @_;
+ my $self = new MTools::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} ? 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');
+ $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})
+ {
+ $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::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, '<Button-1>'],
+ force_press => [$self, 'PRESS'],
+ maintain => [$self, 'MAINTAIN_DOWN'],
+ release => [$self, '<ButtonRelease-1>'],
+ force_release => [$self, 'RELEASE'],
+ enter => [$self, '<Enter>'],
+ leave => [$self, '<Leave>'],
+ 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);
+
+ return $self;
+}
+
+
+1;
+