|
1 " |
|
2 COPYRIGHT (c) 1989/90/91 by Claus Gittinger |
|
3 All Rights Reserved |
|
4 |
|
5 This software is furnished under a license and may be used |
|
6 only in accordance with the terms of that license and with the |
|
7 inclusion of the above copyright notice. This software may not |
|
8 be provided or otherwise made available to, or used by, any |
|
9 other person. No title to or ownership of the software is |
|
10 hereby transferred. |
|
11 " |
|
12 |
|
13 Button subclass:#Toggle |
|
14 instanceVariableNames:'' |
|
15 classVariableNames:'' |
|
16 poolDictionaries:'' |
|
17 category:'Views-Interactors' |
|
18 ! |
|
19 |
|
20 Toggle comment:' |
|
21 |
|
22 COPYRIGHT (c) 1989/90/91 by Claus Gittinger |
|
23 All Rights Reserved |
|
24 |
|
25 this button changes state whenever pressed and stays pressed until pressed |
|
26 again. All the main action is in Button, Toggle just redefines buttonpress/ |
|
27 release behavior. |
|
28 |
|
29 %W% %E% |
|
30 written spring/summer 89 by claus |
|
31 '! |
|
32 |
|
33 !Toggle methodsFor:'changing state'! |
|
34 |
|
35 toggleNoAction |
|
36 "toggle, but do NOT perform any action - can be used to change a toggle |
|
37 under program control (i.e. turn one toggle off from another one)" |
|
38 |
|
39 pressed := pressed not. |
|
40 self redraw |
|
41 ! |
|
42 |
|
43 toggle |
|
44 "toggle and perform the action" |
|
45 |
|
46 enabled ifTrue:[ |
|
47 pressed := pressed not. |
|
48 pressed ifTrue:[ |
|
49 self level:onLevel. |
|
50 pressActionBlock notNil ifTrue:[pressActionBlock value] |
|
51 ] ifFalse:[ |
|
52 self level:offLevel. |
|
53 releaseActionBlock notNil ifTrue:[releaseActionBlock value] |
|
54 ]. |
|
55 self redraw |
|
56 ] |
|
57 ! ! |
|
58 |
|
59 !Toggle methodsFor:'events'! |
|
60 |
|
61 buttonPress:button x:x y:y |
|
62 button == 1 ifFalse:[ |
|
63 ^ super buttonPress:button x:x y:y |
|
64 ]. |
|
65 self toggle |
|
66 ! |
|
67 |
|
68 buttonRelease:button x:x y:y |
|
69 button == 1 ifFalse:[ |
|
70 ^ super buttonRelease:button x:x y:y |
|
71 ]. |
|
72 "ignore" |
|
73 ! ! |