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 |
|
141
|
24 |
$Header: /cvs/stx/stx/libview/WindowEvent.st,v 1.16 1995-05-10 02:26:23 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 |
"
|
141
|
45 |
$Header: /cvs/stx/stx/libview/WindowEvent.st,v 1.16 1995-05-10 02:26:23 claus Exp $
|
46
|
46 |
"
|
|
47 |
!
|
|
48 |
|
|
49 |
documentation
|
|
50 |
"
|
|
51 |
Instances of WindowEvent are created for every event coming from
|
72
|
52 |
the graphics device, to be handled by a windowGroup.
|
|
53 |
Usually, they are queued by a sensor, and processed in some event loop
|
|
54 |
in the window group.
|
46
|
55 |
"
|
|
56 |
! !
|
|
57 |
|
11
|
58 |
!WindowEvent class methodsFor:'instance creation'!
|
|
59 |
|
|
60 |
for:aView type:aSymbol arguments:argArray
|
|
61 |
"create and return a new windowEvent for sending
|
|
62 |
aSymbol-message with arguments to aView"
|
|
63 |
|
46
|
64 |
^ (self new) for:aView type:aSymbol arguments:argArray
|
|
65 |
!
|
|
66 |
|
72
|
67 |
for:aView type:aSymbol
|
|
68 |
"create and return a new windowEvent for sending
|
|
69 |
aSymbol-message with no arguments to aView"
|
|
70 |
|
|
71 |
^ (self new) for:aView type:aSymbol arguments:#()
|
|
72 |
!
|
|
73 |
|
46
|
74 |
damageFor:aView rectangle:aRectangle
|
|
75 |
"create and return a new damage Event for aRectangle
|
|
76 |
in aView"
|
|
77 |
|
|
78 |
^ (self new) for:aView type:#damage arguments:aRectangle
|
|
79 |
|
11
|
80 |
! !
|
|
81 |
|
72
|
82 |
!WindowEvent methodsFor:'queries'!
|
|
83 |
|
|
84 |
isKeyEvent
|
|
85 |
"return true, if this event is a keyboard event"
|
|
86 |
|
89
|
87 |
^ (type == #keyPress:x:y:) or:[type == #keyRelease:x:y:]
|
|
88 |
!
|
|
89 |
|
|
90 |
isKeyPressEvent
|
|
91 |
"return true, if this event is a keyboard event"
|
|
92 |
|
|
93 |
^ (type == #keyPress:x:y:)
|
|
94 |
!
|
|
95 |
|
|
96 |
isButtonEvent
|
|
97 |
"return true, if this event is a button event"
|
|
98 |
|
|
99 |
^ (type == #buttonPress:x:y:)
|
|
100 |
or:[type == #buttonRelease:x:y:
|
|
101 |
or:[type == #'buttonShiftPress:x:y:'
|
|
102 |
or:[type == #'buttonMultiPress:x:y:'
|
|
103 |
or:[type == #'buttonMotion:x:y:']]]]
|
72
|
104 |
!
|
|
105 |
|
|
106 |
isDamage
|
|
107 |
"return true, if this is a damage event"
|
|
108 |
|
|
109 |
^ type == #damage
|
|
110 |
! !
|
|
111 |
|
28
|
112 |
!WindowEvent methodsFor:'accessing'!
|
|
113 |
|
|
114 |
view
|
|
115 |
"return the view, for which the event is for"
|
|
116 |
|
|
117 |
^ view
|
|
118 |
!
|
|
119 |
|
72
|
120 |
view:aView
|
|
121 |
"set the view, for which the event is for"
|
|
122 |
|
|
123 |
view := aView
|
|
124 |
!
|
|
125 |
|
28
|
126 |
type
|
|
127 |
"return the type of the event"
|
|
128 |
|
|
129 |
^ type
|
|
130 |
!
|
|
131 |
|
|
132 |
arguments
|
|
133 |
"return the arguments of the event"
|
|
134 |
|
|
135 |
^ arguments
|
|
136 |
!
|
|
137 |
|
|
138 |
arguments:anArray
|
|
139 |
"set the arguments"
|
|
140 |
|
|
141 |
arguments := anArray
|
46
|
142 |
!
|
|
143 |
|
|
144 |
rectangle
|
|
145 |
"return the damage rectangle"
|
|
146 |
|
|
147 |
^ arguments "consider this a kludge"
|
89
|
148 |
!
|
|
149 |
|
|
150 |
key
|
|
151 |
"return the key of the key-event. For non key-events, nil is returned."
|
|
152 |
|
|
153 |
((type == #keyPress:x:y:)
|
|
154 |
or:[type == #keyRelease:x:y:]) ifTrue:[
|
|
155 |
^ arguments at:1
|
|
156 |
].
|
|
157 |
^ nil
|
28
|
158 |
! !
|
|
159 |
|
115
|
160 |
!WindowEvent class methodsFor:'forwarding events'!
|
|
161 |
|
|
162 |
sendEvent:type arguments:arguments view:view
|
|
163 |
"forward the event represented by type and arguments to the views delegate,
|
|
164 |
the views controller or the view.
|
11
|
165 |
|
115
|
166 |
If there is a delegate, only messages which are understood by it are
|
|
167 |
forwarded. Also, the delegate is asked if it is willing to handle the event
|
|
168 |
before.
|
|
169 |
Delegated messages get the original view as an extra argument.
|
|
170 |
Delegation has higher priority than controller forwarding."
|
11
|
171 |
|
135
|
172 |
^ self
|
|
173 |
sendEvent:type
|
|
174 |
arguments:arguments
|
|
175 |
view:view
|
|
176 |
withFocusOn:nil
|
|
177 |
delegate:true
|
89
|
178 |
!
|
|
179 |
|
115
|
180 |
sendEvent:type arguments:argArray view:view withFocusOn:focusView
|
|
181 |
"forward the event represented by type and arguments to the views delegate,
|
|
182 |
the views controller or the view.
|
|
183 |
If focusView is nonNil, and it is a keyboard event, it is forwarded to this
|
141
|
184 |
view (even if there is a delegate).
|
115
|
185 |
|
89
|
186 |
If there is a delegate, only messages which are understood by it are
|
115
|
187 |
forwarded. Also, the delegate is asked if it is willing to handle the event
|
|
188 |
before.
|
|
189 |
Delegated messages get the original view as an extra argument.
|
89
|
190 |
Delegation has higher priority than both controller or focusView
|
|
191 |
forwarding."
|
|
192 |
|
135
|
193 |
^ self
|
|
194 |
sendEvent:type
|
|
195 |
arguments:argArray
|
|
196 |
view:view
|
|
197 |
withFocusOn:focusView
|
|
198 |
delegate:true
|
|
199 |
!
|
|
200 |
|
|
201 |
sendEvent:type arguments:argArray view:view withFocusOn:focusView delegate:doDelegate
|
|
202 |
"forward the event represented by type and arguments to the views delegate,
|
|
203 |
the views controller or the view.
|
|
204 |
If focusView is nonNil, and it is a keyboard event, it is forwarded to this
|
|
205 |
view (but not if there was a delegate in the first place).
|
|
206 |
|
|
207 |
If doDelegate is true, keyboard and button events are forwarded to a
|
|
208 |
delegate object (if non-nil). DoDelegate may be passed as true, to
|
|
209 |
handle events which are already delegated.
|
|
210 |
If there is a delegate, only messages which are understood by it are
|
|
211 |
forwarded. Also, the delegate is asked if it is willing to handle the event
|
|
212 |
before.
|
|
213 |
Delegated messages get the original view as an extra argument.
|
|
214 |
Delegation has higher priority than both controller or focusView
|
|
215 |
forwarding."
|
|
216 |
|
115
|
217 |
|delegate selector delegateMessage delegateQuery
|
|
218 |
eventReceiver controller deviceMessage
|
|
219 |
isKeyEvent isButtonEvent isPointerEvent trans|
|
|
220 |
|
|
221 |
isKeyEvent := isButtonEvent := isPointerEvent := false.
|
11
|
222 |
|
115
|
223 |
(type == #'keyPress:x:y:') ifTrue:[
|
|
224 |
isKeyEvent := true.
|
|
225 |
deviceMessage := #'deviceKeyPress:x:y:'.
|
|
226 |
delegateMessage := #'keyPress:x:y:view:'.
|
|
227 |
delegateQuery := #'handlesKeyPress:inView:'.
|
|
228 |
] ifFalse:[ (type == #'keyRelease:x:y:') ifTrue:[
|
|
229 |
isKeyEvent := true.
|
|
230 |
deviceMessage := #'deviceKeyRelease:x:y:'.
|
|
231 |
delegateMessage := #'keyRelease:x:y:view:'.
|
|
232 |
delegateQuery := #'handlesKeyRelease:inView:'.
|
141
|
233 |
] ifFalse:[ (type == #'buttonMotion:x:y:') ifTrue:[
|
|
234 |
isButtonEvent := true.
|
|
235 |
deviceMessage := #'deviceButtonMotion:x:y:'.
|
|
236 |
delegateMessage := #'buttonMotion:x:y:view:'.
|
|
237 |
delegateQuery := #'handlesButtonMotion:inView:'.
|
115
|
238 |
] ifFalse:[ (type == #'buttonPress:x:y:') ifTrue:[
|
|
239 |
isButtonEvent := true.
|
|
240 |
deviceMessage := #'deviceButtonPress:x:y:'.
|
|
241 |
delegateMessage := #'buttonPress:x:y:view:'.
|
|
242 |
delegateQuery := #'handlesButtonPress:inView:'.
|
|
243 |
] ifFalse:[ (type == #'buttonRelease:x:y:') ifTrue:[
|
|
244 |
isButtonEvent := true.
|
|
245 |
deviceMessage := #'deviceButtonRelease:x:y:'.
|
|
246 |
delegateMessage := #'buttonRelease:x:y:view:'.
|
|
247 |
delegateQuery := #'handlesButtonRelease:inView:'.
|
|
248 |
] ifFalse:[ (type == #'buttonShiftPress:x:y:') ifTrue:[
|
|
249 |
isButtonEvent := true.
|
|
250 |
deviceMessage := #'deviceButtonShiftPress:x:y:'.
|
|
251 |
delegateMessage := #'buttonShiftPress:x:y:view:'.
|
|
252 |
delegateQuery := #'handlesButtonShiftPress:inView:'.
|
|
253 |
] ifFalse:[ (type == #'buttonMultiPress:x:y:') ifTrue:[
|
|
254 |
isButtonEvent := true.
|
|
255 |
deviceMessage := #'deviceButtonMultiPress:x:y:'.
|
|
256 |
delegateMessage := #'buttonMultiPress:x:y:view:'.
|
|
257 |
delegateQuery := #'handlesButtonMultiPress:inView:'.
|
|
258 |
] ifFalse:[ (type == #'pointerEnter:x:y:') ifTrue:[
|
|
259 |
isPointerEvent := true.
|
|
260 |
deviceMessage := #'devicePointerEnter:x:y:'.
|
|
261 |
delegateMessage := #'pointerEnter:x:y:view:'.
|
|
262 |
delegateQuery := #'handlesPointerEnter:inView:'.
|
|
263 |
] ifFalse:[ (type == #'pointerLeave:') ifTrue:[
|
|
264 |
isPointerEvent := true.
|
|
265 |
delegateMessage := #'pointerLeave:view:'.
|
|
266 |
delegateQuery := #'handlesPointerLeave:inView:'.
|
|
267 |
] ifFalse:[ (type == #'exposeX:y:width:height:') ifTrue:[
|
|
268 |
deviceMessage := #'deviceExposeX:y:width:height:'.
|
|
269 |
] ifFalse:[ (type == #'graphicExposeX:y:width:height:') ifTrue:[
|
|
270 |
deviceMessage := #'deviceGraphicExposeX:y:width:height:'.
|
|
271 |
]]]]]]]]]]].
|
89
|
272 |
|
141
|
273 |
"
|
|
274 |
if there is a focusView, and its a keyboard event, pass it
|
|
275 |
to that view (or its controller, or its delegate).
|
|
276 |
In this case, a coordinate which is outside of
|
|
277 |
the focusView (-1 @ -1) is passed as x/y coordinates.
|
|
278 |
"
|
|
279 |
(focusView notNil
|
|
280 |
and:[isKeyEvent]) ifTrue:[
|
|
281 |
self sendEvent:type
|
|
282 |
arguments:(Array with:(argArray at:1)
|
|
283 |
with:-1
|
|
284 |
with:-1)
|
|
285 |
view:focusView
|
|
286 |
withFocusOn:nil
|
|
287 |
delegate:doDelegate.
|
|
288 |
^ self
|
|
289 |
].
|
|
290 |
|
135
|
291 |
doDelegate ifTrue:[
|
|
292 |
"
|
|
293 |
handle delegated messages
|
78
|
294 |
"
|
135
|
295 |
(isKeyEvent
|
|
296 |
or:[isButtonEvent
|
|
297 |
or:[isPointerEvent]]) ifTrue:[
|
|
298 |
delegate := view delegate.
|
|
299 |
|
89
|
300 |
"
|
135
|
301 |
what a kludge - sending to delegate requires
|
|
302 |
another selector and an additional argument ...
|
115
|
303 |
"
|
140
|
304 |
(delegate notNil
|
|
305 |
and:[delegate respondsTo:delegateMessage]) ifTrue:[
|
135
|
306 |
"
|
|
307 |
is the delegate interrested in that event ?
|
|
308 |
(if it does not respond to the handlesXXX message,
|
|
309 |
we assume: NO)
|
115
|
310 |
"
|
135
|
311 |
((delegate respondsTo:delegateQuery)
|
|
312 |
and:[delegate perform:delegateQuery with:(argArray at:1) with:view]) ifTrue:[
|
|
313 |
"
|
|
314 |
mhmh ... have to convert to logical coordinates
|
|
315 |
"
|
|
316 |
(trans := view transformation) notNil ifTrue:[
|
|
317 |
argArray size > 2 ifTrue:[
|
|
318 |
argArray at:2 put:(trans applyInverseToX:(argArray at:2)).
|
|
319 |
argArray at:3 put:(trans applyInverseToY:(argArray at:3)).
|
|
320 |
].
|
89
|
321 |
].
|
135
|
322 |
argArray isNil ifTrue:[
|
|
323 |
delegate perform:delegateMessage with:view
|
|
324 |
] ifFalse:[
|
|
325 |
delegate perform:delegateMessage withArguments:(argArray copyWith:view)
|
|
326 |
].
|
|
327 |
^ self
|
|
328 |
]
|
|
329 |
].
|
89
|
330 |
].
|
|
331 |
].
|
|
332 |
|
|
333 |
"
|
|
334 |
if there is a controller, that one gets all user events
|
|
335 |
"
|
|
336 |
eventReceiver := view.
|
|
337 |
(controller := view controller) notNil ifTrue:[
|
115
|
338 |
(isKeyEvent
|
|
339 |
or:[isButtonEvent
|
|
340 |
or:[isPointerEvent
|
|
341 |
or:[(type == #focusIn)
|
|
342 |
or:[(type == #focusOut)]]]]) ifTrue:[
|
89
|
343 |
eventReceiver := controller.
|
72
|
344 |
]
|
89
|
345 |
].
|
|
346 |
|
|
347 |
"
|
115
|
348 |
finally, another one:
|
89
|
349 |
if the view has a transformation, edit the selector
|
|
350 |
from #foo to #deviceFoo...
|
|
351 |
This allows the view to handle the event either in device or
|
|
352 |
logical coordinates. (since the deviceFoo-messages default implementation
|
|
353 |
in PseudoView translates and resends).
|
|
354 |
Actually, I could always send deviceXXX without speed penalty
|
|
355 |
(event sending is no high frequency operation), but that just adds
|
|
356 |
another context to any debuggers walkback, making things less clear.
|
|
357 |
"
|
115
|
358 |
selector := type.
|
|
359 |
|
89
|
360 |
view transformation notNil ifTrue:[
|
115
|
361 |
(isKeyEvent
|
|
362 |
or:[isButtonEvent
|
|
363 |
or:[(type == #'pointerEnter:x:y:')
|
|
364 |
or:[(type == #'exposeX:y:width:height:')
|
|
365 |
or:[(type == #'graphicExposeX:y:width:height:')]]]]) ifTrue:[
|
|
366 |
selector := deviceMessage
|
89
|
367 |
]
|
|
368 |
].
|
115
|
369 |
eventReceiver perform:selector withArguments:argArray
|
|
370 |
! !
|
|
371 |
|
|
372 |
!WindowEvent methodsFor:'sending'!
|
|
373 |
|
|
374 |
sendEvent
|
|
375 |
"forward the event represented by the receiver to the delegate,
|
|
376 |
the controller or the view."
|
|
377 |
|
|
378 |
self sendEventWithFocusOn:nil
|
|
379 |
!
|
|
380 |
|
|
381 |
sendEventWithFocusOn:focusView
|
|
382 |
"forward the event represented by the receiver to the delegate,
|
141
|
383 |
the controller or the view. If focusView is nonNil, and it is a keyboard
|
|
384 |
event, the event is forwarded to the focusView instead of the target view."
|
115
|
385 |
|
135
|
386 |
self class
|
|
387 |
sendEvent:type
|
|
388 |
arguments:arguments
|
|
389 |
view:view
|
|
390 |
withFocusOn:focusView
|
|
391 |
delegate:true
|
11
|
392 |
! !
|
|
393 |
|
|
394 |
!WindowEvent methodsFor:'private accessing'!
|
|
395 |
|
|
396 |
for:aView type:aSymbol arguments:argArray
|
|
397 |
"set the instances of the window event"
|
|
398 |
|
|
399 |
view := aView.
|
|
400 |
type := aSymbol.
|
|
401 |
arguments := argArray
|
|
402 |
! !
|