aboutsummaryrefslogtreecommitdiff
path: root/src/MTools/Widget/MRadioBouton.pm
blob: 1dfa1a4a8ab374042876ad37291cd860ace5e960 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
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::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 $off = $options {g_off};
	
	$self -> recordEvent ('RELEASE');
	$self -> recordEvent ('PRESS');
	$self -> recordProperty ('selected', 0);
	
	my @gon;
	push (@gon, $on);
	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 $sw = new MTools::MSwitch (
		$self,
		on => \@gon,
		off => \@goff,
	);
	my $st = new MTools::MState (
		current_state => 'on',
		events => {
			press => [$self, '<Button-1>'],
			press2 => [$self, 'PRESS'],
			release => [$self, 'RELEASE'],
		},
		transitions => {
			on => {
				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;