ToggleController.st
author Claus Gittinger <cg@exept.de>
Thu, 09 Nov 2017 20:09:30 +0100
changeset 6225 0122e4e6c587
parent 6097 12cbf18037c6
permissions -rw-r--r--
#FEATURE by cg class: GenericToolbarIconLibrary class added: #hideFilter16x16Icon
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
6083
3843436837d2 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 4525
diff changeset
    14
"{ NameSpace: Smalltalk }"
3843436837d2 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 4525
diff changeset
    15
78
1122ab450f80 Initial revision
claus
parents:
diff changeset
    16
ButtonController subclass:#ToggleController
582
e151eeae2c9a documentation
Claus Gittinger <cg@exept.de>
parents: 203
diff changeset
    17
	instanceVariableNames:'action'
e151eeae2c9a documentation
Claus Gittinger <cg@exept.de>
parents: 203
diff changeset
    18
	classVariableNames:''
e151eeae2c9a documentation
Claus Gittinger <cg@exept.de>
parents: 203
diff changeset
    19
	poolDictionaries:''
e151eeae2c9a documentation
Claus Gittinger <cg@exept.de>
parents: 203
diff changeset
    20
	category:'Interface-Support-Controllers'
78
1122ab450f80 Initial revision
claus
parents:
diff changeset
    21
!
1122ab450f80 Initial revision
claus
parents:
diff changeset
    22
88
7560534e9026 *** empty log message ***
claus
parents: 78
diff changeset
    23
!ToggleController class methodsFor:'documentation'!
7560534e9026 *** empty log message ***
claus
parents: 78
diff changeset
    24
7560534e9026 *** empty log message ***
claus
parents: 78
diff changeset
    25
copyright
7560534e9026 *** empty log message ***
claus
parents: 78
diff changeset
    26
"
7560534e9026 *** empty log message ***
claus
parents: 78
diff changeset
    27
 COPYRIGHT (c) 1995 by Claus Gittinger
7560534e9026 *** empty log message ***
claus
parents: 78
diff changeset
    28
	      All Rights Reserved
7560534e9026 *** empty log message ***
claus
parents: 78
diff changeset
    29
7560534e9026 *** empty log message ***
claus
parents: 78
diff changeset
    30
 This software is furnished under a license and may be used
7560534e9026 *** empty log message ***
claus
parents: 78
diff changeset
    31
 only in accordance with the terms of that license and with the
7560534e9026 *** empty log message ***
claus
parents: 78
diff changeset
    32
 inclusion of the above copyright notice.   This software may not
7560534e9026 *** empty log message ***
claus
parents: 78
diff changeset
    33
 be provided or otherwise made available to, or used by, any
7560534e9026 *** empty log message ***
claus
parents: 78
diff changeset
    34
 other person.  No title to or ownership of the software is
7560534e9026 *** empty log message ***
claus
parents: 78
diff changeset
    35
 hereby transferred.
7560534e9026 *** empty log message ***
claus
parents: 78
diff changeset
    36
"
7560534e9026 *** empty log message ***
claus
parents: 78
diff changeset
    37
!
7560534e9026 *** empty log message ***
claus
parents: 78
diff changeset
    38
7560534e9026 *** empty log message ***
claus
parents: 78
diff changeset
    39
documentation
7560534e9026 *** empty log message ***
claus
parents: 78
diff changeset
    40
"
7560534e9026 *** empty log message ***
claus
parents: 78
diff changeset
    41
    ToggleControllers redefine some of ButtonControllers behavior;
7560534e9026 *** empty log message ***
claus
parents: 78
diff changeset
    42
    user interaction: they always triggerOnDown, and ignore buttonrelease.
7560534e9026 *** empty log message ***
claus
parents: 78
diff changeset
    43
    Finally, every buttonPress leads to a toggle action.
125
claus
parents: 120
diff changeset
    44
128
claus
parents: 126
diff changeset
    45
    ToggleController adds another actionBlock, since it inherits press-
