ButtonController.st
author claus
Mon, 18 Sep 1995 12:39:22 +0200
changeset 162 1c68705a8903
parent 160 0f356ac274e0
child 174 d80a6cc3f9b2
permissions -rw-r--r--
.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
76
81e3409404d2 Initial revision
claus
parents:
diff changeset
     1
"
81e3409404d2 Initial revision
claus
parents:
diff changeset
     2
 COPYRIGHT (c) 1995 by Claus Gittinger
81e3409404d2 Initial revision
claus
parents:
diff changeset
     3
	      All Rights Reserved
81e3409404d2 Initial revision
claus
parents:
diff changeset
     4
81e3409404d2 Initial revision
claus
parents:
diff changeset
     5
 This software is furnished under a license and may be used
81e3409404d2 Initial revision
claus
parents:
diff changeset
     6
 only in accordance with the terms of that license and with the
81e3409404d2 Initial revision
claus
parents:
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
81e3409404d2 Initial revision
claus
parents:
diff changeset
     8
 be provided or otherwise made available to, or used by, any
81e3409404d2 Initial revision
claus
parents:
diff changeset
     9
 other person.  No title to or ownership of the software is
81e3409404d2 Initial revision
claus
parents:
diff changeset
    10
 hereby transferred.
81e3409404d2 Initial revision
claus
parents:
diff changeset
    11
"
81e3409404d2 Initial revision
claus
parents:
diff changeset
    12
121
claus
parents: 118
diff changeset
    13
'From Smalltalk/X, Version:2.10.5 on 4-may-1995 at 6:17:35 am'!
claus
parents: 118
diff changeset
    14
76
81e3409404d2 Initial revision
claus
parents:
diff changeset
    15
Controller subclass:#ButtonController
145
claus
parents: 133
diff changeset
    16
	 instanceVariableNames:'enableChannel pressChannel releaseChannel
claus
parents: 133
diff changeset
    17
		pressed active entered isTriggerOnDown autoRepeat
125
claus
parents: 121
diff changeset
    18
		repeatBlock initialDelay repeatDelay pressActionBlock
claus
parents: 121
diff changeset
    19
		releaseActionBlock isToggle'
76
81e3409404d2 Initial revision
claus
parents:
diff changeset
    20
	 classVariableNames:''
81e3409404d2 Initial revision
claus
parents:
diff changeset
    21
	 poolDictionaries:''
126
claus
parents: 125
diff changeset
    22
	 category:'Interface-Support-Controllers'
76
81e3409404d2 Initial revision
claus
parents:
diff changeset
    23
!
81e3409404d2 Initial revision
claus
parents:
diff changeset
    24
81e3409404d2 Initial revision
claus
parents:
diff changeset
    25
!ButtonController class methodsFor:'documentation'!
81e3409404d2 Initial revision
claus
parents:
diff changeset
    26
81e3409404d2 Initial revision
claus
parents:
diff changeset
    27
copyright
81e3409404d2 Initial revision
claus
parents:
diff changeset
    28
"
81e3409404d2 Initial revision
claus
parents:
diff changeset
    29
 COPYRIGHT (c) 1995 by Claus Gittinger
81e3409404d2 Initial revision
claus
parents:
diff changeset
    30
	      All Rights Reserved
81e3409404d2 Initial revision
claus
parents:
diff changeset
    31
81e3409404d2 Initial revision
claus
parents:
diff changeset
    32
 This software is furnished under a license and may be used
81e3409404d2 Initial revision
claus
parents:
diff changeset
    33
 only in accordance with the terms of that license and with the
81e3409404d2 Initial revision
claus
parents:
diff changeset
    34
 inclusion of the above copyright notice.   This software may not
81e3409404d2 Initial revision
claus
parents:
diff changeset
    35
 be provided or otherwise made available to, or used by, any
81e3409404d2 Initial revision
claus
parents:
diff changeset
    36
 other person.  No title to or ownership of the software is
81e3409404d2 Initial revision
claus
parents:
diff changeset
    37
 hereby transferred.
81e3409404d2 Initial revision
claus
parents:
diff changeset
    38
"
81e3409404d2 Initial revision
claus
parents:
diff changeset
    39
!
81e3409404d2 Initial revision
claus
parents:
diff changeset
    40
81e3409404d2 Initial revision
claus
parents:
diff changeset
    41
version
81e3409404d2 Initial revision
claus
parents:
diff changeset
    42
"
162
claus
parents: 160
diff changeset
    43
$Header: /cvs/stx/stx/libwidg/ButtonController.st,v 1.19 1995-09-18 10:38:03 claus Exp $
76
81e3409404d2 Initial revision
claus
parents:
diff changeset
    44
"
81e3409404d2 Initial revision
claus
parents:
diff changeset
    45
!
81e3409404d2 Initial revision
claus
parents:
diff changeset
    46
81e3409404d2 Initial revision
claus
parents:
diff changeset
    47
documentation
81e3409404d2 Initial revision
claus
parents:
diff changeset
    48
"
81e3409404d2 Initial revision
claus
parents:
diff changeset
    49
    ButtonControllers are used with buttons and handle all user interaction.
81e3409404d2 Initial revision
claus
parents:
diff changeset
    50
    These are automatically created when a Button is created, therefore no manual
81e3409404d2 Initial revision
claus
parents:
diff changeset
    51
    action is required for creation.
133
claus
parents: 132
diff changeset
    52
    In normal applications, you dont have to care for the controller; 
