ToggleController.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Fri, 26 Jan 2018 11:43:24 +0000
branchjv
changeset 6279 232954e959f7
parent 4525 27c8f14cfd04
child 6083 3843436837d2
permissions -rw-r--r--
Fixed `PopUpList` widget to display correctly non-string objects ...using their `#displayOn:x:y:` / or `#displayString`. The popup menu shown the `#displayString` correctly however the "button" stubbornly used object's `#printString`, making the widget largely unusable with anything but strings. This commit removes this limitation.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
88
7560534e9026 *** empty log message ***
claus
parents: 78
diff changeset
     1
"
7560534e9026 *** empty log message ***
claus
parents: 78
diff changeset
     2
 COPYRIGHT (c) 1995 by Claus Gittinger
7560534e9026 *** empty log message ***
claus
parents: 78
diff changeset
     3
	      All Rights Reserved
7560534e9026 *** empty log message ***
claus
parents: 78
diff changeset
     4
7560534e9026 *** empty log message ***
claus
parents: 78
diff changeset
     5
 This software is furnished under a license and may be used
7560534e9026 *** empty log message ***
claus
parents: 78
diff changeset
     6
 only in accordance with the terms of that license and with the
7560534e9026 *** empty log message ***
claus
parents: 78
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
7560534e9026 *** empty log message ***
claus
parents: 78
diff changeset
     8
 be provided or otherwise made available to, or used by, any
7560534e9026 *** empty log message ***
claus
parents: 78
diff changeset
     9
 other person.  No title to or ownership of the software is
7560534e9026 *** empty log message ***
claus
parents: 78
diff changeset
    10
 hereby transferred.
7560534e9026 *** empty log message ***
claus
parents: 78
diff changeset
    11
"
2504
f12dab112227 use new #valueWithOptionalArg
Claus Gittinger <cg@exept.de>
parents: 973
diff changeset
    12
"{ Package: 'stx:libwidg' }"
f12dab112227 use new #valueWithOptionalArg
Claus Gittinger <cg@exept.de>
parents: 973
diff changeset
    13
78
1122ab450f80 Initial revision
claus
parents:
diff changeset
    14
ButtonController subclass:#ToggleController
582
e151eeae2c9a documentation
Claus Gittinger <cg@exept.de>
parents: 203
diff changeset
    15
	instanceVariableNames:'action'
e151eeae2c9a documentation
Claus Gittinger <cg@exept.de>
parents: 203
diff changeset
    16
	classVariableNames:''
e151eeae2c9a documentation
Claus Gittinger <cg@exept.de>
parents: 203
diff changeset
    17
	poolDictionaries:''
e151eeae2c9a documentation
Claus Gittinger <cg@exept.de>
parents: 203
diff changeset
    18
	category:'Interface-Support-Controllers'
78
1122ab450f80 Initial revision
claus
parents:
diff changeset
    19
!
1122ab450f80 Initial revision
claus
parents:
diff changeset
    20
88
7560534e9026 *** empty log message ***
claus
parents: 78
diff changeset
    21
!ToggleController class methodsFor:'documentation'!
7560534e9026 *** empty log message ***
claus
parents: 78
diff changeset
    22
7560534e9026 *** empty log message ***
claus
parents: 78
diff changeset
    23
copyright
7560534e9026 *** empty log message ***
claus
parents: 78
diff changeset
    24
"
7560534e9026 *** empty log message ***
claus
parents: 78
diff changeset
    25
 COPYRIGHT (c) 1995 by Claus Gittinger
7560534e9026 *** empty log message ***
claus
parents: 78
diff changeset
    26
	      All Rights Reserved
7560534e9026 *** empty log message ***
claus
parents: 78
diff changeset
    27
7560534e9026 *** empty log message ***
claus
parents: 78
diff changeset
    28
 This software is furnished under a license and may be used
7560534e9026 *** empty log message ***
claus
parents: 78
diff changeset
    29
 only in accordance with the terms of that license and with the
7560534e9026 *** empty log message ***
claus
parents: 78
diff changeset
    30
 inclusion of the above copyright notice.   This software may not
7560534e9026 *** empty log message ***
claus
parents: 78
diff changeset
    31
 be provided or otherwise made available to, or used by, any
7560534e9026 *** empty log message ***
claus
parents: 78
diff changeset
    32
 other person.  No title to or ownership of the software is
7560534e9026 *** empty log message ***
claus
parents: 78
diff changeset
    33
 hereby transferred.
7560534e9026 *** empty log message ***
claus
parents: 78
diff changeset
    34
"
7560534e9026 *** empty log message ***
claus
parents: 78
diff changeset
    35
