128
|
1 |
"
|
|
2 |
COPYRIGHT (c) 1995 by Claus Gittinger
|
|
3 |
All Rights Reserved
|
|
4 |
|
|
5 |
This software is furnished under a license and may be used
|
|
6 |
only in accordance with the terms of that license and with the
|
|
7 |
inclusion of the above copyright notice. This software may not
|
|
8 |
be provided or otherwise made available to, or used by, any
|
|
9 |
other person. No title to or ownership of the software is
|
|
10 |
hereby transferred.
|
|
11 |
"
|
|
12 |
|
|
13 |
|
|
14 |
'From Smalltalk/X, Version:2.10.5 on 30-mar-1995 at 5:32:55 am'!
|
|
15 |
|
|
16 |
Object subclass:#KeyboardForwarder
|
139
|
17 |
instanceVariableNames:'sourceView destinationView destination condition'
|
128
|
18 |
classVariableNames:''
|
|
19 |
poolDictionaries:''
|
|
20 |
category:'Interface-Support'
|
|
21 |
!
|
|
22 |
|
|
23 |
!KeyboardForwarder class methodsFor:'documentation'!
|
|
24 |
|
|
25 |
version
|
|
26 |
"
|
142
|
27 |
$Header: /cvs/stx/stx/libview/KeyboardForwarder.st,v 1.5 1995-05-12 18:00:26 claus Exp $
|
128
|
28 |
"
|
|
29 |
!
|
|
30 |
|
|
31 |
documentation
|
|
32 |
"
|
|
33 |
Instances of this class can be used as delegates to forward keyboard
|
139
|
34 |
events to some object or other view (via aView delegate:).
|
128
|
35 |
Notice, that delegates dont have to be instances of
|
|
36 |
myself; any object with a protocol similar to mine can be used as
|
|
37 |
a delegate.
|
142
|
38 |
(i.e. any object that responds to
|
|
39 |
handlesKeyPress:view: / keyPress:x:y:view: / delegatesTo: etc.)
|
139
|
40 |
|
|
41 |
However, I provide the most common functions required for conditional
|
|
42 |
event delegation and instances of myself are for example used to forward
|
|
43 |
events from elements of some dialogBoxes to the enterfield/fieldGroup -
|
|
44 |
this allows keyboard input to be forwarded to the active text-field even
|
|
45 |
while the mouse pointer is somewhere else.
|
|
46 |
|
|
47 |
Another application of delegation is to catch keyboard input to some standard
|
|
48 |
widget, optionally processing and resending the key-event.
|
128
|
49 |
|
|
50 |
Instance Variables:
|
139
|
51 |
|
128
|
52 |
destinationView <View> the view which shall receive
|
|
53 |
the forwarded keyboard events.
|
134
|
54 |
|
139
|
55 |
destination <Object> the object which shall receive
|
|
56 |
the forwarded keyboard events.
|
|
57 |
|
134
|
58 |
sourceView <ViewOrNil> if non-nil, only events from this
|
|
59 |
view are forwarded.
|
|
60 |
(currently nowhere used)
|
|
61 |
|
|
62 |
condition <Symbol> an additional condition for forwarding
|
|
63 |
currently only #noFocus is implemented.
|
|
64 |
The #noFocus condition will only forward
|
|
65 |
events if no explicit focus has been
|
|
66 |
set in the windowGroup.
|
128
|
67 |
"
|
|
68 |
!
|
|
69 |
|
|
70 |
copyright
|
|
71 |
"
|
|
72 |
COPYRIGHT (c) 1995 by Claus Gittinger
|
|
73 |
All Rights Reserved
|
|
74 |
|
|
75 |
This software is furnished under a license and may be used
|
|
76 |
only in accordance with the terms of that license and with the
|
|
77 |
inclusion of the above copyright notice. This software may not
|
|
78 |
be provided or otherwise made available to, or used by, any
|
|
79 |
other person. No title to or ownership of the software is
|
|
80 |
hereby transferred.
|
|
81 |
"
|
|
82 |
|
|
83 |
! !
|
|
84 |
|
|
85 |
!KeyboardForwarder class methodsFor:'instance creation'!
|
|
86 |
|
139
|
87 |
from:sourceView toView:destinationView
|
|
88 |
"create and return a new KeyboardForwarder to redirect key events
|
|
89 |
for sourceView to destinationView. Events from other than the sourceView
|
|
90 |
will not be forwarded. The forwarded event will be reported excluding
|
|
91 |
the original view as argument (i.e. as #keyPress:x:y:).
|
|
92 |
Use this, if the destination is a view."
|
|
93 |
|
128
|
94 |
^ self new sourceView:sourceView; destinationView:destinationView
|
|
95 |
!
|
|
96 |
|
139
|
97 |
from:sourceView to:destination
|
|
98 |
"create and return a new KeyboardForwarder to redirect key events
|
|
99 |
for sourceView to destination. Events from other than the sourceView
|
|
100 |
will not be forwarded. The forwarded event will be reported including
|
|
101 |
the original view as argument (i.e. as #keyPress:x:y:view:).
|
|
102 |
Use this, if the destination is not a view."
|
|
103 |
|
|
104 |
^ self new sourceView:sourceView; destination:destination
|
|
105 |
!
|
|
106 |
|
|
107 |
toView:destinationView
|
|
108 |
"create and return a new KeyboardForwarder to redirect any key event
|
|
109 |
to destinationView (Independent of the view in which the event originally
|
|
110 |
occurred). The forwarded event will be reported excluding
|
|
111 |
the original view as argument (i.e. as #keyPress:x:y:).
|
|
112 |
Use this, if the destination is a view."
|
|
113 |
|
128
|
114 |
^ self new destinationView:destinationView
|
134
|
115 |
!
|
|
116 |
|
139
|
117 |
to:destination
|
|
118 |
"create and return a new KeyboardForwarder to redirect any key event
|
|
119 |
to destination (Independent of the view in which the event originally
|
|
120 |
occurred). The forwarded event will be reported including
|
|
121 |
the original view as argument (i.e. as #keyPress:x:y:view:).
|
|
122 |
Use this, if the destination is not a view."
|
|
123 |
|
|
124 |
^ self new destination:destination
|
|
125 |
!
|
|
126 |
|
|
127 |
toView:destinationView condition:aConditionSymbol
|
|
128 |
"create and return a new KeyboardForwarder to redirect any key event
|
|
129 |
to destinationView (Independent of the view in which the event originally
|
|
130 |
occurred) but only, if some condition as specified by aConditionSymbol
|
|
131 |
is met. The forwarded event will be reported excluding
|
|
132 |
the original view as argument (i.e. as #keyPress:x:y:).
|
|
133 |
Use this, if the destination is a view."
|
|
134 |
|
|
135 |
^ self new destinationView:destinationView; condition:aConditionSymbol
|
|
136 |
!
|
|
137 |
|
|
138 |
to:destination condition:aConditionSymbol
|
|
139 |
"create and return a new KeyboardForwarder to redirect any key event
|
|
140 |
to destinationView (Independent of the view in which the event originally
|
|
141 |
occurred) but only, if some condition as specified by aConditionSymbol
|
|
142 |
is met. The forwarded event will be reported including
|
|
143 |
the original view as argument (i.e. as #keyPress:x:y:view:).
|
|
144 |
Use this, if the destination is not a view."
|
|
145 |
|
|
146 |
^ self new destination:destination; condition:aConditionSymbol
|
128
|
147 |
! !
|
|
148 |
|
139
|
149 |
!KeyboardForwarder methodsFor:'private accessing'!
|
128
|
150 |
|
134
|
151 |
condition:aCondition
|
|
152 |
condition := aCondition
|
|
153 |
!
|
|
154 |
|
128
|
155 |
destinationView:aView
|
|
156 |
destinationView := aView
|
|
157 |
!
|
|
158 |
|
139
|
159 |
destinationView
|
|
160 |
^ destinationView
|
|
161 |
!
|
|
162 |
|
|
163 |
destination:anObject
|
|
164 |
destination := anObject
|
|
165 |
!
|
|
166 |
|
|
167 |
destination
|
|
168 |
^ destination
|
|
169 |
!
|
|
170 |
|
128
|
171 |
sourceView:aView
|
|
172 |
sourceView := aView
|
|
173 |
!
|
|
174 |
|
|
175 |
sourceView
|
|
176 |
^ sourceView
|
|
177 |
! !
|
|
178 |
|
|
179 |
!KeyboardForwarder methodsFor:'queries'!
|
|
180 |
|
142
|
181 |
delegatesTo:someone
|
|
182 |
"return true, if I delegate events to someone"
|
|
183 |
|
|
184 |
^ destination == someone or:[destinationView == someone]
|
|
185 |
!
|
|
186 |
|
128
|
187 |
handlesKeyPress:key inView:aView
|
139
|
188 |
"this is the query from the sensor to ask me if I would like to
|
|
189 |
get a keyPress event for key from aView. Return true, if I want so,
|
|
190 |
false otherwise."
|
|
191 |
|
134
|
192 |
condition notNil ifTrue:[
|
|
193 |
condition == #noFocus ifTrue:[
|
|
194 |
aView windowGroup focusView notNil ifTrue:[^ false]
|
|
195 |
]
|
|
196 |
].
|
128
|
197 |
sourceView notNil ifTrue:[
|
|
198 |
^ aView == sourceView
|
|
199 |
].
|
|
200 |
^ true
|
|
201 |
!
|
|
202 |
|
|
203 |
handlesKeyRelease:key inView:aView
|
139
|
204 |
"this is the query from the sensor to ask me if I would like to
|
|
205 |
get a keyRelease event for key from aView. Return true, if I want so,
|
|
206 |
false otherwise."
|
|
207 |
|
134
|
208 |
condition notNil ifTrue:[
|
|
209 |
condition == #noFocus ifTrue:[
|
|
210 |
aView windowGroup focusView notNil ifTrue:[^ false]
|
|
211 |
]
|
|
212 |
].
|
128
|
213 |
sourceView notNil ifTrue:[
|
|
214 |
^ aView == sourceView
|
|
215 |
].
|
|
216 |
^ true
|
|
217 |
! !
|
|
218 |
|
|
219 |
!KeyboardForwarder methodsFor:'event forwarding'!
|
|
220 |
|
|
221 |
keyPress:key x:x y:y view:aView
|
139
|
222 |
"handle a delegated event - this is sent by the sensor to actually
|
|
223 |
forward the event (i.e. after I returned true on handlesKeyPress:.
|
|
224 |
Take care of cyclic delegation (via a kludge-test for negative coordinate)."
|
|
225 |
|
128
|
226 |
x < 0 ifTrue:[
|
|
227 |
"
|
|
228 |
already delegated ... ignore
|
|
229 |
"
|
|
230 |
^ self
|
|
231 |
].
|
|
232 |
|
139
|
233 |
destination notNil ifTrue:[
|
|
234 |
destination keyPress:key x:-1 y:-1 view:aView.
|
|
235 |
] ifFalse:[
|
140
|
236 |
WindowEvent
|
|
237 |
sendEvent:#keyPress:x:y:
|
|
238 |
arguments:(Array with:key with:-1 with:-1)
|
|
239 |
view:destinationView
|
|
240 |
"/ destinationView keyPress:key x:-1 y:-1
|
139
|
241 |
]
|
128
|
242 |
!
|
|
243 |
|
|
244 |
keyRelease:key x:x y:y view:aView
|
139
|
245 |
"handle a delegated event - this is sent by the sensor to actually
|
|
246 |
forward the event (i.e. after I returned true on handlesKeyRelease:.
|
|
247 |
Take care of cyclic delegation (via a kludge-test for negative coordinate)."
|
|
248 |
|
128
|
249 |
x < 0 ifTrue:[
|
|
250 |
"
|
|
251 |
already delegated ... ignore
|
|
252 |
"
|
|
253 |
^ self
|
|
254 |
].
|
|
255 |
|
139
|
256 |
destination notNil ifTrue:[
|
140
|
257 |
WindowEvent
|
|
258 |
sendEvent:#keyRelease:x:y:
|
|
259 |
arguments:(Array with:key with:-1 with:-1)
|
|
260 |
view:destinationView
|
|
261 |
"/ destinationView keyRelease:key x:-1 y:-1 view:aView
|
139
|
262 |
] ifFalse:[
|
|
263 |
destinationView keyRelease:key x:-1 y:-1
|
|
264 |
]
|
128
|
265 |
! !
|