claus
parents: 132
diff changeset
    53
    access to the controllers behavior is possible via messages to the button.
125
claus
parents: 121
diff changeset
    54
    (setting actions, controlling autorepeat etc.)
76
81e3409404d2 Initial revision
claus
parents:
diff changeset
    55
133
claus
parents: 132
diff changeset
    56
    See examples in the Button class.
claus
parents: 132
diff changeset
    57
76
81e3409404d2 Initial revision
claus
parents:
diff changeset
    58
    Instance variables:
81e3409404d2 Initial revision
claus
parents:
diff changeset
    59
133
claus
parents: 132
diff changeset
    60
      enableChannel           <ValueHolder    pressing is allowed (default: true)
claus
parents: 132
diff changeset
    61
			       on Boolean>    
125
claus
parents: 121
diff changeset
    62
76
81e3409404d2 Initial revision
claus
parents:
diff changeset
    63
      pressed                 <Boolean>       true if currently pressed (read-only)
125
claus
parents: 121
diff changeset
    64
76
81e3409404d2 Initial revision
claus
parents:
diff changeset
    65
      entered                 <Boolean>       true if the cursor is currently in this view
125
claus
parents: 121
diff changeset
    66
118
claus
parents: 97
diff changeset
    67
      isTriggerOnDown         <Boolean>       controls if the action should be executed on
76
81e3409404d2 Initial revision
claus
parents:
diff changeset
    68
					      press or on release (default: on release).
125
claus
parents: 121
diff changeset
    69
claus
parents: 121
diff changeset
    70
      isToggle                <Boolean>       controls if the button should show toggle
claus
parents: 121
diff changeset
    71
					      behavior (as opposed to one-shot behavior)
claus
parents: 121
diff changeset
    72
76
81e3409404d2 Initial revision
claus
parents:
diff changeset
    73
      pressActionBlock        <Block>         block to evaluate when pressed (default: noop)
125
claus
parents: 121
diff changeset
    74
76
81e3409404d2 Initial revision
claus
parents:
diff changeset
    75
      releaseActionBlock      <Block>         block to evaluate when released (default: noop)
125
claus
parents: 121
diff changeset
    76
76
81e3409404d2 Initial revision
claus
parents:
diff changeset
    77
      autoRepeat              <Boolean>       auto-repeats when pressed long enough (default: false)
125
claus
parents: 121
diff changeset
    78
76
81e3409404d2 Initial revision
claus
parents:
diff changeset
    79
      initialDelay            <Number>        seconds till first auto-repeat (default: 0.2)
125
claus
parents: 121
diff changeset
    80
76
81e3409404d2 Initial revision
claus
parents:
diff changeset
    81
      repeatDelay             <Number>        seconds of repeat intervall (default: 0.025)
125
claus
parents: 121
diff changeset
    82
76
81e3409404d2 Initial revision
claus
parents:
diff changeset
    83
      repeatBlock             <Block>         block evaluated for auto-repeat (internal)
125
claus
parents: 121
diff changeset
    84
76
81e3409404d2 Initial revision
claus
parents:
diff changeset
    85
      active                  <Boolean>       true during action evaluation (internal)
81e3409404d2 Initial revision
claus
parents:
diff changeset
    86
"
81e3409404d2 Initial revision
claus
parents:
diff changeset
    87
! !
81e3409404d2 Initial revision
claus
parents:
diff changeset
    88
81e3409404d2 Initial revision
claus
parents:
diff changeset
    89
!ButtonController class methodsFor:'defaults'!
81e3409404d2 Initial revision
claus
parents:
diff changeset
    90
81e3409404d2 Initial revision
claus
parents:
diff changeset
    91
defaultRepeatDelay
81e3409404d2 Initial revision
claus
parents:
diff changeset
    92
    "when autorepeat is enabled, and button is not released,
81e3409404d2 Initial revision
claus
parents:
diff changeset
    93
     repeat every repeatDelay seconds"
81e3409404d2 Initial revision
claus
parents:
diff changeset
    94
81e3409404d2 Initial revision
claus
parents:
diff changeset
    95
    ^ 0.025
81e3409404d2 Initial revision
claus
parents:
diff changeset
    96
!
81e3409404d2 Initial revision
claus
parents:
diff changeset
    97
81e3409404d2 Initial revision
claus
parents:
diff changeset
    98
defaultInitialDelay
81e3409404d2 Initial revision
claus
parents:
diff changeset
    99
    "when autorepeat is enabled, and button is not released,
81e3409404d2 Initial revision
claus
parents:
diff changeset
   100
     start repeating after initialDelay seconds"
81e3409404d2 Initial revision
claus
parents:
diff changeset
   101
81e3409404d2 Initial revision
claus
parents:
diff changeset
   102
    ^ 0.2
81e3409404d2 Initial revision
claus
parents:
diff changeset
   103
! !
81e3409404d2 Initial revision
claus
parents:
diff changeset
   104
128
claus
parents: 126
diff changeset
   105
!ButtonController methodsFor:'accessing-state'!
76
81e3409404d2 Initial revision
claus
parents:
diff changeset
   106
121
claus
parents: 118
diff changeset
   107
pressed
claus
parents: 118
diff changeset
   108
    "return true, if I am pressed"
118
claus
parents: 97
diff changeset
   109
121
claus
parents: 118
diff changeset
   110
    ^ pressed
118
claus
parents: 97
diff changeset
   111
!
claus
parents: 97
diff changeset
   112
121
claus
parents: 118
diff changeset
   113