!
7560534e9026 *** empty log message ***
claus
parents: 78
diff changeset
    36
7560534e9026 *** empty log message ***
claus
parents: 78
diff changeset
    37
documentation
7560534e9026 *** empty log message ***
claus
parents: 78
diff changeset
    38
"
7560534e9026 *** empty log message ***
claus
parents: 78
diff changeset
    39
    ToggleControllers redefine some of ButtonControllers behavior;
7560534e9026 *** empty log message ***
claus
parents: 78
diff changeset
    40
    user interaction: they always triggerOnDown, and ignore buttonrelease.
7560534e9026 *** empty log message ***
claus
parents: 78
diff changeset
    41
    Finally, every buttonPress leads to a toggle action.
125
claus
parents: 120
diff changeset
    42
128
claus
parents: 126
diff changeset
    43
    ToggleController adds another actionBlock, since it inherits press-
125
claus
parents: 120
diff changeset
    44
    and releaseActions, while we want one actionBlock to be used for both
claus
parents: 120
diff changeset
    45
    on- and off. The actionBlock (if any) is evaluated with the current
claus
parents: 120
diff changeset
    46
    toggles state if it expects an argument, or without argument if its a no-arg
claus
parents: 120
diff changeset
    47
    block.
128
claus
parents: 126
diff changeset
    48
claus
parents: 126
diff changeset
    49
    Other than that, all model relations are inherited - i.e. if the view has a model,
claus
parents: 126
diff changeset
    50
    that one gets change-messages and the toggle updates on aspect changes.
582
e151eeae2c9a documentation
Claus Gittinger <cg@exept.de>
parents: 203
diff changeset
    51
e151eeae2c9a documentation
Claus Gittinger <cg@exept.de>
parents: 203
diff changeset
    52
    [author:]
e151eeae2c9a documentation
Claus Gittinger <cg@exept.de>
parents: 203
diff changeset
    53
        Claus Gittinger
88
7560534e9026 *** empty log message ***
claus
parents: 78
diff changeset
    54
"
7560534e9026 *** empty log message ***
claus
parents: 78
diff changeset
    55
! !
7560534e9026 *** empty log message ***
claus
parents: 78
diff changeset
    56
200
aa3e56929a5a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
    57
!ToggleController methodsFor:'accessing'!
78
1122ab450f80 Initial revision
claus
parents:
diff changeset
    58
200
aa3e56929a5a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
    59
action:aBlock
aa3e56929a5a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
    60
    "set the action to be performed. This is called
aa3e56929a5a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
    61
     with the toggles state as argument."
aa3e56929a5a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
    62
aa3e56929a5a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
    63
    action := aBlock
119
claus
parents: 88
diff changeset
    64
! !
claus
parents: 88
diff changeset
    65
claus
parents: 88
diff changeset
    66
!ToggleController methodsFor:'events'!
claus
parents: 88
diff changeset
    67
4524
0a8e4c9060ae class: ToggleController
Stefan Vogel <sv@exept.de>
parents: 2504
diff changeset
    68
keyPress:key x:x y:y
0a8e4c9060ae class: ToggleController
Stefan Vogel <sv@exept.de>
parents: 2504
diff changeset
    69
    "toggle on space"
0a8e4c9060ae class: ToggleController
Stefan Vogel <sv@exept.de>
parents: 2504
diff changeset
    70
0a8e4c9060ae class: ToggleController
Stefan Vogel <sv@exept.de>
parents: 2504
diff changeset
    71
    <resource: #keyboard (#Space)>
0a8e4c9060ae class: ToggleController
Stefan Vogel <sv@exept.de>
parents: 2504
diff changeset
    72
0a8e4c9060ae class: ToggleController
Stefan Vogel <sv@exept.de>
parents: 2504
diff changeset
    73
    (key == Character space) ifTrue:[
4525
27c8f14cfd04 class: ToggleController
Stefan Vogel <sv@exept.de>
parents: 4524
diff changeset
    74
        enableChannel value ifTrue:[
27c8f14cfd04 class: ToggleController
Stefan Vogel <sv@exept.de>
parents: 4524
diff changeset
    75
            self toggle.
27c8f14cfd04 class: ToggleController
Stefan Vogel <sv@exept.de>
parents: 4524
diff changeset
    76
            ^ self
27c8f14cfd04 class: ToggleController
Stefan Vogel <sv@exept.de>
parents: 4524
diff changeset
    77
        ].
4524
0a8e4c9060ae class: ToggleController
Stefan Vogel <sv@exept.de>
parents: 2504
diff changeset
    78
    ].
0a8e4c9060ae class: ToggleController
Stefan Vogel <sv@exept.de>
parents: 2504
diff changeset
    79
    super keyPress:key x:x y:y