125
claus
parents: 120
diff changeset
    46
    and releaseActions, while we want one actionBlock to be used for both
claus
parents: 120
diff changeset
    47
    on- and off. The actionBlock (if any) is evaluated with the current
6097
12cbf18037c6 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 6083
diff changeset
    48
    toggles state if it expects an argument, or without argument if it's a no-arg
125
claus
parents: 120
diff changeset
    49
    block.
128
claus
parents: 126
diff changeset
    50
claus
parents: 126
diff changeset
    51
    Other than that, all model relations are inherited - i.e. if the view has a model,
claus
parents: 126
diff changeset
    52
    that one gets change-messages and the toggle updates on aspect changes.
582
e151eeae2c9a documentation
Claus Gittinger <cg@exept.de>
parents: 203
diff changeset
    53
e151eeae2c9a documentation
Claus Gittinger <cg@exept.de>
parents: 203
diff changeset
    54
    [author:]
e151eeae2c9a documentation
Claus Gittinger <cg@exept.de>
parents: 203
diff changeset
    55
        Claus Gittinger
88
7560534e9026 *** empty log message ***
claus
parents: 78
diff changeset
    56
"
7560534e9026 *** empty log message ***
claus
parents: 78
diff changeset
    57
! !
7560534e9026 *** empty log message ***
claus
parents: 78
diff changeset
    58
200
aa3e56929a5a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
    59
!ToggleController methodsFor:'accessing'!
78
1122ab450f80 Initial revision
claus
parents:
diff changeset
    60
200
aa3e56929a5a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
    61
action:aBlock
aa3e56929a5a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
    62
    "set the action to be performed. This is called
aa3e56929a5a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
    63
     with the toggles state as argument."
aa3e56929a5a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
    64
aa3e56929a5a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
    65
    action := aBlock
119
claus
parents: 88
diff changeset
    66
! !
claus
parents: 88
diff changeset
    67
claus
parents: 88
diff changeset
    68
!ToggleController methodsFor:'events'!
claus
parents: 88
diff changeset
    69
4524
0a8e4c9060ae class: ToggleController
Stefan Vogel <sv@exept.de>
parents: 2504
diff changeset
    70
keyPress:key x:x y:y
0a8e4c9060ae class: ToggleController
Stefan Vogel <sv@exept.de>
parents: 2504
diff changeset
    71
    "toggle on 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
    <resource: #keyboard (#Space)>
0a8e4c9060ae class: ToggleController
Stefan Vogel <sv@exept.de>
parents: 2504
diff changeset
    74