active
125
claus
parents: 121
diff changeset
   114
    "return true, if I am active; 
claus
parents: 121
diff changeset
   115
     that is: currently performing my action.
claus
parents: 121
diff changeset
   116
     This query can be used to avoid multiple redraws."
121
claus
parents: 118
diff changeset
   117
claus
parents: 118
diff changeset
   118
    ^ active
claus
parents: 118
diff changeset
   119
!
76
81e3409404d2 Initial revision
claus
parents:
diff changeset
   120
121
claus
parents: 118
diff changeset
   121
enabled
claus
parents: 118
diff changeset
   122
    "return true, if I am enabled"
claus
parents: 118
diff changeset
   123
133
claus
parents: 132
diff changeset
   124
    ^ enableChannel value
121
claus
parents: 118
diff changeset
   125
!
claus
parents: 118
diff changeset
   126
claus
parents: 118
diff changeset
   127
entered
claus
parents: 118
diff changeset
   128
    "return true, if the mouse pointer is currently in my view"
claus
parents: 118
diff changeset
   129
claus
parents: 118
diff changeset
   130
    ^ entered
76
81e3409404d2 Initial revision
claus
parents:
diff changeset
   131
!
81e3409404d2 Initial revision
claus
parents:
diff changeset
   132
128
claus
parents: 126
diff changeset
   133
entered:aBoolean
claus
parents: 126
diff changeset
   134
    entered := aBoolean
claus
parents: 126
diff changeset
   135
!
claus
parents: 126
diff changeset
   136
claus
parents: 126
diff changeset
   137
active:aBoolean
claus
parents: 126
diff changeset
   138
    active := aBoolean
claus
parents: 126
diff changeset
   139
!
claus
parents: 126
diff changeset
   140
claus
parents: 126
diff changeset
   141
pressed:aBoolean
claus
parents: 126
diff changeset
   142
    pressed := aBoolean
claus
parents: 126
diff changeset
   143
! !
claus
parents: 126
diff changeset
   144
145
claus
parents: 133
diff changeset
   145
!ButtonController methodsFor:'accessing-channels'!
claus
parents: 133
diff changeset
   146
claus
parents: 133
diff changeset
   147
enableChannel
claus
parents: 133
diff changeset
   148
    "return the valueHolder which holdes the enable
claus
parents: 133
diff changeset
   149
     boolean value"
claus
parents: 133
diff changeset
   150
claus
parents: 133
diff changeset
   151
    ^ enableChannel
claus
parents: 133
diff changeset
   152
!
claus
parents: 133
diff changeset
   153
claus
parents: 133
diff changeset
   154
enableChannel:aValueHolder
claus
parents: 133
diff changeset
   155
    "set the valueHolder, which holds the enable boolean value"
claus
parents: 133
diff changeset
   156
162
claus
parents: 160
diff changeset
   157
    |wasEnabled|
claus
parents: 160
diff changeset
   158
145
claus
parents: 133
diff changeset
   159
    enableChannel notNil ifTrue:[
162
claus
parents: 160
diff changeset
   160
	wasEnabled := enableChannel value.
145
claus
parents: 133
diff changeset
   161
	enableChannel retractInterrestFor:self. 
162
claus
parents: 160
diff changeset
   162
    ] ifFalse:[
claus
parents: 160
diff changeset
   163
	wasEnabled := true
145
claus
parents: 133
diff changeset
   164
    ].
claus
parents: 133
diff changeset
   165
    enableChannel := aValueHolder.
claus
parents: 133
diff changeset
   166
    aValueHolder onChangeSend:#enableStateChange to:self.
162
claus
parents: 160
diff changeset
   167
    enableChannel value ~~ wasEnabled ifTrue:[
claus
parents: 160
diff changeset
   168
	self enableStateChange
145
claus
parents: 133
diff changeset
   169
    ]
162
claus
parents: 160
diff changeset
   170
claus
parents: 160
diff changeset
   171
    "Modified: 17.9.1995 / 19:41:18 / claus"
145
claus
parents: 133
diff changeset
   172
!
claus
parents: 133
diff changeset
   173
claus
parents: 133
diff changeset
   174
pressChannel:aChannel
claus
parents: 133
diff changeset
   175
    pressChannel := aChannel
claus
parents: 133
diff changeset
   176
!
claus
parents: 133
diff changeset
   177
claus
parents: 133
diff changeset
   178
releaseChannel:aChannel
claus
parents: 133
diff changeset
   179
    releaseChannel := aChannel
claus
parents: 133
diff changeset
   180
! !
claus
parents: 133
diff changeset
   181
128
claus
parents: 126
diff changeset
   182
!ButtonController methodsFor:'accessing-behavior'!
claus
parents: 126
diff changeset
   183
76
81e3409404d2 Initial revision
claus
parents:
diff changeset
   184
beTriggerOnDown
81e3409404d2 Initial revision
claus
parents:
diff changeset
   185
    "make the receiver act on button press"
81e3409404d2 Initial revision
claus
parents:
diff changeset
   186
118
claus
parents: 97
diff changeset
   187
    isTriggerOnDown := true
76
81e3409404d2 Initial revision
claus
parents:
diff changeset
   188
!
81e3409404d2 Initial revision
claus
parents:
diff changeset
   189
128
claus
parents: 126
diff changeset
   190
beTriggerOnUp
claus
parents: 126
diff changeset
   191
    "make the receiver act on button release"
claus
parents: 126
diff changeset
   192
