KeyboardForwarder.st
author Claus Gittinger <cg@exept.de>
Mon, 04 Mar 1996 23:31:36 +0100
changeset 490 1d2ed059a063
parent 400 47fa508fd78b
child 598 1a2339e902d4
permissions -rw-r--r--
delegated keyboardMessages get nil as x/y
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
128
9c2378152500 Initial revision
claus
parents:
diff changeset
     1
"
9c2378152500 Initial revision
claus
parents:
diff changeset
     2
 COPYRIGHT (c) 1995 by Claus Gittinger
9c2378152500 Initial revision
claus
parents:
diff changeset
     3
	      All Rights Reserved
9c2378152500 Initial revision
claus
parents:
diff changeset
     4
9c2378152500 Initial revision
claus
parents:
diff changeset
     5
 This software is furnished under a license and may be used
9c2378152500 Initial revision
claus
parents:
diff changeset
     6
 only in accordance with the terms of that license and with the
9c2378152500 Initial revision
claus
parents:
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
9c2378152500 Initial revision
claus
parents:
diff changeset
     8
 be provided or otherwise made available to, or used by, any
9c2378152500 Initial revision
claus
parents:
diff changeset
     9
 other person.  No title to or ownership of the software is
9c2378152500 Initial revision
claus
parents:
diff changeset
    10
 hereby transferred.
9c2378152500 Initial revision
claus
parents:
diff changeset
    11
"
9c2378152500 Initial revision
claus
parents:
diff changeset
    12
9c2378152500 Initial revision
claus
parents:
diff changeset
    13
9c2378152500 Initial revision
claus
parents:
diff changeset
    14
Object subclass:#KeyboardForwarder
400
47fa508fd78b added optional filterBlock
Claus Gittinger <cg@exept.de>
parents: 385
diff changeset
    15
	instanceVariableNames:'sourceView destinationView destination condition filter'
47fa508fd78b added optional filterBlock
Claus Gittinger <cg@exept.de>
parents: 385
diff changeset
    16
	classVariableNames:''
47fa508fd78b added optional filterBlock
Claus Gittinger <cg@exept.de>
parents: 385
diff changeset
    17
	poolDictionaries:''
47fa508fd78b added optional filterBlock
Claus Gittinger <cg@exept.de>
parents: 385
diff changeset
    18
	category:'Interface-Support'
128
9c2378152500 Initial revision
claus
parents:
diff changeset
    19
!
9c2378152500 Initial revision
claus
parents:
diff changeset
    20
9c2378152500 Initial revision
claus
parents:
diff changeset
    21
!KeyboardForwarder class methodsFor:'documentation'!
9c2378152500 Initial revision
claus
parents:
diff changeset
    22
244
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    23
copyright
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    24
"
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    25
 COPYRIGHT (c) 1995 by Claus Gittinger
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    26
	      All Rights Reserved
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    27
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    28
 This software is furnished under a license and may be used
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    29
 only in accordance with the terms of that license and with the
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    30
 inclusion of the above copyright notice.   This software may not
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    31
 be provided or otherwise made available to, or used by, any
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    32
 other person.  No title to or ownership of the software is
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    33
 hereby transferred.
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    34
"
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    35
128
9c2378152500 Initial revision
claus
parents:
diff changeset
    36
!
9c2378152500 Initial revision
claus
parents:
diff changeset
    37
9c2378152500 Initial revision
claus
parents:
diff changeset
    38
documentation
9c2378152500 Initial revision
claus
parents:
diff changeset
    39
"
144
claus
parents: 142
diff changeset
    40
    Instances of this class can be used to forward keyboard
claus
parents: 142
diff changeset
    41
    events to some object or other view (install them via aView delegate:).
claus
parents: 142
diff changeset
    42
    Event delegation allows to add additional keyboard functions to views
claus
parents: 142
diff changeset
    43
    WITHOUT modifying their code or changing controllers.
claus
parents: 142
diff changeset
    44
    Also, it allows to catch certain individual keys to ignore them or
claus
parents: 142
diff changeset
    45
    perform different functions.
claus
parents: 142
diff changeset
    46
128
9c2378152500 Initial revision
claus
parents:
diff changeset
    47
    Notice, that delegates dont have to be instances of
9c2378152500 Initial revision
claus
parents:
diff changeset
    48
    myself; any object with a protocol similar to mine can be used as
9c2378152500 Initial revision
claus
parents:
diff changeset
    49
    a delegate. 
142
claus
parents: 140
diff changeset
    50
    (i.e. any object that responds to 
claus
parents: 140
diff changeset
    51
     handlesKeyPress:view: / keyPress:x:y:view: / delegatesTo: etc.)
139
claus
parents: 134
diff changeset
    52
claus
parents: 134
diff changeset
    53
    However, I provide the most common functions required for conditional
claus
parents: 134
diff changeset
    54
    event delegation and instances of myself are for example used to forward 
claus
parents: 134
diff changeset
    55
    events from elements of some dialogBoxes to the enterfield/fieldGroup - 
