26
|
1 |
"
|
|
2 |
COPYRIGHT (c) 1993 by Claus Gittinger
|
72
|
3 |
All Rights Reserved
|
26
|
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 |
"
|
11
|
12 |
|
|
13 |
Object subclass:#WindowEvent
|
72
|
14 |
instanceVariableNames:'view type arguments'
|
|
15 |
classVariableNames:''
|
|
16 |
poolDictionaries:''
|
|
17 |
category:'Interface-Support'
|
11
|
18 |
!
|
|
19 |
|
54
|
20 |
WindowEvent comment:'
|
|
21 |
COPYRIGHT (c) 1993 by Claus Gittinger
|
72
|
22 |
All Rights Reserved
|
54
|
23 |
|
144
|
24 |
$Header: /cvs/stx/stx/libview/WindowEvent.st,v 1.18 1995-05-16 17:14:32 claus Exp $
|
54
|
25 |
'!
|
|
26 |
|
46
|
27 |
!WindowEvent class methodsFor:'documentation'!
|
|
28 |
|
|
29 |
copyright
|
|
30 |
"
|
|
31 |
COPYRIGHT (c) 1993 by Claus Gittinger
|
72
|
32 |
All Rights Reserved
|
46
|
33 |
|
|
34 |
This software is furnished under a license and may be used
|
|
35 |
only in accordance with the terms of that license and with the
|
|
36 |
inclusion of the above copyright notice. This software may not
|
|
37 |
be provided or otherwise made available to, or used by, any
|
|
38 |
other person. No title to or ownership of the software is
|
|
39 |
hereby transferred.
|
|
40 |
"
|
|
41 |
!
|
|
42 |
|
|
43 |
version
|
|
44 |
"
|
144
|
45 |
$Header: /cvs/stx/stx/libview/WindowEvent.st,v 1.18 1995-05-16 17:14:32 claus Exp $
|
46
|
46 |
"
|
|
47 |
!
|
|
48 |
|
|
49 |
documentation
|
|
50 |
"
|
|
51 |
Instances of WindowEvent are created for every event coming from
|
144
|
52 |
the graphics device.
|
|
53 |
Usually, they are enqueued by the event dispatcher process into
|
|
54 |
a sensors input queue, and dequeued & processed by a windowGroup process
|
|
55 |
in its event loop.
|
|
56 |
|
|
57 |
WindowEvents hold the event type and additional information (such as key,
|
|
58 |
x/y coordinates etc). Also, windowEvents know how to send themself to some
|
|
59 |
destination. To provide a common (single) place where event dispatching is
|
|
60 |
implemented, this forwarding is done by a clas method here (i.e. not by the
|
|
61 |
window group itself).
|
|
62 |
|
|
63 |
The algorithm for event dispatching is:
|
|
64 |
|
|
65 |
- if the destination view has a keyboard focus set,
|
|
66 |
AND the event is a keyboard event,
|
|
67 |
THEN recursively invoke the event dispatching method,
|
|
68 |
sending the event to the focus view (or its delegate, as below)
|
|
69 |
|
|
70 |
- if the destination view has a delegate,
|
|
71 |
AND its a keyboard, button or pointer event,
|
|
72 |
AND the delegate is interrested in that event
|
|
73 |
(i.e. implements & responds to #handlesXXX with true)
|
|
74 |
THEN send the event to the delegate, passing the original view
|
|
75 |
as additional argument
|
|
76 |
|
|
77 |
- if the view has a nonNil controller,
|
|
78 |
AND its a key, button or pointer event,
|
|
79 |
THEN send the event to the controller
|
|
80 |
|
|
81 |
- otherwise send the event to the view
|
|
82 |
|
|
83 |
|
|
84 |
If the view has a non-nil transformation, the event is sent as a
|
|
85 |
#deviceXXX message, passing device coordinates. Typically, subclasses
|
|
86 |
of view do not redefine this method and the inherited default method
|
|
87 |
translates these device coordinates into logical coordinates and resends
|
|
88 |
an XXX message.
|
|
89 |
If the view has no transformation, the XXX message is directly sent here.
|
|
90 |
|
|
91 |
For example, a 'buttonPress:button x:x y:y' event leads to sending of
|
|
92 |
'aView deviceButtonPress:button x:x y:y' which resends
|
|
93 |
'aView buttonPress:button x:(x-logical) y:(y-logical)'
|
|
94 |
|
|
95 |
This allows views which are interrested in deviceCoordinates to get them
|
|
96 |
(by redefining #deviceXXX) and other views to transparently get & use
|
|
97 |
logical coordinates.
|
|
98 |
|
|
99 |
Therefore, for a delegated keyPress messages, the flow is:
|
|
100 |
|
|
101 |
sendEvent
|
|
102 |
view has delegate
|
|
103 |
------> ask delegate via 'handlesKeyPress:key inView:view'
|
|
104 |
<------ returns true
|
|
105 |
------> 'delegate keyPress:key x:x y:y view:view'
|
|
106 |
-----> delegate does whatever it wants to do
|
|
107 |
(typically sends the event to some other view)
|
|
108 |
|
|
109 |
for an undelegated message:
|
|
110 |
|
|
111 |
sendEvent
|
|
112 |
view has delegate
|
|
113 |
------> ask delegate via 'handlesKeyPress:key inView:view'
|
|
114 |
<------ returns false
|
|
115 |
view has controller
|
|
116 |
------> 'controller keyPress:key x:x y:y'
|
|
117 |
view has no controller
|
|
118 |
view has transformation
|
|
119 |
----> 'view deviceKeyPress:key x:x y:y'
|
|
120 |
inverse transform x/y
|
|
121 |
----> 'self keyPress:key x:xLogical y:yLogical'
|
|
122 |
view has no transformation
|
|
123 |
----> 'view keyPress:key x:x y:y'
|
46
|
124 |
"
|
|
125 |
! !
|
|
126 |
|
11
|
127 |
!WindowEvent class methodsFor:'instance creation'!
|
|
128 |
|
|
129 |
for:aView type:aSymbol arguments:argArray
|
|
130 |
"create and return a new windowEvent for sending
|
|
131 |
aSymbol-message with arguments to aView"
|
|
132 |
|
46
|
133 |
^ (self new) for:aView type:aSymbol arguments:argArray
|
|
134 |
!
|
|
135 |
|
72
|
136 |
for:aView type:aSymbol
|
|
137 |
"create and return a new windowEvent for sending
|
|
138 |
aSymbol-message with no arguments to aView"
|
|
139 |
|
|
140 |
^ (self new) for:aView type:aSymbol arguments:#()
|
|
141 |
!
|
|
142 |
|
46
|
143 |
damageFor:aView rectangle:aRectangle
|
|
144 |
"create and return a new damage Event for aRectangle
|
|
145 |
in aView"
|
|
146 |
|
|
147 |
^ (self new) for:aView type:#damage arguments:aRectangle
|
|
148 |
|
11
|
149 |
! !
|
|
150 |
|
72
|
151 |
!WindowEvent methodsFor:'queries'!
|
|
152 |
|
|
153 |
isKeyEvent
|
|
154 |
"return true, if this event is a keyboard event"
|
|
155 |
|
89
|
156 |
^ (type == #keyPress:x:y:) or:[type == #keyRelease:x:y:]
|
|
157 |
!
|
|
158 |
|
|
159 |
isKeyPressEvent
|
|
160 |
"return true, if this event is a keyboard event"
|
|
161 |
|
|
162 |
^ (type == #keyPress:x:y:)
|
|
163 |
!
|
|
164 |
|
|
165 |
isButtonEvent
|
|
166 |
"return true, if this event is a button event"
|
|
167 |
|
|
168 |
^ (type == #buttonPress:x:y:)
|
|
169 |
or:[type == #buttonRelease:x:y:
|
|
170 |
or:[type == #'buttonShiftPress:x:y:'
|
|
171 |
or:[type == #'buttonMultiPress:x:y:'
|
|
172 |
or:[type == #'buttonMotion:x:y:']]]]
|
72
|
173 |
!
|
|
174 |
|
|
175 |
isDamage
|
|
176 |
"return true, if this is a damage event"
|
|
177 |
|
|
178 |
^ type == #damage
|
|
179 |
! !
|
|
180 |
|
28
|
181 |
!WindowEvent methodsFor:'accessing'!
|
|
182 |
|
|
183 |
view
|
|
184 |
"return the view, for which the event is for"
|
|
185 |
|
|
186 |
^ view
|
|
187 |
!
|
|
188 |
|
72
|
189 |
view:aView
|
|
190 |
"set the view, for which the event is for"
|
|
191 |
|
|
192 |
view := aView
|
|
193 |
!
|
|
194 |
|
28
|
195 |
type
|
|
196 |
"return the type of the event"
|
|
197 |
|
|
198 |
^ type
|
|
199 |
!
|
|
200 |
|
|
201 |
arguments
|
|
202 |
"return the arguments of the event"
|
|
203 |
|
|
204 |
^ arguments
|
|
205 |
!
|
|
206 |
|
|
207 |
arguments:anArray
|
|
208 |
"set the arguments"
|
|
209 |
|
|
210 |
arguments := anArray
|
46
|
211 |
!
|
|
212 |
|
|
213 |
rectangle
|
|
214 |
"return the damage rectangle"
|
|
215 |
|
|
216 |
^ arguments "consider this a kludge"
|
89
|
217 |
!
|
|
218 |
|
|
219 |
key
|
|
220 |
"return the key of the key-event. For non key-events, nil is returned."
|
|
221 |
|
|
222 |
((type == #keyPress:x:y:)
|
|
223 |
or:[type == #keyRelease:x:y:]) ifTrue:[
|
|
224 |
^ arguments at:1
|
|
225 |
].
|
|
226 |
^ nil
|
28
|
227 |
! !
|
|
228 |
|
115
|
229 |
!WindowEvent class methodsFor:'forwarding events'!
|
|
230 |
|
|
231 |
sendEvent:type arguments:arguments view:view
|
|
232 |
"forward the event represented by type and arguments to the views delegate,
|
|
233 |
the views controller or the view.
|
11
|
234 |
|
115
|
235 |
If there is a delegate, only messages which are understood by it are
|
|
236 |
forwarded. Also, the delegate is asked if it is willing to handle the event
|
|
237 |
before.
|
|
238 |
Delegated messages get the original view as an extra argument.
|
|
239 |
Delegation has higher priority than controller forwarding."
|
11
|
240 |
|
135
|
241 |
^ self
|
|
242 |
sendEvent:type
|
|
243 |
arguments:arguments
|
|
244 |
view:view
|
|
245 |
withFocusOn:nil
|
|
246 |
delegate:true
|
89
|
247 |
!
|
|
248 |
|
115
|
249 |
sendEvent:type arguments:argArray view:view withFocusOn:focusView
|
|
250 |
"forward the event represented by type and arguments to the views delegate,
|
|
251 |
the views controller or the view.
|
|
252 |
If focusView is nonNil, and it is a keyboard event, it is forwarded to this
|
141
|
253 |
view (even if there is a delegate).
|
115
|
254 |
|
89
|
255 |
If there is a delegate, only messages which are understood by it are
|
115
|
256 |
forwarded. Also, the delegate is asked if it is willing to handle the event
|
|
257 |
before.
|
|
258 |
Delegated messages get the original view as an extra argument.
|
89
|
259 |
Delegation has higher priority than both controller or focusView
|
|
260 |
forwarding."
|
|
261 |
|
135
|
262 |
^ self
|
|
263 |
sendEvent:type
|
|
264 |
arguments:argArray
|
|
265 |
view:view
|
|
266 |
withFocusOn:focusView
|
|
267 |
delegate:true
|
|
268 |
!
|
|
269 |
|
|
270 |
sendEvent:type arguments:argArray view:view withFocusOn:focusView delegate:doDelegate
|
|
271 |
"forward the event represented by type and arguments to the views delegate,
|
|
272 |
the views controller or the view.
|
|
273 |
If focusView is nonNil, and it is a keyboard event, it is forwarded to this
|
|
274 |
view (but not if there was a delegate in the first place).
|
|
275 |
|
|
276 |
If doDelegate is true, keyboard and button events are forwarded to a
|
|
277 |
delegate object (if non-nil). DoDelegate may be passed as true, to
|
|
278 |
handle events which are already delegated.
|
|
279 |
If there is a delegate, only messages which are understood by it are
|
|
280 |
forwarded. Also, the delegate is asked if it is willing to handle the event
|
|
281 |
before.
|
|
282 |
Delegated messages get the original view as an extra argument.
|
|
283 |
Delegation has higher priority than both controller or focusView
|
|
284 |
forwarding."
|
|
285 |
|
115
|
286 |
|delegate selector delegateMessage delegateQuery
|
|
287 |
eventReceiver controller deviceMessage
|
|
288 |
isKeyEvent isButtonEvent isPointerEvent trans|
|
|
289 |
|
|
290 |
isKeyEvent := isButtonEvent := isPointerEvent := false.
|
11
|
291 |
|
115
|
292 |
(type == #'keyPress:x:y:') ifTrue:[
|
|
293 |
isKeyEvent := true.
|
|
294 |
deviceMessage := #'deviceKeyPress:x:y:'.
|
|
295 |
delegateMessage := #'keyPress:x:y:view:'.
|
|
296 |
delegateQuery := #'handlesKeyPress:inView:'.
|
|
297 |
] ifFalse:[ (type == #'keyRelease:x:y:') ifTrue:[
|
|
298 |
isKeyEvent := true.
|
|
299 |
deviceMessage := #'deviceKeyRelease:x:y:'.
|
|
300 |
delegateMessage := #'keyRelease:x:y:view:'.
|
|
301 |
delegateQuery := #'handlesKeyRelease:inView:'.
|
141
|
302 |
] ifFalse:[ (type == #'buttonMotion:x:y:') ifTrue:[
|
|
303 |
isButtonEvent := true.
|
|
304 |
deviceMessage := #'deviceButtonMotion:x:y:'.
|
|
305 |
delegateMessage := #'buttonMotion:x:y:view:'.
|
|
306 |
delegateQuery := #'handlesButtonMotion:inView:'.
|
115
|
307 |
] ifFalse:[ (type == #'buttonPress:x:y:') ifTrue:[
|
|
308 |
isButtonEvent := true.
|
|
309 |
deviceMessage := #'deviceButtonPress:x:y:'.
|
|
310 |
delegateMessage := #'buttonPress:x:y:view:'.
|
|
311 |
delegateQuery := #'handlesButtonPress:inView:'.
|
|
312 |
] ifFalse:[ (type == #'buttonRelease:x:y:') ifTrue:[
|
|
313 |
isButtonEvent := true.
|
|
314 |
deviceMessage := #'deviceButtonRelease:x:y:'.
|
|
315 |
delegateMessage := #'buttonRelease:x:y:view:'.
|
|
316 |
delegateQuery := #'handlesButtonRelease:inView:'.
|
|
317 |
] ifFalse:[ (type == #'buttonShiftPress:x:y:') ifTrue:[
|
|
318 |
isButtonEvent := true.
|
|
319 |
deviceMessage := #'deviceButtonShiftPress:x:y:'.
|
|
320 |
delegateMessage := #'buttonShiftPress:x:y:view:'.
|
|
321 |
delegateQuery := #'handlesButtonShiftPress:inView:'.
|
|
322 |
] ifFalse:[ (type == #'buttonMultiPress:x:y:') ifTrue:[
|
|
323 |
isButtonEvent := true.
|
|
324 |
deviceMessage := #'deviceButtonMultiPress:x:y:'.
|
|
325 |
delegateMessage := #'buttonMultiPress:x:y:view:'.
|
|
326 |
delegateQuery := #'handlesButtonMultiPress:inView:'.
|
|
327 |
] ifFalse:[ (type == #'pointerEnter:x:y:') ifTrue:[
|
|
328 |
isPointerEvent := true.
|
|
329 |
deviceMessage := #'devicePointerEnter:x:y:'.
|
|
330 |
delegateMessage := #'pointerEnter:x:y:view:'.
|
|
331 |
delegateQuery := #'handlesPointerEnter:inView:'.
|
|
332 |
] ifFalse:[ (type == #'pointerLeave:') ifTrue:[
|
|
333 |
isPointerEvent := true.
|
144
|
334 |
deviceMessage := #'pointerLeave:view:'.
|
115
|
335 |
delegateMessage := #'pointerLeave:view:'.
|
|
336 |
delegateQuery := #'handlesPointerLeave:inView:'.
|
|
337 |
] ifFalse:[ (type == #'exposeX:y:width:height:') ifTrue:[
|
|
338 |
deviceMessage := #'deviceExposeX:y:width:height:'.
|
|
339 |
] ifFalse:[ (type == #'graphicExposeX:y:width:height:') ifTrue:[
|
|
340 |
deviceMessage := #'deviceGraphicExposeX:y:width:height:'.
|
|
341 |
]]]]]]]]]]].
|
89
|
342 |
|
141
|
343 |
"
|
|
344 |
if there is a focusView, and its a keyboard event, pass it
|
|
345 |
to that view (or its controller, or its delegate).
|
|
346 |
In this case, a coordinate which is outside of
|
143
|
347 |
the focusView (0 @ 0) is passed as x/y coordinates.
|
141
|
348 |
"
|
|
349 |
(focusView notNil
|
|
350 |
and:[isKeyEvent]) ifTrue:[
|
|
351 |
self sendEvent:type
|
143
|
352 |
arguments:(Array with:(argArray at:1) with:0 with:0)
|
141
|
353 |
view:focusView
|
|
354 |
withFocusOn:nil
|
|
355 |
delegate:doDelegate.
|
|
356 |
^ self
|
|
357 |
].
|
|
358 |
|
135
|
359 |
doDelegate ifTrue:[
|
|
360 |
"
|
|
361 |
handle delegated messages
|
78
|
362 |
"
|
135
|
363 |
(isKeyEvent
|
|
364 |
or:[isButtonEvent
|
|
365 |
or:[isPointerEvent]]) ifTrue:[
|
|
366 |
delegate := view delegate.
|
|
367 |
|
89
|
368 |
"
|
135
|
369 |
what a kludge - sending to delegate requires
|
|
370 |
another selector and an additional argument ...
|
115
|
371 |
"
|
140
|
372 |
(delegate notNil
|
|
373 |
and:[delegate respondsTo:delegateMessage]) ifTrue:[
|
135
|
374 |
"
|
|
375 |
is the delegate interrested in that event ?
|
|
376 |
(if it does not respond to the handlesXXX message,
|
|
377 |
we assume: NO)
|
115
|
378 |
"
|
135
|
379 |
((delegate respondsTo:delegateQuery)
|
|
380 |
and:[delegate perform:delegateQuery with:(argArray at:1) with:view]) ifTrue:[
|
|
381 |
"
|
|
382 |
mhmh ... have to convert to logical coordinates
|
|
383 |
"
|
|
384 |
(trans := view transformation) notNil ifTrue:[
|
|
385 |
argArray size > 2 ifTrue:[
|
|
386 |
argArray at:2 put:(trans applyInverseToX:(argArray at:2)).
|
|
387 |
argArray at:3 put:(trans applyInverseToY:(argArray at:3)).
|
|
388 |
].
|
89
|
389 |
].
|
135
|
390 |
argArray isNil ifTrue:[
|
|
391 |
delegate perform:delegateMessage with:view
|
|
392 |
] ifFalse:[
|
|
393 |
delegate perform:delegateMessage withArguments:(argArray copyWith:view)
|
|
394 |
].
|
|
395 |
^ self
|
|
396 |
]
|
|
397 |
].
|
89
|
398 |
].
|
|
399 |
].
|
|
400 |
|
|
401 |
"
|
|
402 |
if there is a controller, that one gets all user events
|
|
403 |
"
|
|
404 |
eventReceiver := view.
|
|
405 |
(controller := view controller) notNil ifTrue:[
|
115
|
406 |
(isKeyEvent
|
|
407 |
or:[isButtonEvent
|
|
408 |
or:[isPointerEvent
|
|
409 |
or:[(type == #focusIn)
|
|
410 |
or:[(type == #focusOut)]]]]) ifTrue:[
|
89
|
411 |
eventReceiver := controller.
|
72
|
412 |
]
|
89
|
413 |
].
|
|
414 |
|
|
415 |
"
|
115
|
416 |
finally, another one:
|
89
|
417 |
if the view has a transformation, edit the selector
|
|
418 |
from #foo to #deviceFoo...
|
|
419 |
This allows the view to handle the event either in device or
|
|
420 |
logical coordinates. (since the deviceFoo-messages default implementation
|
|
421 |
in PseudoView translates and resends).
|
|
422 |
Actually, I could always send deviceXXX without speed penalty
|
|
423 |
(event sending is no high frequency operation), but that just adds
|
|
424 |
another context to any debuggers walkback, making things less clear.
|
|
425 |
"
|
115
|
426 |
selector := type.
|
|
427 |
|
89
|
428 |
view transformation notNil ifTrue:[
|
115
|
429 |
(isKeyEvent
|
|
430 |
or:[isButtonEvent
|
144
|
431 |
or:[isPointerEvent
|
115
|
432 |
or:[(type == #'exposeX:y:width:height:')
|
|
433 |
or:[(type == #'graphicExposeX:y:width:height:')]]]]) ifTrue:[
|
|
434 |
selector := deviceMessage
|
89
|
435 |
]
|
|
436 |
].
|
115
|
437 |
eventReceiver perform:selector withArguments:argArray
|
|
438 |
! !
|
|
439 |
|
|
440 |
!WindowEvent methodsFor:'sending'!
|
|
441 |
|
|
442 |
sendEvent
|
144
|
443 |
"forward the event represented by the receiver to the views delegate,
|
|
444 |
the views controller or the view. Ignore any focusView."
|
115
|
445 |
|
|
446 |
self sendEventWithFocusOn:nil
|
|
447 |
!
|
|
448 |
|
|
449 |
sendEventWithFocusOn:focusView
|
144
|
450 |
"forward the event represented by the receiver to the views delegate,
|
|
451 |
the views controller or the view.
|
|
452 |
If focusView is nonNil, and the receiver is a keyboard event,
|
|
453 |
the event will be forwarded to the focusView instead
|
|
454 |
(or its delegate, or its controller)."
|
115
|
455 |
|
135
|
456 |
self class
|
|
457 |
sendEvent:type
|
|
458 |
arguments:arguments
|
|
459 |
view:view
|
|
460 |
withFocusOn:focusView
|
|
461 |
delegate:true
|
11
|
462 |
! !
|
|
463 |
|
|
464 |
!WindowEvent methodsFor:'private accessing'!
|
|
465 |
|
|
466 |
for:aView type:aSymbol arguments:argArray
|
144
|
467 |
"set the instance variables of the event"
|
11
|
468 |
|
|
469 |
view := aView.
|
|
470 |
type := aSymbol.
|
|
471 |
arguments := argArray
|
|
472 |
! !
|