claus
parents: 126
diff changeset
   193
    isTriggerOnDown := false
claus
parents: 126
diff changeset
   194
!
claus
parents: 126
diff changeset
   195
claus
parents: 126
diff changeset
   196
triggerOnDown:aBoolean
claus
parents: 126
diff changeset
   197
    "set/clear the flag which controls if the action block is to be evaluated
claus
parents: 126
diff changeset
   198
     on press or on release. 
claus
parents: 126
diff changeset
   199
     (see also ST-80 compatibility methods beTriggerOn*)"
claus
parents: 126
diff changeset
   200
claus
parents: 126
diff changeset
   201
    isTriggerOnDown := aBoolean
76
81e3409404d2 Initial revision
claus
parents:
diff changeset
   202
!
81e3409404d2 Initial revision
claus
parents:
diff changeset
   203
81e3409404d2 Initial revision
claus
parents:
diff changeset
   204
isTriggerOnDown
88
7560534e9026 *** empty log message ***
claus
parents: 87
diff changeset
   205
    "return true, if I trigger on press
7560534e9026 *** empty log message ***
claus
parents: 87
diff changeset
   206
     (in contrast to triggering on up, which is the default)"
7560534e9026 *** empty log message ***
claus
parents: 87
diff changeset
   207
118
claus
parents: 97
diff changeset
   208
    ^ isTriggerOnDown
76
81e3409404d2 Initial revision
claus
parents:
diff changeset
   209
!
81e3409404d2 Initial revision
claus
parents:
diff changeset
   210
128
claus
parents: 126
diff changeset
   211
beToggle
claus
parents: 126
diff changeset
   212
    "make the receiver act like a toggle"
claus
parents: 126
diff changeset
   213
claus
parents: 126
diff changeset
   214
    isTriggerOnDown := true.
claus
parents: 126
diff changeset
   215
    isToggle := true
claus
parents: 126
diff changeset
   216
!
claus
parents: 126
diff changeset
   217
claus
parents: 126
diff changeset
   218
autoRepeat
155
claus
parents: 149
diff changeset
   219
    "turn on autorepeat. OBSOLETE"
128
claus
parents: 126
diff changeset
   220
claus
parents: 126
diff changeset
   221
    autoRepeat := true.
claus
parents: 126
diff changeset
   222
    repeatBlock := [self repeat]
76
81e3409404d2 Initial revision
claus
parents:
diff changeset
   223
!
81e3409404d2 Initial revision
claus
parents:
diff changeset
   224
155
claus
parents: 149
diff changeset
   225
autoRepeat:aBoolean
claus
parents: 149
diff changeset
   226
    "turn on/off autorepeat"
claus
parents: 149
diff changeset
   227
claus
parents: 149
diff changeset
   228
    autoRepeat := aBoolean.
claus
parents: 149
diff changeset
   229
    repeatBlock := [self repeat]
claus
parents: 149
diff changeset
   230
claus
parents: 149
diff changeset
   231
    "Modified: 5.9.1995 / 22:06:00 / claus"
claus
parents: 149
diff changeset
   232
!
claus
parents: 149
diff changeset
   233
76
81e3409404d2 Initial revision
claus
parents:
diff changeset
   234
action:aBlock
81e3409404d2 Initial revision
claus
parents:
diff changeset
   235
    "convenient method: depending on the setting the triggerOnDown flag,
81e3409404d2 Initial revision
claus
parents:
diff changeset
   236
     either set the press-action clear any release-action or
81e3409404d2 Initial revision
claus
parents:
diff changeset
   237
     vice versa, set the release-action and clear the press-action."
81e3409404d2 Initial revision
claus
parents:
diff changeset
   238
118
claus
parents: 97
diff changeset
   239
    isTriggerOnDown ifTrue:[
76
81e3409404d2 Initial revision
claus
parents:
diff changeset
   240
	releaseActionBlock := nil.
81e3409404d2 Initial revision
claus
parents:
diff changeset
   241
	pressActionBlock := aBlock
81e3409404d2 Initial revision
claus
parents:
diff changeset
   242
    ] ifFalse:[
81e3409404d2 Initial revision
claus
parents:
diff changeset
   243
	releaseActionBlock := aBlock.
81e3409404d2 Initial revision
claus
parents:
diff changeset
   244
	pressActionBlock := nil
81e3409404d2 Initial revision
claus
parents:
diff changeset
   245
    ]
81e3409404d2 Initial revision
claus
parents:
diff changeset
   246
!
81e3409404d2 Initial revision
claus
parents:
diff changeset
   247
121
claus
parents: 118
diff changeset
   248
pressAction:aBlock
claus
parents: 118
diff changeset
   249
    "define the action to be performed on press"
claus
parents: 118
diff changeset
   250
claus
parents: 118
diff changeset
   251
    pressActionBlock := aBlock
claus
parents: 118
diff changeset
   252
!
claus
parents: 118
diff changeset
   253
claus
parents: 118
diff changeset
   254
releaseAction:aBlock
claus
parents: 118
diff changeset
   255
    "define the action to be performed on release"
claus
parents: 118
diff changeset
   256
claus
parents: 118
diff changeset
   257
    releaseActionBlock := aBlock
claus
parents: 118
diff changeset
   258
!
claus
parents: 118
diff changeset
   259
118
claus
parents: 97
diff changeset
   260
toggleNoAction
claus
parents: 97
diff changeset
   261
    "toggle, but do NOT perform any action"
claus
parents: 97
diff changeset
   262