144
claus
parents: 142
diff changeset
    56
    (which allows keyboard input to be forwarded to the active text-field even 
claus
parents: 142
diff changeset
    57
     while the mouse pointer is somewhere else)
139
claus
parents: 134
diff changeset
    58
claus
parents: 134
diff changeset
    59
    Another application of delegation is to catch keyboard input to some standard
claus
parents: 134
diff changeset
    60
    widget, optionally processing and resending the key-event.
128
9c2378152500 Initial revision
claus
parents:
diff changeset
    61
144
claus
parents: 142
diff changeset
    62
    I can either forward the key event to another view, or to some general
claus
parents: 142
diff changeset
    63
    object - the difference is that views are sent a #keyXXX:x:y: message,
claus
parents: 142
diff changeset
    64
    while general destinations get a #keyXXX:x:y:view: message, with the original
claus
parents: 142
diff changeset
    65
    view (the one in which the event occurred) as additional argument.
claus
parents: 142
diff changeset
    66
128
9c2378152500 Initial revision
claus
parents:
diff changeset
    67
    Instance Variables:
139
claus
parents: 134
diff changeset
    68
128
9c2378152500 Initial revision
claus
parents:
diff changeset
    69
	destinationView         <View>          the view which shall receive
9c2378152500 Initial revision
claus
parents:
diff changeset
    70
						the forwarded keyboard events.
134
claus
parents: 128
diff changeset
    71
139
claus
parents: 134
diff changeset
    72
	destination             <Object>        the object which shall receive
claus
parents: 134
diff changeset
    73
						the forwarded keyboard events.
claus
parents: 134
diff changeset
    74
134
claus
parents: 128
diff changeset
    75
	sourceView              <ViewOrNil>     if non-nil, only events from this
claus
parents: 128
diff changeset
    76
						view are forwarded.
claus
parents: 128
diff changeset
    77
						(currently nowhere used)
claus
parents: 128
diff changeset
    78
claus
parents: 128
diff changeset
    79
	condition               <Symbol>        an additional condition for forwarding
claus
parents: 128
diff changeset
    80
						currently only #noFocus is implemented.
claus
parents: 128
diff changeset
    81
						The #noFocus condition will only forward
claus
parents: 128
diff changeset
    82
						events if no explicit focus has been
claus
parents: 128
diff changeset
    83
						set in the windowGroup.
144
claus
parents: 142
diff changeset
    84
claus
parents: 142
diff changeset
    85
				<Block>         condition block - event is forwarded,
claus
parents: 142
diff changeset
    86
						if it evaluates to true.
claus
parents: 142
diff changeset
    87
						The block gets 3 arguments:
claus
parents: 142
diff changeset
    88
						    eventType   #keyPress or #keyRelease
claus
parents: 142
diff changeset
    89
						    key         the key
claus
parents: 142
diff changeset
    90
						    view        the originating view
claus
parents: 142
diff changeset
    91
claus
parents: 142
diff changeset
    92
    For more info on event handling/forwarding, see the documentation in
claus
parents: 142
diff changeset
    93
    WindowSensor, WindowGroup and especially in WindowEvent.
claus
parents: 142
diff changeset
    94
"
claus
parents: 142
diff changeset
    95
!
claus
parents: 142
diff changeset
    96
claus
parents: 142
diff changeset
    97
examples
claus
parents: 142
diff changeset
    98
"
claus
parents: 142
diff changeset
    99
    catch an enterfields input:
claus
parents: 142
diff changeset
   100
claus
parents: 142
diff changeset
   101
	|top field forwarder catcher|
claus
parents: 142
diff changeset
   102
claus
parents: 142
diff changeset
   103
	catcher := Plug new.
claus
parents: 142
diff changeset
   104
	catcher respondTo:#keyPress:x:y:view:
claus
parents: 142
diff changeset
   105
		    with:[:key :x :y :view | Transcript showCr:'cought keyPress: ' , key printString.].
claus
parents: 142
diff changeset
   106
	catcher respondTo:#keyRelease:x:y:view:
claus
parents: 142
diff changeset
   107
		    with:[:key :x :y :view | Transcript showCr:'cought keyRelease: ' , key printString.].
claus
parents: 142
diff changeset
   108
claus
parents: 142
diff changeset
   109
	top := StandardSystemView new.
claus
parents: 142
diff changeset
   110
	top extent:200@200.
claus
parents: 142
diff changeset
   111
claus
parents: 142
diff changeset
   112
	field := EditField in:top.
claus
parents: 142
diff changeset
   113
	field origin:0.0@0.0; width:1.0.
claus
parents: 142
diff changeset
   114
claus
parents: 142
diff changeset
   115
	forwarder := KeyboardForwarder to:catcher. 
claus
parents: 142
diff changeset
   116
	field delegate:forwarder.
claus
parents: 142
diff changeset
   117
claus
parents: 142
diff changeset
   118
	top open
claus
parents: 142
diff changeset
   119
claus
parents: 142
diff changeset
   120