0a8e4c9060ae class: ToggleController
Stefan Vogel <sv@exept.de>
parents: 2504
diff changeset
    80
!
0a8e4c9060ae class: ToggleController
Stefan Vogel <sv@exept.de>
parents: 2504
diff changeset
    81
119
claus
parents: 88
diff changeset
    82
performAction
973
bcc8b920dccc model notifications first - then actionBlocks.
Claus Gittinger <cg@exept.de>
parents: 582
diff changeset
    83
    "the toggle changed its state; first tell the model and
bcc8b920dccc model notifications first - then actionBlocks.
Claus Gittinger <cg@exept.de>
parents: 582
diff changeset
    84
     channels, then evaluate any (optional) press/release actions,
bcc8b920dccc model notifications first - then actionBlocks.
Claus Gittinger <cg@exept.de>
parents: 582
diff changeset
    85
     finally evaluate my real action, the toggle action.
bcc8b920dccc model notifications first - then actionBlocks.
Claus Gittinger <cg@exept.de>
parents: 582
diff changeset
    86
     Individual press/release actions are usually nil for toggles."
bcc8b920dccc model notifications first - then actionBlocks.
Claus Gittinger <cg@exept.de>
parents: 582
diff changeset
    87
bcc8b920dccc model notifications first - then actionBlocks.
Claus Gittinger <cg@exept.de>
parents: 582
diff changeset
    88
    super performAction.
bcc8b920dccc model notifications first - then actionBlocks.
Claus Gittinger <cg@exept.de>
parents: 582
diff changeset
    89
120
claus
parents: 119
diff changeset
    90
    action notNil ifTrue:[
973
bcc8b920dccc model notifications first - then actionBlocks.
Claus Gittinger <cg@exept.de>
parents: 582
diff changeset
    91
        active := true.
2504
f12dab112227 use new #valueWithOptionalArg
Claus Gittinger <cg@exept.de>
parents: 973
diff changeset
    92
        action valueWithOptionalArgument:pressed.
973
bcc8b920dccc model notifications first - then actionBlocks.
Claus Gittinger <cg@exept.de>
parents: 582
diff changeset
    93
        active := false.
120
claus
parents: 119
diff changeset
    94
    ].
973
bcc8b920dccc model notifications first - then actionBlocks.
Claus Gittinger <cg@exept.de>
parents: 582
diff changeset
    95
bcc8b920dccc model notifications first - then actionBlocks.
Claus Gittinger <cg@exept.de>
parents: 582
diff changeset
    96
    "Modified: 24.1.1997 / 15:42:14 / cg"
78
1122ab450f80 Initial revision
claus
parents:
diff changeset
    97
! !
1122ab450f80 Initial revision
claus
parents:
diff changeset
    98
200
aa3e56929a5a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
    99
!ToggleController methodsFor:'initialization'!
78
1122ab450f80 Initial revision
claus
parents:
diff changeset
   100
200
aa3e56929a5a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   101
initialize
aa3e56929a5a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   102
    super initialize.
aa3e56929a5a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   103
    self beToggle
aa3e56929a5a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   104
! !
78
1122ab450f80 Initial revision
claus
parents:
diff changeset
   105
203
8a38b0b03233 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 200
diff changeset
   106
!ToggleController class methodsFor:'documentation'!
8a38b0b03233 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 200
diff changeset
   107
8a38b0b03233 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 200
diff changeset
   108
version
4525
27c8f14cfd04 class: ToggleController
Stefan Vogel <sv@exept.de>
parents: 4524
diff changeset
   109
    ^ '$Header: /cvs/stx/stx/libwidg/ToggleController.st,v 1.15 2013-02-27 11:23:05 stefan Exp $'
27c8f14cfd04 class: ToggleController
Stefan Vogel <sv@exept.de>
parents: 4524
diff changeset
   110
!
27c8f14cfd04 class: ToggleController
Stefan Vogel <sv@exept.de>
parents: 4524
diff changeset
   111
27c8f14cfd04 class: ToggleController
Stefan Vogel <sv@exept.de>
parents: 4524
diff changeset
   112
version_CVS
27c8f14cfd04 class: ToggleController
Stefan Vogel <sv@exept.de>
parents: 4524
diff changeset
   113
    ^ '$Header: /cvs/stx/stx/libwidg/ToggleController.st,v 1.15 2013-02-27 11:23:05 stefan Exp $'
203
8a38b0b03233 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 200
diff changeset
   114
! !
4524
0a8e4c9060ae class: ToggleController
Stefan Vogel <sv@exept.de>
parents: 2504
diff changeset
   115