claus
parents: 97
diff changeset
   263
    pressed ifTrue:[
claus
parents: 97
diff changeset
   264
	view turnOff.
claus
parents: 97
diff changeset
   265
	pressed := false.
claus
parents: 97
diff changeset
   266
    ] ifFalse:[
claus
parents: 97
diff changeset
   267
	view turnOn.
claus
parents: 97
diff changeset
   268
	pressed := true.
claus
parents: 97
diff changeset
   269
    ].
claus
parents: 97
diff changeset
   270
!
claus
parents: 97
diff changeset
   271
claus
parents: 97
diff changeset
   272
toggle
claus
parents: 97
diff changeset
   273
    "toggle and perform the action"
claus
parents: 97
diff changeset
   274
133
claus
parents: 132
diff changeset
   275
    enableChannel value ifTrue:[
125
claus
parents: 121
diff changeset
   276
	self toggleNoAction.
claus
parents: 121
diff changeset
   277
	self performAction.
claus
parents: 121
diff changeset
   278
	view changed:#toggle with:pressed
121
claus
parents: 118
diff changeset
   279
    ]
claus
parents: 118
diff changeset
   280
!
claus
parents: 118
diff changeset
   281
claus
parents: 118
diff changeset
   282
pressAction
claus
parents: 118
diff changeset
   283
    "return the pressAction; thats the block which gets evaluated
claus
parents: 118
diff changeset
   284
     when the button is pressed (if non-nil)"
claus
parents: 118
diff changeset
   285
claus
parents: 118
diff changeset
   286
    ^ pressActionBlock
claus
parents: 118
diff changeset
   287
!
claus
parents: 118
diff changeset
   288
claus
parents: 118
diff changeset
   289
releaseAction
claus
parents: 118
diff changeset
   290
    "return the releaseAction; thats the block which gets evaluated
claus
parents: 118
diff changeset
   291
     when the button is relreased (if non-nil)"
claus
parents: 118
diff changeset
   292
claus
parents: 118
diff changeset
   293
    ^ releaseActionBlock
claus
parents: 118
diff changeset
   294
!
claus
parents: 118
diff changeset
   295
128
claus
parents: 126
diff changeset
   296
enable
claus
parents: 126
diff changeset
   297
    "enable the button"
claus
parents: 126
diff changeset
   298
133
claus
parents: 132
diff changeset
   299
    enableChannel value ifFalse:[
claus
parents: 132
diff changeset
   300
	enableChannel value:true.
149
claus
parents: 146
diff changeset
   301
	"/ view redraw    - not needed; I listen to enableChannel
128
claus
parents: 126
diff changeset
   302
    ]
claus
parents: 126
diff changeset
   303
!
claus
parents: 126
diff changeset
   304
121
claus
parents: 118
diff changeset
   305
disable
claus
parents: 118
diff changeset
   306
    "disable the button"
claus
parents: 118
diff changeset
   307
133
claus
parents: 132
diff changeset
   308
    enableChannel value ifTrue:[
claus
parents: 132
diff changeset
   309
	enableChannel value:false.
149
claus
parents: 146
diff changeset
   310
	"/ view redraw    - not needed; I listen to enableChannel
133
claus
parents: 132
diff changeset
   311
    ]
76
81e3409404d2 Initial revision
claus
parents:
diff changeset
   312
! !
81e3409404d2 Initial revision
claus
parents:
diff changeset
   313
81e3409404d2 Initial revision
claus
parents:
diff changeset
   314
!ButtonController methodsFor:'event handling'!
81e3409404d2 Initial revision
claus
parents:
diff changeset
   315
81e3409404d2 Initial revision
claus
parents:
diff changeset
   316