claus
parents: 142
diff changeset
   121
    catch an enterfields return-key only:
claus
parents: 142
diff changeset
   122
claus
parents: 142
diff changeset
   123
	|top field forwarder catcher|
claus
parents: 142
diff changeset
   124
claus
parents: 142
diff changeset
   125
	catcher := Plug new.
claus
parents: 142
diff changeset
   126
	catcher respondTo:#keyPress:x:y:view:
claus
parents: 142
diff changeset
   127
		    with:[:key :x :y :view | Transcript showCr:'cought return'].
claus
parents: 142
diff changeset
   128
claus
parents: 142
diff changeset
   129
	top := StandardSystemView new.
claus
parents: 142
diff changeset
   130
	top extent:200@200.
claus
parents: 142
diff changeset
   131
claus
parents: 142
diff changeset
   132
	field := EditField in:top.
claus
parents: 142
diff changeset
   133
	field origin:0.0@0.0; width:1.0.
claus
parents: 142
diff changeset
   134
claus
parents: 142
diff changeset
   135
	forwarder := KeyboardForwarder 
claus
parents: 142
diff changeset
   136
			to:catcher 
claus
parents: 142
diff changeset
   137
			condition:[:type :key :view | (type == #keyPress) & (key == #Return)].
claus
parents: 142
diff changeset
   138
	field delegate:forwarder.
claus
parents: 142
diff changeset
   139
claus
parents: 142
diff changeset
   140
	top open
claus
parents: 142
diff changeset
   141
claus
parents: 142
diff changeset
   142
claus
parents: 142
diff changeset
   143
    catch all of an enterfields input and ignore it:
claus
parents: 142
diff changeset
   144
claus
parents: 142
diff changeset
   145
	|top field forwarder|
claus
parents: 142
diff changeset
   146
claus
parents: 142
diff changeset
   147
	top := StandardSystemView new.
claus
parents: 142
diff changeset
   148
	top extent:200@200.
claus
parents: 142
diff changeset
   149
claus
parents: 142
diff changeset
   150
	field := EditField in:top.
claus
parents: 142
diff changeset
   151
	field origin:0.0@0.0; width:1.0.
claus
parents: 142
diff changeset
   152
claus
parents: 142
diff changeset
   153
	forwarder := KeyboardForwarder to:nil. 
claus
parents: 142
diff changeset
   154
	field delegate:forwarder.
claus
parents: 142
diff changeset
   155
claus
parents: 142
diff changeset
   156
	top open
128
9c2378152500 Initial revision
claus
parents:
diff changeset
   157
"
9c2378152500 Initial revision
claus
parents:
diff changeset
   158
! !
9c2378152500 Initial revision
claus
parents:
diff changeset
   159
9c2378152500 Initial revision
claus
parents:
diff changeset
   160
!KeyboardForwarder class methodsFor:'instance creation'!
9c2378152500 Initial revision
claus
parents:
diff changeset
   161
139
claus
parents: 134
diff changeset
   162
from:sourceView to:destination
claus
parents: 134
diff changeset
   163
    "create and return a new KeyboardForwarder to redirect key events
claus
parents: 134
diff changeset
   164
     for sourceView to destination. Events from other than the sourceView
claus
parents: 134
diff changeset
   165
     will not be forwarded. The forwarded event will be reported including
claus
parents: 134
diff changeset
   166
     the original view as argument (i.e. as #keyPress:x:y:view:). 
claus
parents: 134
diff changeset
   167
     Use this, if the destination is not a view."
claus
parents: 134
diff changeset
   168
claus
parents: 134
diff changeset
   169
    ^ self new sourceView:sourceView; destination:destination
claus
parents: 134
diff changeset
   170
!
claus
parents: 134
diff changeset
   171
244
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   172
from:sourceView toView:destinationView
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   173
    "create and return a new KeyboardForwarder to redirect key events
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   174
     for sourceView to destinationView. Events from other than the sourceView
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   175
     will not be forwarded. The forwarded event will be reported excluding
139
claus
parents: 134
diff changeset
   176
     the original view as argument (i.e. as #keyPress:x:y:). 
claus
parents: 134
diff changeset
   177
     Use this, if the destination is a view."
claus
parents: 134
diff changeset
   178
244
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   179
    ^ self new sourceView:sourceView; destinationView:destinationView
134
claus
parents: 128
diff changeset
   180
!
claus
parents: 128
diff changeset
   181
139
claus
parents: 134
diff changeset
   182
to:destination
claus
parents: 134
diff changeset
   183
    "create and return a new KeyboardForwarder to redirect any key event
claus
parents: 134
diff changeset
   184
     to destination (Independent of the view in which the event originally
claus
parents: 134
diff changeset
   185
     occurred). The forwarded event will be reported including
claus
parents: 134
diff changeset
   186
     the original view as argument (i.e. as #keyPress:x:y:view:). 
claus
parents: 134
diff changeset
   187
     Use this, if the destination is not a view."
claus
parents: 134
diff changeset
   188
400
47fa508fd78b added optional filterBlock
Claus Gittinger <cg@exept.de>
parents: 385
diff changeset
   189
    ^ self to:destination condition:nil filter:nil 
139
claus
parents: 134
diff changeset
   190
!
claus
parents: 134
diff changeset
   191
244
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   192
to:destination condition:aCondition
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   193
    "create and return a new KeyboardForwarder to redirect any key event
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   194
     to destinationView (Independent of the view in which the event originally
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   195
     occurred) but only, if some condition as specified by aCondition
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   196
     is met. The forwarded event will be reported including
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   197
     the original view as argument (i.e. as #keyPress:x:y:view:). 
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   198
     Use this, if the destination is not a view."
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   199
400
47fa508fd78b added optional filterBlock
Claus Gittinger <cg@exept.de>
parents: 385
diff changeset
   200
    ^ self to:destination condition:aCondition filter:nil 
47fa508fd78b added optional filterBlock
Claus Gittinger <cg@exept.de>
parents: 385
diff changeset
   201
!
47fa508fd78b added optional filterBlock
Claus Gittinger <cg@exept.de>
parents: 385
diff changeset
   202
47fa508fd78b added optional filterBlock
Claus Gittinger <cg@exept.de>
parents: 385
diff changeset
   203
to:destination condition:aCondition filter:aFilterBlock
47fa508fd78b added optional filterBlock
Claus Gittinger <cg@exept.de>
parents: 385
diff changeset
   204
    "create and return a new KeyboardForwarder to redirect any key event
47fa508fd78b added optional filterBlock
Claus Gittinger <cg@exept.de>
parents: 385
diff changeset
   205
     to destinationView (Independent of the view in which the event originally
47fa508fd78b added optional filterBlock
Claus Gittinger <cg@exept.de>
parents: 385
diff changeset
   206
     occurred) but only, if some condition as specified by aCondition
47fa508fd78b added optional filterBlock
Claus Gittinger <cg@exept.de>
parents: 385
diff changeset
   207
     is met and aFilterBlock returns true for that key.
47fa508fd78b added optional filterBlock
Claus Gittinger <cg@exept.de>
parents: 385
diff changeset
   208
     The forwarded event will be reported including
47fa508fd78b added optional filterBlock
Claus Gittinger <cg@exept.de>
parents: 385
diff changeset
   209
     the original view as argument (i.e. as #keyPress:x:y:view:). 
47fa508fd78b added optional filterBlock
Claus Gittinger <cg@exept.de>
parents: 385
diff changeset
   210
     Use this, if the destination is not a view."
47fa508fd78b added optional filterBlock
Claus Gittinger <cg@exept.de>
parents: 385
diff changeset
   211
47fa508fd78b added optional filterBlock
Claus Gittinger <cg@exept.de>
parents: 385
diff changeset
   212
    ^ self new destination:destination; condition:aCondition; filter:aFilterBlock
244
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   213
!
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   214
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   215
toView:destinationView
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   216
    "create and return a new KeyboardForwarder to redirect any key event
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   217
     to destinationView (Independent of the view in which the event originally
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   218
     occurred). The forwarded event will be reported excluding
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   219
     the original view as argument (i.e. as #keyPress:x:y:). 
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   220
     Use this, if the destination is a view."
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   221
400
47fa508fd78b added optional filterBlock
Claus Gittinger <cg@exept.de>
parents: 385
diff changeset
   222
    ^ self toView:destinationView condition:nil filter:nil 
244
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   223
!
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   224
144
claus
parents: 142
diff changeset
   225
toView:destinationView condition:aCondition
139
claus
parents: 134
diff changeset
   226
    "create and return a new KeyboardForwarder to redirect any key event
claus
parents: 134
diff changeset
   227
     to destinationView (Independent of the view in which the event originally
144
claus
parents: 142
diff changeset
   228
     occurred) but only, if some condition as specified by aCondition
139
claus
parents: 134
diff changeset
   229
     is met. The forwarded event will be reported excluding
claus
parents: 134
diff changeset
   230
     the original view as argument (i.e. as #keyPress:x:y:). 
claus
parents: 134
diff changeset
   231
     Use this, if the destination is a view."
claus
parents: 134
diff changeset
   232
400
47fa508fd78b added optional filterBlock
Claus Gittinger <cg@exept.de>
parents: 385
diff changeset
   233
    ^ self toView:destinationView condition:aCondition filter:nil 
47fa508fd78b added optional filterBlock
Claus Gittinger <cg@exept.de>
parents: 385
diff changeset
   234
!
47fa508fd78b added optional filterBlock
Claus Gittinger <cg@exept.de>
parents: 385
diff changeset
   235
47fa508fd78b added optional filterBlock
Claus Gittinger <cg@exept.de>
parents: 385
diff changeset
   236
toView:destinationView condition:aCondition filter:aFilterBlock
47fa508fd78b added optional filterBlock
Claus Gittinger <cg@exept.de>
parents: 385
diff changeset
   237
    "create and return a new KeyboardForwarder to redirect any key event
47fa508fd78b added optional filterBlock
Claus Gittinger <cg@exept.de>
parents: 385
diff changeset
   238
     to destinationView (Independent of the view in which the event originally
47fa508fd78b added optional filterBlock
Claus Gittinger <cg@exept.de>
parents: 385
diff changeset
   239
     occurred) but only, if some condition as specified by aCondition
47fa508fd78b added optional filterBlock
Claus Gittinger <cg@exept.de>
parents: 385
diff changeset
   240
     is met and aFilterBlock returns true for that key.
47fa508fd78b added optional filterBlock
Claus Gittinger <cg@exept.de>
parents: 385
diff changeset
   241
     The forwarded event will be reported excluding
47fa508fd78b added optional filterBlock
Claus Gittinger <cg@exept.de>
parents: 385
diff changeset
   242
     the original view as argument (i.e. as #keyPress:x:y:). 
47fa508fd78b added optional filterBlock
Claus Gittinger <cg@exept.de>
parents: 385
diff changeset
   243
     Use this, if the destination is a view."
47fa508fd78b added optional filterBlock
Claus Gittinger <cg@exept.de>
parents: 385
diff changeset
   244
47fa508fd78b added optional filterBlock
Claus Gittinger <cg@exept.de>
parents: 385
diff changeset
   245
    ^ self new destinationView:destinationView; condition:aCondition; filter:aFilterBlock
128
9c2378152500 Initial revision
claus
parents:
diff changeset
   246
! !
9c2378152500 Initial revision
claus
parents:
diff changeset
   247
144
claus
parents: 142
diff changeset
   248
!KeyboardForwarder methodsFor:'accessing'!
128
9c2378152500 Initial revision
claus
parents:
diff changeset
   249
134
claus
parents: 128
diff changeset
   250
condition:aCondition
144
claus
parents: 142
diff changeset
   251
    "set the condition - typically a block"
claus
parents: 142
diff changeset
   252
134
claus
parents: 128
diff changeset
   253
    condition := aCondition
claus
parents: 128
diff changeset
   254
!
claus
parents: 128
diff changeset
   255
244
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   256
destination
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   257
    "return the destination"
144
claus
parents: 142
diff changeset
   258
244
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   259
    ^ destination
139
claus
parents: 134
diff changeset
   260
!
claus
parents: 134
diff changeset
   261
claus
parents: 134
diff changeset
   262
destination:anObject 
144
claus
parents: 142
diff changeset
   263
    "set the destination 
claus
parents: 142
diff changeset
   264
     - that one will get the event with an additional view arg."
claus
parents: 142
diff changeset
   265
139
claus
parents: 134
diff changeset
   266
    destination := anObject
claus
parents: 134
diff changeset
   267
!
claus
parents: 134
diff changeset
   268
244
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   269
destinationView
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   270
    "return the destination view"
144
claus
parents: 142
diff changeset
   271
244
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   272
    ^ destinationView
139
claus
parents: 134
diff changeset
   273
!
claus
parents: 134
diff changeset
   274
244
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   275
destinationView:aView
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   276
    "set the destination view"
144
claus
parents: 142
diff changeset
   277
244
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   278
    destinationView := aView
128
9c2378152500 Initial revision
claus
parents:
diff changeset
   279
!
9c2378152500 Initial revision
claus
parents:
diff changeset
   280
400
47fa508fd78b added optional filterBlock
Claus Gittinger <cg@exept.de>
parents: 385
diff changeset
   281
filter:aOneArgBlock
47fa508fd78b added optional filterBlock
Claus Gittinger <cg@exept.de>
parents: 385
diff changeset
   282
    "set the filter - if non-nil, only keys for which it returns true are forwarded"
47fa508fd78b added optional filterBlock
Claus Gittinger <cg@exept.de>
parents: 385
diff changeset
   283
47fa508fd78b added optional filterBlock
Claus Gittinger <cg@exept.de>
parents: 385
diff changeset
   284
     filter := aOneArgBlock
47fa508fd78b added optional filterBlock
Claus Gittinger <cg@exept.de>
parents: 385
diff changeset
   285
47fa508fd78b added optional filterBlock
Claus Gittinger <cg@exept.de>
parents: 385
diff changeset
   286
    "Created: 4.2.1996 / 20:35:15 / cg"
47fa508fd78b added optional filterBlock
Claus Gittinger <cg@exept.de>
parents: 385
diff changeset
   287
!
47fa508fd78b added optional filterBlock
Claus Gittinger <cg@exept.de>
parents: 385
diff changeset
   288
128
9c2378152500 Initial revision
claus
parents:
diff changeset
   289
sourceView
144
claus
parents: 142
diff changeset
   290
    "get the sourceView - if nonNil, only events from this view will be forwarded"
claus
parents: 142
diff changeset
   291
128
9c2378152500 Initial revision
claus
parents:
diff changeset
   292
    ^ sourceView
142
claus
parents: 140
diff changeset
   293
!
claus
parents: 140
diff changeset
   294
244
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   295
sourceView:aView
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   296
    "set the sourceView - if nonNil, only events from this view will be forwarded"
128
9c2378152500 Initial revision
claus
parents:
diff changeset
   297
244
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   298
    sourceView := aView
128
9c2378152500 Initial revision
claus
parents:
diff changeset
   299
! !
9c2378152500 Initial revision
claus
parents:
diff changeset
   300
9c2378152500 Initial revision
claus
parents:
diff changeset
   301
!KeyboardForwarder methodsFor:'event forwarding'!
9c2378152500 Initial revision
claus
parents:
diff changeset
   302
9c2378152500 Initial revision
claus
parents:
diff changeset
   303
keyPress:key x:x y:y view:aView
139
claus
parents: 134
diff changeset
   304
    "handle a delegated event - this is sent by the sensor to actually
claus
parents: 134
diff changeset
   305
     forward the event (i.e. after I returned true on handlesKeyPress:.
claus
parents: 134
diff changeset
   306
     Take care of cyclic delegation (via a kludge-test for negative coordinate)."
claus
parents: 134
diff changeset
   307
490
1d2ed059a063 delegated keyboardMessages get nil as x/y
Claus Gittinger <cg@exept.de>
parents: 400
diff changeset
   308
    x isNil ifTrue:[
400
47fa508fd78b added optional filterBlock
Claus Gittinger <cg@exept.de>
parents: 385
diff changeset
   309
        "
47fa508fd78b added optional filterBlock
Claus Gittinger <cg@exept.de>
parents: 385
diff changeset
   310
         already delegated ... ignore
47fa508fd78b added optional filterBlock
Claus Gittinger <cg@exept.de>
parents: 385
diff changeset
   311
        "
47fa508fd78b added optional filterBlock
Claus Gittinger <cg@exept.de>
parents: 385
diff changeset
   312
        ^ self
47fa508fd78b added optional filterBlock
Claus Gittinger <cg@exept.de>
parents: 385
diff changeset
   313
    ].
47fa508fd78b added optional filterBlock
Claus Gittinger <cg@exept.de>
parents: 385
diff changeset
   314
47fa508fd78b added optional filterBlock
Claus Gittinger <cg@exept.de>
parents: 385
diff changeset
   315
    filter notNil ifTrue:[
47fa508fd78b added optional filterBlock
Claus Gittinger <cg@exept.de>
parents: 385
diff changeset
   316
        (filter value:key) ifFalse:[^ self].
128
9c2378152500 Initial revision
claus
parents:
diff changeset
   317
    ].
9c2378152500 Initial revision
claus
parents:
diff changeset
   318
139
claus
parents: 134
diff changeset
   319
    destination notNil ifTrue:[
490
1d2ed059a063 delegated keyboardMessages get nil as x/y
Claus Gittinger <cg@exept.de>
parents: 400
diff changeset
   320
        destination keyPress:key x:nil y:nil view:aView.
139
claus
parents: 134
diff changeset
   321
    ] ifFalse:[
400
47fa508fd78b added optional filterBlock
Claus Gittinger <cg@exept.de>
parents: 385
diff changeset
   322
        destinationView notNil ifTrue:[
47fa508fd78b added optional filterBlock
Claus Gittinger <cg@exept.de>
parents: 385
diff changeset
   323
            WindowEvent
47fa508fd78b added optional filterBlock
Claus Gittinger <cg@exept.de>
parents: 385
diff changeset
   324
                sendEvent:#keyPress:x:y:
490
1d2ed059a063 delegated keyboardMessages get nil as x/y
Claus Gittinger <cg@exept.de>
parents: 400
diff changeset
   325
                arguments:(Array with:key with:nil with:nil)
400
47fa508fd78b added optional filterBlock
Claus Gittinger <cg@exept.de>
parents: 385
diff changeset
   326
                view:destinationView
47fa508fd78b added optional filterBlock
Claus Gittinger <cg@exept.de>
parents: 385
diff changeset
   327
        ]
139
claus
parents: 134
diff changeset
   328
    ]
400
47fa508fd78b added optional filterBlock
Claus Gittinger <cg@exept.de>
parents: 385
diff changeset
   329
490
1d2ed059a063 delegated keyboardMessages get nil as x/y
Claus Gittinger <cg@exept.de>
parents: 400
diff changeset
   330
    "Modified: 4.3.1996 / 22:18:37 / cg"
128
9c2378152500 Initial revision
claus
parents:
diff changeset
   331
!
9c2378152500 Initial revision
claus
parents:
diff changeset
   332
9c2378152500 Initial revision
claus
parents:
diff changeset
   333
keyRelease:key x:x y:y view:aView
139
claus
parents: 134
diff changeset
   334
    "handle a delegated event - this is sent by the sensor to actually
claus
parents: 134
diff changeset
   335
     forward the event (i.e. after I returned true on handlesKeyRelease:.
claus
parents: 134
diff changeset
   336
     Take care of cyclic delegation (via a kludge-test for negative coordinate)."
claus
parents: 134
diff changeset
   337
128
9c2378152500 Initial revision
claus
parents:
diff changeset
   338
    x < 0 ifTrue:[
400
47fa508fd78b added optional filterBlock
Claus Gittinger <cg@exept.de>
parents: 385
diff changeset
   339
        "
47fa508fd78b added optional filterBlock
Claus Gittinger <cg@exept.de>
parents: 385
diff changeset
   340
         already delegated ... ignore
47fa508fd78b added optional filterBlock
Claus Gittinger <cg@exept.de>
parents: 385
diff changeset
   341
        "
47fa508fd78b added optional filterBlock
Claus Gittinger <cg@exept.de>
parents: 385
diff changeset
   342
        ^ self
47fa508fd78b added optional filterBlock
Claus Gittinger <cg@exept.de>
parents: 385
diff changeset
   343
    ].
47fa508fd78b added optional filterBlock
Claus Gittinger <cg@exept.de>
parents: 385
diff changeset
   344
47fa508fd78b added optional filterBlock
Claus Gittinger <cg@exept.de>
parents: 385
diff changeset
   345
    filter notNil ifTrue:[
47fa508fd78b added optional filterBlock
Claus Gittinger <cg@exept.de>
parents: 385
diff changeset
   346
        (filter value:key) ifFalse:[^ self].
128
9c2378152500 Initial revision
claus
parents:
diff changeset
   347
    ].
9c2378152500 Initial revision
claus
parents:
diff changeset
   348
139
claus
parents: 134
diff changeset
   349
    destination notNil ifTrue:[
400
47fa508fd78b added optional filterBlock
Claus Gittinger <cg@exept.de>
parents: 385
diff changeset
   350
        destination keyRelease:key x:-1 y:-1 view:aView
139
claus
parents: 134
diff changeset
   351
    ] ifFalse:[
400
47fa508fd78b added optional filterBlock
Claus Gittinger <cg@exept.de>
parents: 385
diff changeset
   352
        destinationView notNil ifTrue:[
47fa508fd78b added optional filterBlock
Claus Gittinger <cg@exept.de>
parents: 385
diff changeset
   353
            WindowEvent
47fa508fd78b added optional filterBlock
Claus Gittinger <cg@exept.de>
parents: 385
diff changeset
   354
                sendEvent:#keyRelease:x:y:
47fa508fd78b added optional filterBlock
Claus Gittinger <cg@exept.de>
parents: 385
diff changeset
   355
                arguments:(Array with:key with:-1 with:-1)
47fa508fd78b added optional filterBlock
Claus Gittinger <cg@exept.de>
parents: 385
diff changeset
   356
                view:destinationView
47fa508fd78b added optional filterBlock
Claus Gittinger <cg@exept.de>
parents: 385
diff changeset
   357
        ]
139
claus
parents: 134
diff changeset
   358
    ]
400
47fa508fd78b added optional filterBlock
Claus Gittinger <cg@exept.de>
parents: 385
diff changeset
   359
47fa508fd78b added optional filterBlock
Claus Gittinger <cg@exept.de>
parents: 385
diff changeset
   360
    "Modified: 4.2.1996 / 20:35:55 / cg"
128
9c2378152500 Initial revision
claus
parents:
diff changeset
   361
! !
244
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   362
385
15fd1c806d2a pass info if focus change was explicit (i.e. Tab-key) or by window manager.
Claus Gittinger <cg@exept.de>
parents: 251
diff changeset
   363
!KeyboardForwarder methodsFor:'focus forwarding'!
15fd1c806d2a pass info if focus change was explicit (i.e. Tab-key) or by window manager.
Claus Gittinger <cg@exept.de>
parents: 251
diff changeset
   364
15fd1c806d2a pass info if focus change was explicit (i.e. Tab-key) or by window manager.
Claus Gittinger <cg@exept.de>
parents: 251
diff changeset
   365
showFocus:explicit
15fd1c806d2a pass info if focus change was explicit (i.e. Tab-key) or by window manager.
Claus Gittinger <cg@exept.de>
parents: 251
diff changeset
   366
    destinationView notNil ifTrue:[destinationView showFocus:explicit]
15fd1c806d2a pass info if focus change was explicit (i.e. Tab-key) or by window manager.
Claus Gittinger <cg@exept.de>
parents: 251
diff changeset
   367
15fd1c806d2a pass info if focus change was explicit (i.e. Tab-key) or by window manager.
Claus Gittinger <cg@exept.de>
parents: 251
diff changeset
   368
    "Created: 27.1.1996 / 13:06:53 / cg"
15fd1c806d2a pass info if focus change was explicit (i.e. Tab-key) or by window manager.
Claus Gittinger <cg@exept.de>
parents: 251
diff changeset
   369
!
15fd1c806d2a pass info if focus change was explicit (i.e. Tab-key) or by window manager.
Claus Gittinger <cg@exept.de>
parents: 251
diff changeset
   370
15fd1c806d2a pass info if focus change was explicit (i.e. Tab-key) or by window manager.
Claus Gittinger <cg@exept.de>
parents: 251
diff changeset
   371
showNoFocus:explicit
15fd1c806d2a pass info if focus change was explicit (i.e. Tab-key) or by window manager.
Claus Gittinger <cg@exept.de>
parents: 251
diff changeset
   372
    destinationView notNil ifTrue:[destinationView showNoFocus:explicit]
15fd1c806d2a pass info if focus change was explicit (i.e. Tab-key) or by window manager.
Claus Gittinger <cg@exept.de>
parents: 251
diff changeset
   373
15fd1c806d2a pass info if focus change was explicit (i.e. Tab-key) or by window manager.
Claus Gittinger <cg@exept.de>
parents: 251
diff changeset
   374
    "Created: 27.1.1996 / 13:07:52 / cg"
15fd1c806d2a pass info if focus change was explicit (i.e. Tab-key) or by window manager.
Claus Gittinger <cg@exept.de>
parents: 251
diff changeset
   375
! !
15fd1c806d2a pass info if focus change was explicit (i.e. Tab-key) or by window manager.
Claus Gittinger <cg@exept.de>
parents: 251
diff changeset
   376
244
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   377
!KeyboardForwarder methodsFor:'queries'!
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   378
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   379
checkCondition:type key:key view:aView
400
47fa508fd78b added optional filterBlock
Claus Gittinger <cg@exept.de>
parents: 385
diff changeset
   380
    filter notNil ifTrue:[
47fa508fd78b added optional filterBlock
Claus Gittinger <cg@exept.de>
parents: 385
diff changeset
   381
        (filter value:key) ifFalse:[^ false].
47fa508fd78b added optional filterBlock
Claus Gittinger <cg@exept.de>
parents: 385
diff changeset
   382
    ].
47fa508fd78b added optional filterBlock
Claus Gittinger <cg@exept.de>
parents: 385
diff changeset
   383
244
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   384
    condition notNil ifTrue:[
400
47fa508fd78b added optional filterBlock
Claus Gittinger <cg@exept.de>
parents: 385
diff changeset
   385
        condition == #noFocus ifTrue:[
47fa508fd78b added optional filterBlock
Claus Gittinger <cg@exept.de>
parents: 385
diff changeset
   386
            aView windowGroup focusView notNil ifTrue:[^ false]
47fa508fd78b added optional filterBlock
Claus Gittinger <cg@exept.de>
parents: 385
diff changeset
   387
        ].
47fa508fd78b added optional filterBlock
Claus Gittinger <cg@exept.de>
parents: 385
diff changeset
   388
        condition isBlock ifTrue:[
47fa508fd78b added optional filterBlock
Claus Gittinger <cg@exept.de>
parents: 385
diff changeset
   389
            (condition value:type value:key value:aView) ifFalse:[^ false]
47fa508fd78b added optional filterBlock
Claus Gittinger <cg@exept.de>
parents: 385
diff changeset
   390
        ]
244
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   391
    ].
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   392
    sourceView notNil ifTrue:[
400
47fa508fd78b added optional filterBlock
Claus Gittinger <cg@exept.de>
parents: 385
diff changeset
   393
        ^ aView == sourceView
244
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   394
    ].
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   395
    ^ true
400
47fa508fd78b added optional filterBlock
Claus Gittinger <cg@exept.de>
parents: 385
diff changeset
   396
47fa508fd78b added optional filterBlock
Claus Gittinger <cg@exept.de>
parents: 385
diff changeset
   397
    "Modified: 4.2.1996 / 20:36:16 / cg"
244
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   398
!
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   399
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   400
delegatesTo:someone
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   401
    "return true, if I delegate events to someone"
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   402
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   403
    ^ destination == someone or:[destinationView == someone]
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   404
!
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   405
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   406
handlesKeyPress:key inView:aView
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   407
    "this is the query from the sensor to ask me if I would like to
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   408
     get a keyPress event for key from aView. Return true, if I want so,
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   409
     false otherwise."
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   410
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   411
    ^ self checkCondition:#keyPress key:key view:aView
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   412
!
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   413
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   414
handlesKeyRelease:key inView:aView
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   415
    "this is the query from the sensor to ask me if I would like to
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   416
     get a keyRelease event for key from aView. Return true, if I want so,
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   417
     false otherwise."
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   418
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   419
    ^ self checkCondition:#keyRelease key:key view:aView
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   420
! !
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   421
251
915de9a65169 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 244
diff changeset
   422
!KeyboardForwarder class methodsFor:'documentation'!
915de9a65169 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 244
diff changeset
   423
915de9a65169 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 244
diff changeset
   424
version
490
1d2ed059a063 delegated keyboardMessages get nil as x/y
Claus Gittinger <cg@exept.de>
parents: 400
diff changeset
   425
    ^ '$Header: /cvs/stx/stx/libview/KeyboardForwarder.st,v 1.12 1996-03-04 22:31:36 cg Exp $'
251
915de9a65169 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 244
diff changeset
   426
! !