0a8e4c9060ae class: ToggleController
Stefan Vogel <sv@exept.de>
parents: 2504
diff changeset
    75
    (key == Character space) ifTrue:[
4525
27c8f14cfd04 class: ToggleController
Stefan Vogel <sv@exept.de>
parents: 4524
diff changeset
    76
        enableChannel value ifTrue:[
27c8f14cfd04 class: ToggleController
Stefan Vogel <sv@exept.de>
parents: 4524
diff changeset
    77
            self toggle.
27c8f14cfd04 class: ToggleController
Stefan Vogel <sv@exept.de>
parents: 4524
diff changeset
    78
            ^ self
27c8f14cfd04 class: ToggleController
Stefan Vogel <sv@exept.de>
parents: 4524
diff changeset
    79
        ].
4524
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
    super keyPress:key x:x y:y
0a8e4c9060ae class: ToggleController
Stefan Vogel <sv@exept.de>
parents: 2504
diff changeset
    82
!
0a8e4c9060ae class: ToggleController
Stefan Vogel <sv@exept.de>
parents: 2504
diff changeset
    83
119
claus
parents: 88
diff changeset
    84
performAction
973
bcc8b920dccc model notifications first - then actionBlocks.
Claus Gittinger <cg@exept.de>
parents: 582
diff changeset
    85
    "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
    86
     channels, then evaluate any (optional) press/release actions,
bcc8b920dccc model notifications first - then actionBlocks.
Claus Gittinger <cg@exept.de>
parents: 582
diff changeset
    87
     finally evaluate my real action, the toggle action.
bcc8b920dccc model notifications first - then actionBlocks.
Claus Gittinger <cg@exept.de>
parents: 582
diff changeset
    88
     Individual press/release actions are usually nil for toggles."
bcc8b920dccc model notifications first - then actionBlocks.
Claus Gittinger <cg@exept.de>
parents: 582
diff changeset
    89
bcc8b920dccc model notifications first - then actionBlocks.
Claus Gittinger <cg@exept.de>
parents: 582
diff changeset
    90
    super performAction.
bcc8b920dccc model notifications first - then actionBlocks.
Claus Gittinger <cg@exept.de>
parents: 582
diff changeset
    91
120
claus
parents: 119
diff changeset
    92
    action notNil ifTrue:[
973
bcc8b920dccc model notifications first - then actionBlocks.
Claus Gittinger <cg@exept.de>
parents: 582
diff changeset
    93
        active := true.
2504
f12dab112227 use new #valueWithOptionalArg
Claus Gittinger <cg@exept.de>
parents: 973
diff changeset
    94
        action valueWithOptionalArgument:pressed.
973
bcc8b920dccc model notifications first - then actionBlocks.
Claus Gittinger <cg@exept.de>
parents: 582
diff changeset
    95
        active := false.
120
claus
parents: 119
diff changeset
    96
    ].
973
bcc8b920dccc model notifications first - then actionBlocks.
Claus Gittinger <cg@exept.de>
parents: 582
diff changeset
    97
bcc8b920dccc model notifications first - then actionBlocks.
Claus Gittinger <cg@exept.de>
parents: 582
diff changeset
    98
    "Modified: 24.1.1997 / 15:42:14 / cg"
78
1122ab450f80 Initial revision
claus
parents:
diff changeset
    99
! !
1122ab450f80 Initial revision
claus
parents:
diff changeset
   100
200
aa3e56929a5a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   101
!ToggleController methodsFor:'initialization'!
78
1122ab450f80 Initial revision
claus
parents:
diff changeset
   102
200
aa3e56929a5a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   103
initialize
6083
3843436837d2 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 4525
diff changeset
   104
    <modifier: #super> "must be called if redefined"
3843436837d2 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 4525
diff changeset
   105
200
aa3e56929a5a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   106
    super initialize.
aa3e56929a5a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   107
    self beToggle
6083
3843436837d2 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 4525
diff changeset
   108
3843436837d2 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 4525
diff changeset
   109
    "Modified: / 08-02-2017 / 00:34:39 / cg"
200
aa3e56929a5a checkin from browser
Claus Gittinger <cg@exept.de>
parents: 174
diff changeset
   110
! !
78
1122ab450f80 Initial revision
claus
parents:
diff changeset
   111
203
8a38b0b03233 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 200
diff changeset
   112
!ToggleController class methodsFor:'documentation'!
8a38b0b03233 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 200
diff changeset
   113
8a38b0b03233 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 200
diff changeset
   114
version
6083
3843436837d2 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 4525
diff changeset
   115
    ^ '$Header$'
4525
27c8f14cfd04 class: ToggleController
Stefan Vogel <sv@exept.de>
parents: 4524
diff changeset
   116
!
27c8f14cfd04 class: ToggleController
Stefan Vogel <sv@exept.de>
parents: 4524
diff changeset
   117
27c8f14cfd04 class: ToggleController
Stefan Vogel <sv@exept.de>
parents: 4524
diff changeset
   118
version_CVS
6083
3843436837d2 #OTHER by cg
Claus Gittinger <cg@exept.de>
parents: 4525
diff changeset
   119
    ^ '$Header$'
203
8a38b0b03233 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 200
diff changeset
   120
! !
4524
0a8e4c9060ae class: ToggleController
Stefan Vogel <sv@exept.de>
parents: 2504
diff changeset
   121