buttonPress:button x:x y:y
81e3409404d2 Initial revision
claus
parents:
diff changeset
   317
    (button == 1 or:[button == #select]) ifFalse:[
125
claus
parents: 121
diff changeset
   318
	^ super buttonPress:button x:x y:y
76
81e3409404d2 Initial revision
claus
parents:
diff changeset
   319
    ].
81e3409404d2 Initial revision
claus
parents:
diff changeset
   320
133
claus
parents: 132
diff changeset
   321
    enableChannel value ifTrue:[
125
claus
parents: 121
diff changeset
   322
	isToggle ifTrue:[
claus
parents: 121
diff changeset
   323
	    self toggle.
claus
parents: 121
diff changeset
   324
	    ^ self
claus
parents: 121
diff changeset
   325
	].
118
claus
parents: 97
diff changeset
   326
125
claus
parents: 121
diff changeset
   327
	pressed ifFalse:[
claus
parents: 121
diff changeset
   328
	    pressed := true.
claus
parents: 121
diff changeset
   329
	    view showActive.
76
81e3409404d2 Initial revision
claus
parents:
diff changeset
   330
125
claus
parents: 121
diff changeset
   331
	    (pressActionBlock notNil or:[model notNil]) ifTrue:[
claus
parents: 121
diff changeset
   332
		"
claus
parents: 121
diff changeset
   333
		 force output - so that button is drawn correctly in case
claus
parents: 121
diff changeset
   334
		 of any long-computation (at high priority)
claus
parents: 121
diff changeset
   335
		"
130
claus
parents: 128
diff changeset
   336
		view device flush.
125
claus
parents: 121
diff changeset
   337
	    ].
76
81e3409404d2 Initial revision
claus
parents:
diff changeset
   338
125
claus
parents: 121
diff changeset
   339
	    self performAction.
76
81e3409404d2 Initial revision
claus
parents:
diff changeset
   340
125
claus
parents: 121
diff changeset
   341
	    autoRepeat ifTrue:[
claus
parents: 121
diff changeset
   342
		Processor addTimedBlock:repeatBlock afterSeconds:initialDelay
claus
parents: 121
diff changeset
   343
	    ]
claus
parents: 121
diff changeset
   344
	]
76
81e3409404d2 Initial revision
claus
parents:
diff changeset
   345
    ]
81e3409404d2 Initial revision
claus
parents:
diff changeset
   346
!
81e3409404d2 Initial revision
claus
parents:
diff changeset
   347
81e3409404d2 Initial revision
claus
parents:
diff changeset
   348
buttonRelease:button x:x y:y
81e3409404d2 Initial revision
claus
parents:
diff changeset
   349
    "button was released - if enabled, perform releaseaction"
81e3409404d2 Initial revision
claus
parents:
diff changeset
   350
81e3409404d2 Initial revision
claus
parents:
diff changeset
   351
    (button == 1 or:[button == #select]) ifFalse:[
125
claus
parents: 121
diff changeset
   352
	^ super buttonRelease:button x:x y:y
76
81e3409404d2 Initial revision
claus
parents:
diff changeset
   353
    ].
118
claus
parents: 97
diff changeset
   354
claus
parents: 97
diff changeset
   355
    isToggle ifTrue:[
125
claus
parents: 121
diff changeset
   356
	^ self
118
claus
parents: 97
diff changeset
   357
    ].
claus
parents: 97
diff changeset
   358
76
81e3409404d2 Initial revision
claus
parents:
diff changeset
   359
    pressed ifTrue:[
125
claus
parents: 121
diff changeset
   360
	autoRepeat ifTrue:[
claus
parents: 121
diff changeset
   361
	    Processor removeTimedBlock:repeatBlock
claus
parents: 121
diff changeset
   362
	].
claus
parents: 121
diff changeset
   363
	pressed := false.
claus
parents: 121
diff changeset
   364
	view showPassive.
76
81e3409404d2 Initial revision
claus
parents:
diff changeset
   365
133
claus
parents: 132
diff changeset
   366
	enableChannel value ifTrue:[
125
claus
parents: 121
diff changeset
   367
	    "
claus
parents: 121
diff changeset
   368
	     only perform action if released within myself
claus
parents: 121
diff changeset
   369
	    "
claus
parents: 121
diff changeset
   370
	    ((x >= 0) 
claus
parents: 121
diff changeset
   371
	    and:[x <= view width
claus
parents: 121
diff changeset
   372
	    and:[y >= 0
claus
parents: 121
diff changeset
   373
	    and:[y <= view height]]]) ifTrue:[
claus
parents: 121
diff changeset
   374
		(releaseActionBlock notNil or:[model notNil]) ifTrue:[
claus
parents: 121
diff changeset
   375
		    "
claus
parents: 121
diff changeset
   376
		     force output - so that button is drawn correctly in case
claus
parents: 121
diff changeset
   377
		     of any long-computation (at high priority)
claus
parents: 121
diff changeset
   378
		    "
130
claus
parents: 128
diff changeset
   379
		    view device flush.
125
claus
parents: 121
diff changeset
   380
		].
76
81e3409404d2 Initial revision
claus
parents:
diff changeset
   381
125
claus
parents: 121
diff changeset
   382
		self performAction.
claus
parents: 121
diff changeset
   383
	    ]
claus
parents: 121
diff changeset
   384
	]
76
81e3409404d2 Initial revision
claus
parents:
diff changeset
   385
    ]
81e3409404d2 Initial revision
claus
parents:
diff changeset
   386
!
81e3409404d2 Initial revision
claus
parents:
diff changeset
   387
81e3409404d2 Initial revision
claus
parents:
diff changeset
   388
pointerEnter:state x:x y:y
125
claus
parents: 121
diff changeset
   389
    "mouse pointer entered my view.
claus
parents: 121
diff changeset
   390
     Redraw with enteredColors if they differ from the normal colors"
76
81e3409404d2 Initial revision
claus
parents:
diff changeset
   391
81e3409404d2 Initial revision
claus
parents:
diff changeset
   392
    entered := true.
133
claus
parents: 132
diff changeset
   393
    enableChannel value ifTrue:[
125
claus
parents: 121
diff changeset
   394
	pressed ifTrue:[
claus
parents: 121
diff changeset
   395
	    "
claus
parents: 121
diff changeset
   396
	     reentered after a leave with mouse-button down;
claus
parents: 121
diff changeset
   397
	     restart autorepeating and/or if I am a button with
claus
parents: 121
diff changeset
   398
	     triggerOnDown, show active again.
claus
parents: 121
diff changeset
   399
	    "
76
81e3409404d2 Initial revision
claus
parents:
diff changeset
   400
	    autoRepeat ifTrue:[
81e3409404d2 Initial revision
claus
parents:
diff changeset
   401
		Processor addTimedBlock:repeatBlock afterSeconds:initialDelay
81e3409404d2 Initial revision
claus
parents:
diff changeset
   402
	    ].
118
claus
parents: 97
diff changeset
   403
	    isTriggerOnDown ifFalse:[
76
81e3409404d2 Initial revision
claus
parents:
diff changeset
   404
		view showActive.
81e3409404d2 Initial revision
claus
parents:
diff changeset
   405
	    ]
125
claus
parents: 121
diff changeset
   406
	] ifFalse:[
76
81e3409404d2 Initial revision
claus
parents:
diff changeset
   407
	    view redraw
81e3409404d2 Initial revision
claus
parents:
diff changeset
   408
	]
81e3409404d2 Initial revision
claus
parents:
diff changeset
   409
    ]
81e3409404d2 Initial revision
claus
parents:
diff changeset
   410
!
81e3409404d2 Initial revision
claus
parents:
diff changeset
   411
121
claus
parents: 118
diff changeset
   412
pointerLeave:state
125
claus
parents: 121
diff changeset
   413
    "mouse pointer left my view.
claus
parents: 121
diff changeset
   414
     Redraw with normal colors if they differ from enteredColors"
121
claus
parents: 118
diff changeset
   415
claus
parents: 118
diff changeset
   416
    entered := false.
claus
parents: 118
diff changeset
   417
    pressed ifTrue:[
claus
parents: 118
diff changeset
   418
	"
claus
parents: 118
diff changeset
   419
	 leave with mouse-button down;
claus
parents: 118
diff changeset
   420
	 stop autorepeating and/or if I am a button with
claus
parents: 118
diff changeset
   421
	 action on release, show passive
claus
parents: 118
diff changeset
   422
	"
claus
parents: 118
diff changeset
   423
	autoRepeat ifTrue:[
claus
parents: 118
diff changeset
   424
	    Processor removeTimedBlock:repeatBlock
claus
parents: 118
diff changeset
   425
	].
claus
parents: 118
diff changeset
   426
	isTriggerOnDown ifFalse:[
claus
parents: 118
diff changeset
   427
	    view showPassive.
claus
parents: 118
diff changeset
   428
	]
claus
parents: 118
diff changeset
   429
    ] ifFalse:[
133
claus
parents: 132
diff changeset
   430
	enableChannel value ifTrue:[
121
claus
parents: 118
diff changeset
   431
	    view redraw
claus
parents: 118
diff changeset
   432
	]
claus
parents: 118
diff changeset
   433
    ]
claus
parents: 118
diff changeset
   434
!
claus
parents: 118
diff changeset
   435
claus
parents: 118
diff changeset
   436
performAction
146
claus
parents: 145
diff changeset
   437
    |action value|
133
claus
parents: 132
diff changeset
   438
claus
parents: 132
diff changeset
   439
    isToggle ifTrue:[
claus
parents: 132
diff changeset
   440
	value := pressed
claus
parents: 132
diff changeset
   441
    ] ifFalse:[
claus
parents: 132
diff changeset
   442
	value := true
claus
parents: 132
diff changeset
   443
    ].
76
81e3409404d2 Initial revision
claus
parents:
diff changeset
   444
125
claus
parents: 121
diff changeset
   445
    "
145
claus
parents: 133
diff changeset
   446
     ST/X style actionBlock evaluation & channel notification ...
125
claus
parents: 121
diff changeset
   447
    "
76
81e3409404d2 Initial revision
claus
parents:
diff changeset
   448
    pressed ifTrue:[
145
claus
parents: 133
diff changeset
   449
	action := pressActionBlock.
121
claus
parents: 118
diff changeset
   450
    ] ifFalse:[
145
claus
parents: 133
diff changeset
   451
	action := releaseActionBlock.
121
claus
parents: 118
diff changeset
   452
    ].
125
claus
parents: 121
diff changeset
   453
    action notNil ifTrue:[
claus
parents: 121
diff changeset
   454
	active := true.
claus
parents: 121
diff changeset
   455
	action numArgs == 0 ifTrue:[
claus
parents: 121
diff changeset
   456
	    action value
claus
parents: 121
diff changeset
   457
	] ifFalse:[
133
claus
parents: 132
diff changeset
   458
	    action value:value
125
claus
parents: 121
diff changeset
   459
	].
claus
parents: 121
diff changeset
   460
	active := false.
claus
parents: 121
diff changeset
   461
    ].
146
claus
parents: 145
diff changeset
   462
    pressChannel notNil ifTrue:[
claus
parents: 145
diff changeset
   463
	pressChannel value:pressed 
claus
parents: 145
diff changeset
   464
    ].
claus
parents: 145
diff changeset
   465
    releaseChannel notNil ifTrue:[
claus
parents: 145
diff changeset
   466
	releaseChannel value:pressed not
145
claus
parents: 133
diff changeset
   467
    ].
76
81e3409404d2 Initial revision
claus
parents:
diff changeset
   468
125
claus
parents: 121
diff changeset
   469
    "
claus
parents: 121
diff changeset
   470
     ST-80 style model notification ...
claus
parents: 121
diff changeset
   471
    "
121
claus
parents: 118
diff changeset
   472
    (isToggle
claus
parents: 118
diff changeset
   473
    or:[(isTriggerOnDown and:[pressed])
claus
parents: 118
diff changeset
   474
    or:[isTriggerOnDown not and:[pressed not]]]) ifTrue:[
125
claus
parents: 121
diff changeset
   475
	"the ST-80 way of doing things"
claus
parents: 121
diff changeset
   476
	view notNil ifTrue:[
claus
parents: 121
diff changeset
   477
	    active := true.
133
claus
parents: 132
diff changeset
   478
	    view sendChangeMessageWith:value.
125
claus
parents: 121
diff changeset
   479
	    active := false.
claus
parents: 121
diff changeset
   480
	].
121
claus
parents: 118
diff changeset
   481
    ].
76
81e3409404d2 Initial revision
claus
parents:
diff changeset
   482
!
81e3409404d2 Initial revision
claus
parents:
diff changeset
   483
81e3409404d2 Initial revision
claus
parents:
diff changeset
   484
buttonMultiPress:button x:x y:y
81e3409404d2 Initial revision
claus
parents:
diff changeset
   485
    ^ self buttonPress:button x:x y:y
81e3409404d2 Initial revision
claus
parents:
diff changeset
   486
!
81e3409404d2 Initial revision
claus
parents:
diff changeset
   487
81e3409404d2 Initial revision
claus
parents:
diff changeset
   488
keyPress:key x:x y:y
125
claus
parents: 121
diff changeset
   489
    "trigger on Return and space, if I am the focusView of my group
claus
parents: 121
diff changeset
   490
     (i.e. if I got an explicit focus)"
76
81e3409404d2 Initial revision
claus
parents:
diff changeset
   491
125
claus
parents: 121
diff changeset
   492
    (key == #Return or:[key == Character space]) ifTrue:[
claus
parents: 121
diff changeset
   493
	view hasFocus ifTrue:[
76
81e3409404d2 Initial revision
claus
parents:
diff changeset
   494
	    "just simulate a buttonPress/release here."
81e3409404d2 Initial revision
claus
parents:
diff changeset
   495
	    self buttonPress:1 x:0 y:0.
81e3409404d2 Initial revision
claus
parents:
diff changeset
   496
	    self buttonRelease:1 x:0 y:0.
81e3409404d2 Initial revision
claus
parents:
diff changeset
   497
	    ^ self.
81e3409404d2 Initial revision
claus
parents:
diff changeset
   498
	]
81e3409404d2 Initial revision
claus
parents:
diff changeset
   499
    ].
81e3409404d2 Initial revision
claus
parents:
diff changeset
   500
    view keyPress:key x:x y:y
81e3409404d2 Initial revision
claus
parents:
diff changeset
   501
!
81e3409404d2 Initial revision
claus
parents:
diff changeset
   502
121
claus
parents: 118
diff changeset
   503
repeat
claus
parents: 118
diff changeset
   504
    "this is sent from the autorepeat-block, when the button has been pressed long
claus
parents: 118
diff changeset
   505
     enough; it simulates a release-press, by evaluating both release
claus
parents: 118
diff changeset
   506
     and press actions."
76
81e3409404d2 Initial revision
claus
parents:
diff changeset
   507
81e3409404d2 Initial revision
claus
parents:
diff changeset
   508
    pressed ifTrue:[
133
claus
parents: 132
diff changeset
   509
	enableChannel value ifTrue:[
121
claus
parents: 118
diff changeset
   510
	    active ifFalse:[
155
claus
parents: 149
diff changeset
   511
		self performAction.
claus
parents: 149
diff changeset
   512
"/                active := true.
claus
parents: 149
diff changeset
   513
"/                releaseActionBlock notNil ifTrue:[releaseActionBlock value].
claus
parents: 149
diff changeset
   514
"/                pressActionBlock notNil ifTrue:[pressActionBlock value].
claus
parents: 149
diff changeset
   515
"/                active := false.
121
claus
parents: 118
diff changeset
   516
claus
parents: 118
diff changeset
   517
		autoRepeat ifTrue:[
claus
parents: 118
diff changeset
   518
		    Processor addTimedBlock:repeatBlock afterSeconds:repeatDelay
claus
parents: 118
diff changeset
   519
		]
claus
parents: 118
diff changeset
   520
	    ]
76
81e3409404d2 Initial revision
claus
parents:
diff changeset
   521
	]
81e3409404d2 Initial revision
claus
parents:
diff changeset
   522
    ]
133
claus
parents: 132
diff changeset
   523
!
claus
parents: 132
diff changeset
   524
claus
parents: 132
diff changeset
   525
enableStateChange
claus
parents: 132
diff changeset
   526
    "this is sent, whenever the enable value has changed"
claus
parents: 132
diff changeset
   527
162
claus
parents: 160
diff changeset
   528
    view notNil ifTrue:[view enableStateChangeRedraw]
claus
parents: 160
diff changeset
   529
claus
parents: 160
diff changeset
   530
    "Modified: 17.9.1995 / 19:55:52 / claus"
76
81e3409404d2 Initial revision
claus
parents:
diff changeset
   531
! !
121
claus
parents: 118
diff changeset
   532
claus
parents: 118
diff changeset
   533
!ButtonController methodsFor:'initialization'!
claus
parents: 118
diff changeset
   534
claus
parents: 118
diff changeset
   535
initialize
claus
parents: 118
diff changeset
   536
    super initialize.
claus
parents: 118
diff changeset
   537
133
claus
parents: 132
diff changeset
   538
    self enableChannel:(true asValue).
claus
parents: 132
diff changeset
   539
121
claus
parents: 118
diff changeset
   540
    active := false.
claus
parents: 118
diff changeset
   541
    pressed := false.
claus
parents: 118
diff changeset
   542
    entered := false.
claus
parents: 118
diff changeset
   543
    autoRepeat := false.
claus
parents: 118
diff changeset
   544
    initialDelay := self class defaultInitialDelay.
claus
parents: 118
diff changeset
   545
    repeatDelay := self class defaultRepeatDelay.
claus
parents: 118
diff changeset
   546
    isTriggerOnDown := false.
claus
parents: 118
diff changeset
   547
    isToggle := false.
claus
parents: 118
diff changeset
   548
! !