KeyboardForwarder.st
author Claus Gittinger <cg@exept.de>
Thu, 23 Nov 1995 18:45:33 +0100
changeset 251 915de9a65169
parent 244 83218faf792c
child 385 15fd1c806d2a
permissions -rw-r--r--
checkin from browser
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
139
claus
parents: 134
diff changeset
    15
	 instanceVariableNames:'sourceView destinationView destination condition'
128
9c2378152500 Initial revision
claus
parents:
diff changeset
    16
	 classVariableNames:''
9c2378152500 Initial revision
claus
parents:
diff changeset
    17
	 poolDictionaries:''
9c2378152500 Initial revision
claus
parents:
diff changeset
    18
	 category:'Interface-Support'
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
claus
parents: 134
diff changeset
   189
    ^ self new destination:destination
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
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   200
    ^ self new destination:destination; condition:aCondition
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   201
!
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   202
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   203
toView:destinationView
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   204
    "create and return a new KeyboardForwarder to redirect any key event
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   205
     to destinationView (Independent of the view in which the event originally
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   206
     occurred). The forwarded event will be reported excluding
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   207
     the original view as argument (i.e. as #keyPress:x:y:). 
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   208
     Use this, if the destination is a view."
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   209
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   210
    ^ self new destinationView:destinationView
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   211
!
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   212
144
claus
parents: 142
diff changeset
   213
toView:destinationView condition:aCondition
139
claus
parents: 134
diff changeset
   214
    "create and return a new KeyboardForwarder to redirect any key event
claus
parents: 134
diff changeset
   215
     to destinationView (Independent of the view in which the event originally
144
claus
parents: 142
diff changeset
   216
     occurred) but only, if some condition as specified by aCondition
139
claus
parents: 134
diff changeset
   217
     is met. The forwarded event will be reported excluding
claus
parents: 134
diff changeset
   218
     the original view as argument (i.e. as #keyPress:x:y:). 
claus
parents: 134
diff changeset
   219
     Use this, if the destination is a view."
claus
parents: 134
diff changeset
   220
144
claus
parents: 142
diff changeset
   221
    ^ self new destinationView:destinationView; condition:aCondition
128
9c2378152500 Initial revision
claus
parents:
diff changeset
   222
! !
9c2378152500 Initial revision
claus
parents:
diff changeset
   223
144
claus
parents: 142
diff changeset
   224
!KeyboardForwarder methodsFor:'accessing'!
128
9c2378152500 Initial revision
claus
parents:
diff changeset
   225
134
claus
parents: 128
diff changeset
   226
condition:aCondition
144
claus
parents: 142
diff changeset
   227
    "set the condition - typically a block"
claus
parents: 142
diff changeset
   228
134
claus
parents: 128
diff changeset
   229
    condition := aCondition
claus
parents: 128
diff changeset
   230
!
claus
parents: 128
diff changeset
   231
244
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   232
destination
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   233
    "return the destination"
144
claus
parents: 142
diff changeset
   234
244
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   235
    ^ destination
139
claus
parents: 134
diff changeset
   236
!
claus
parents: 134
diff changeset
   237
claus
parents: 134
diff changeset
   238
destination:anObject 
144
claus
parents: 142
diff changeset
   239
    "set the destination 
claus
parents: 142
diff changeset
   240
     - that one will get the event with an additional view arg."
claus
parents: 142
diff changeset
   241
139
claus
parents: 134
diff changeset
   242
    destination := anObject
claus
parents: 134
diff changeset
   243
!
claus
parents: 134
diff changeset
   244
244
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   245
destinationView
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   246
    "return the destination view"
144
claus
parents: 142
diff changeset
   247
244
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   248
    ^ destinationView
139
claus
parents: 134
diff changeset
   249
!
claus
parents: 134
diff changeset
   250
244
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   251
destinationView:aView
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   252
    "set the destination view"
144
claus
parents: 142
diff changeset
   253
244
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   254
    destinationView := aView
128
9c2378152500 Initial revision
claus
parents:
diff changeset
   255
!
9c2378152500 Initial revision
claus
parents:
diff changeset
   256
9c2378152500 Initial revision
claus
parents:
diff changeset
   257
sourceView
144
claus
parents: 142
diff changeset
   258
    "get the sourceView - if nonNil, only events from this view will be forwarded"
claus
parents: 142
diff changeset
   259
128
9c2378152500 Initial revision
claus
parents:
diff changeset
   260
    ^ sourceView
142
claus
parents: 140
diff changeset
   261
!
claus
parents: 140
diff changeset
   262
244
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   263
sourceView:aView
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   264
    "set the sourceView - if nonNil, only events from this view will be forwarded"
128
9c2378152500 Initial revision
claus
parents:
diff changeset
   265
244
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   266
    sourceView := aView
128
9c2378152500 Initial revision
claus
parents:
diff changeset
   267
! !
9c2378152500 Initial revision
claus
parents:
diff changeset
   268
9c2378152500 Initial revision
claus
parents:
diff changeset
   269
!KeyboardForwarder methodsFor:'event forwarding'!
9c2378152500 Initial revision
claus
parents:
diff changeset
   270
9c2378152500 Initial revision
claus
parents:
diff changeset
   271
keyPress:key x:x y:y view:aView
139
claus
parents: 134
diff changeset
   272
    "handle a delegated event - this is sent by the sensor to actually
claus
parents: 134
diff changeset
   273
     forward the event (i.e. after I returned true on handlesKeyPress:.
claus
parents: 134
diff changeset
   274
     Take care of cyclic delegation (via a kludge-test for negative coordinate)."
claus
parents: 134
diff changeset
   275
128
9c2378152500 Initial revision
claus
parents:
diff changeset
   276
    x < 0 ifTrue:[
9c2378152500 Initial revision
claus
parents:
diff changeset
   277
	"
9c2378152500 Initial revision
claus
parents:
diff changeset
   278
	 already delegated ... ignore
9c2378152500 Initial revision
claus
parents:
diff changeset
   279
	"
9c2378152500 Initial revision
claus
parents:
diff changeset
   280
	^ self
9c2378152500 Initial revision
claus
parents:
diff changeset
   281
    ].
9c2378152500 Initial revision
claus
parents:
diff changeset
   282
139
claus
parents: 134
diff changeset
   283
    destination notNil ifTrue:[
claus
parents: 134
diff changeset
   284
	destination keyPress:key x:-1 y:-1 view:aView.
claus
parents: 134
diff changeset
   285
    ] ifFalse:[
144
claus
parents: 142
diff changeset
   286
	destinationView notNil ifTrue:[
claus
parents: 142
diff changeset
   287
	    WindowEvent
claus
parents: 142
diff changeset
   288
		sendEvent:#keyPress:x:y:
claus
parents: 142
diff changeset
   289
		arguments:(Array with:key with:-1 with:-1)
claus
parents: 142
diff changeset
   290
		view:destinationView
claus
parents: 142
diff changeset
   291
	]
139
claus
parents: 134
diff changeset
   292
    ]
128
9c2378152500 Initial revision
claus
parents:
diff changeset
   293
!
9c2378152500 Initial revision
claus
parents:
diff changeset
   294
9c2378152500 Initial revision
claus
parents:
diff changeset
   295
keyRelease:key x:x y:y view:aView
139
claus
parents: 134
diff changeset
   296
    "handle a delegated event - this is sent by the sensor to actually
claus
parents: 134
diff changeset
   297
     forward the event (i.e. after I returned true on handlesKeyRelease:.
claus
parents: 134
diff changeset
   298
     Take care of cyclic delegation (via a kludge-test for negative coordinate)."
claus
parents: 134
diff changeset
   299
128
9c2378152500 Initial revision
claus
parents:
diff changeset
   300
    x < 0 ifTrue:[
9c2378152500 Initial revision
claus
parents:
diff changeset
   301
	"
9c2378152500 Initial revision
claus
parents:
diff changeset
   302
	 already delegated ... ignore
9c2378152500 Initial revision
claus
parents:
diff changeset
   303
	"
9c2378152500 Initial revision
claus
parents:
diff changeset
   304
	^ self
9c2378152500 Initial revision
claus
parents:
diff changeset
   305
    ].
9c2378152500 Initial revision
claus
parents:
diff changeset
   306
139
claus
parents: 134
diff changeset
   307
    destination notNil ifTrue:[
144
claus
parents: 142
diff changeset
   308
	destination keyRelease:key x:-1 y:-1 view:aView
139
claus
parents: 134
diff changeset
   309
    ] ifFalse:[
144
claus
parents: 142
diff changeset
   310
	destinationView notNil ifTrue:[
claus
parents: 142
diff changeset
   311
	    WindowEvent
claus
parents: 142
diff changeset
   312
		sendEvent:#keyRelease:x:y:
claus
parents: 142
diff changeset
   313
		arguments:(Array with:key with:-1 with:-1)
claus
parents: 142
diff changeset
   314
		view:destinationView
claus
parents: 142
diff changeset
   315
	]
139
claus
parents: 134
diff changeset
   316
    ]
128
9c2378152500 Initial revision
claus
parents:
diff changeset
   317
! !
244
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   318
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   319
!KeyboardForwarder methodsFor:'queries'!
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   320
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   321
checkCondition:type key:key view:aView
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   322
    condition notNil ifTrue:[
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   323
	condition == #noFocus ifTrue:[
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   324
	    aView windowGroup focusView notNil ifTrue:[^ false]
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   325
	].
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   326
	condition isBlock ifTrue:[
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   327
	    (condition value:type value:key value:aView) ifFalse:[^ false]
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   328
	]
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   329
    ].
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   330
    sourceView notNil ifTrue:[
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   331
	^ aView == sourceView
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   332
    ].
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   333
    ^ true
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   334
!
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   335
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   336
delegatesTo:someone
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   337
    "return true, if I delegate events to someone"
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   338
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   339
    ^ destination == someone or:[destinationView == someone]
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   340
!
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   341
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   342
handlesKeyPress:key inView:aView
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   343
    "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
   344
     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
   345
     false otherwise."
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   346
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   347
    ^ self checkCondition:#keyPress key:key view:aView
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   348
!
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   349
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   350
handlesKeyRelease:key inView:aView
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   351
    "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
   352
     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
   353
     false otherwise."
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   354
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   355
    ^ self checkCondition:#keyRelease key:key view:aView
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   356
! !
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   357
251
915de9a65169 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 244
diff changeset
   358
!KeyboardForwarder class methodsFor:'documentation'!
915de9a65169 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 244
diff changeset
   359
915de9a65169 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 244
diff changeset
   360
version
915de9a65169 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 244
diff changeset
   361
    ^ '$Header: /cvs/stx/stx/libview/KeyboardForwarder.st,v 1.9 1995-11-23 17:45:20 cg Exp $'
915de9a65169 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 244
diff changeset
   362
! !