206 isKeyEvent isButtonEvent isPointerEvent trans| |
206 isKeyEvent isButtonEvent isPointerEvent trans| |
207 |
207 |
208 isKeyEvent := isButtonEvent := isPointerEvent := false. |
208 isKeyEvent := isButtonEvent := isPointerEvent := false. |
209 |
209 |
210 (type == #'keyPress:x:y:') ifTrue:[ |
210 (type == #'keyPress:x:y:') ifTrue:[ |
211 isKeyEvent := true. |
211 isKeyEvent := true. |
212 deviceMessage := #'deviceKeyPress:x:y:'. |
212 deviceMessage := #'deviceKeyPress:x:y:'. |
213 delegateMessage := #'keyPress:x:y:view:'. |
213 delegateMessage := #'keyPress:x:y:view:'. |
214 delegateQuery := #'handlesKeyPress:inView:'. |
214 delegateQuery := #'handlesKeyPress:inView:'. |
215 ] ifFalse:[ (type == #'keyRelease:x:y:') ifTrue:[ |
215 ] ifFalse:[ (type == #'keyRelease:x:y:') ifTrue:[ |
216 isKeyEvent := true. |
216 isKeyEvent := true. |
217 deviceMessage := #'deviceKeyRelease:x:y:'. |
217 deviceMessage := #'deviceKeyRelease:x:y:'. |
218 delegateMessage := #'keyRelease:x:y:view:'. |
218 delegateMessage := #'keyRelease:x:y:view:'. |
219 delegateQuery := #'handlesKeyRelease:inView:'. |
219 delegateQuery := #'handlesKeyRelease:inView:'. |
220 ] ifFalse:[ (type == #'buttonMotion:x:y:') ifTrue:[ |
220 ] ifFalse:[ (type == #'buttonMotion:x:y:') ifTrue:[ |
221 isButtonEvent := true. |
221 isButtonEvent := true. |
222 deviceMessage := #'deviceButtonMotion:x:y:'. |
222 deviceMessage := #'deviceButtonMotion:x:y:'. |
223 delegateMessage := #'buttonMotion:x:y:view:'. |
223 delegateMessage := #'buttonMotion:x:y:view:'. |
224 delegateQuery := #'handlesButtonMotion:inView:'. |
224 delegateQuery := #'handlesButtonMotion:inView:'. |
225 ] ifFalse:[ (type == #'buttonPress:x:y:') ifTrue:[ |
225 ] ifFalse:[ (type == #'buttonPress:x:y:') ifTrue:[ |
226 isButtonEvent := true. |
226 isButtonEvent := true. |
227 deviceMessage := #'deviceButtonPress:x:y:'. |
227 deviceMessage := #'deviceButtonPress:x:y:'. |
228 delegateMessage := #'buttonPress:x:y:view:'. |
228 delegateMessage := #'buttonPress:x:y:view:'. |
229 delegateQuery := #'handlesButtonPress:inView:'. |
229 delegateQuery := #'handlesButtonPress:inView:'. |
230 ] ifFalse:[ (type == #'buttonRelease:x:y:') ifTrue:[ |
230 ] ifFalse:[ (type == #'buttonRelease:x:y:') ifTrue:[ |
231 isButtonEvent := true. |
231 isButtonEvent := true. |
232 deviceMessage := #'deviceButtonRelease:x:y:'. |
232 deviceMessage := #'deviceButtonRelease:x:y:'. |
233 delegateMessage := #'buttonRelease:x:y:view:'. |
233 delegateMessage := #'buttonRelease:x:y:view:'. |
234 delegateQuery := #'handlesButtonRelease:inView:'. |
234 delegateQuery := #'handlesButtonRelease:inView:'. |
235 ] ifFalse:[ (type == #'buttonShiftPress:x:y:') ifTrue:[ |
235 ] ifFalse:[ (type == #'buttonShiftPress:x:y:') ifTrue:[ |
236 isButtonEvent := true. |
236 isButtonEvent := true. |
237 deviceMessage := #'deviceButtonShiftPress:x:y:'. |
237 deviceMessage := #'deviceButtonShiftPress:x:y:'. |
238 delegateMessage := #'buttonShiftPress:x:y:view:'. |
238 delegateMessage := #'buttonShiftPress:x:y:view:'. |
239 delegateQuery := #'handlesButtonShiftPress:inView:'. |
239 delegateQuery := #'handlesButtonShiftPress:inView:'. |
240 ] ifFalse:[ (type == #'buttonMultiPress:x:y:') ifTrue:[ |
240 ] ifFalse:[ (type == #'buttonMultiPress:x:y:') ifTrue:[ |
241 isButtonEvent := true. |
241 isButtonEvent := true. |
242 deviceMessage := #'deviceButtonMultiPress:x:y:'. |
242 deviceMessage := #'deviceButtonMultiPress:x:y:'. |
243 delegateMessage := #'buttonMultiPress:x:y:view:'. |
243 delegateMessage := #'buttonMultiPress:x:y:view:'. |
244 delegateQuery := #'handlesButtonMultiPress:inView:'. |
244 delegateQuery := #'handlesButtonMultiPress:inView:'. |
245 ] ifFalse:[ (type == #'pointerEnter:x:y:') ifTrue:[ |
245 ] ifFalse:[ (type == #'pointerEnter:x:y:') ifTrue:[ |
246 isPointerEvent := true. |
246 isPointerEvent := true. |
247 deviceMessage := #'devicePointerEnter:x:y:'. |
247 deviceMessage := #'devicePointerEnter:x:y:'. |
248 delegateMessage := #'pointerEnter:x:y:view:'. |
248 delegateMessage := #'pointerEnter:x:y:view:'. |
249 delegateQuery := #'handlesPointerEnter:inView:'. |
249 delegateQuery := #'handlesPointerEnter:inView:'. |
250 ] ifFalse:[ (type == #'pointerLeave:') ifTrue:[ |
250 ] ifFalse:[ (type == #'pointerLeave:') ifTrue:[ |
251 isPointerEvent := true. |
251 isPointerEvent := true. |
252 deviceMessage := type. |
252 deviceMessage := type. |
253 delegateMessage := #'pointerLeave:view:'. |
253 delegateMessage := #'pointerLeave:view:'. |
254 delegateQuery := #'handlesPointerLeave:inView:'. |
254 delegateQuery := #'handlesPointerLeave:inView:'. |
255 ] ifFalse:[ (type == #'exposeX:y:width:height:') ifTrue:[ |
255 ] ifFalse:[ (type == #'exposeX:y:width:height:') ifTrue:[ |
256 deviceMessage := #'deviceExposeX:y:width:height:'. |
256 deviceMessage := #'deviceExposeX:y:width:height:'. |
257 ] ifFalse:[ (type == #'graphicsExposeX:y:width:height:final:') ifTrue:[ |
257 ] ifFalse:[ (type == #'graphicsExposeX:y:width:height:final:') ifTrue:[ |
258 deviceMessage := #'deviceGraphicsExposeX:y:width:height:final:'. |
258 deviceMessage := #'deviceGraphicsExposeX:y:width:height:final:'. |
259 ]]]]]]]]]]]. |
259 ]]]]]]]]]]]. |
260 |
260 |
261 " |
261 " |
262 if there is a focusView, and its a keyboard event, pass it |
262 if there is a focusView, and its a keyboard event, pass it |
263 to that view (or its controller, or its delegate). |
263 to that view (or its controller, or its delegate). |
264 In this case, a coordinate which is outside of |
264 In this case, a coordinate which is outside of |
265 the focusView (0 @ 0) is passed as x/y coordinates. |
265 the focusView (0 @ 0) is passed as x/y coordinates. |
266 " |
266 " |
267 (focusView notNil |
267 (focusView notNil |
268 and:[isKeyEvent]) ifTrue:[ |
268 and:[isKeyEvent]) ifTrue:[ |
269 self sendEvent:type |
269 self sendEvent:type |
270 arguments:(Array with:(argArray at:1) with:0 with:0) |
270 arguments:(Array with:(argArray at:1) with:0 with:0) |
271 view:focusView |
271 view:focusView |
272 withFocusOn:nil |
272 withFocusOn:nil |
273 delegate:doDelegate. |
273 delegate:doDelegate. |
274 ^ self |
274 ^ self |
275 ]. |
275 ]. |
276 |
276 |
277 doDelegate ifTrue:[ |
277 doDelegate ifTrue:[ |
278 " |
278 " |
279 handle delegated messages |
279 handle delegated messages |
280 " |
280 " |
281 (isKeyEvent |
281 (isKeyEvent |
282 or:[isButtonEvent |
282 or:[isButtonEvent |
283 or:[isPointerEvent]]) ifTrue:[ |
283 or:[isPointerEvent]]) ifTrue:[ |
284 delegate := view delegate. |
284 delegate := view delegate. |
285 |
285 |
286 " |
286 " |
287 what a kludge - sending to delegate requires |
287 what a kludge - sending to delegate requires |
288 another selector and an additional argument ... |
288 another selector and an additional argument ... |
289 " |
289 " |
290 (delegate notNil |
290 (delegate notNil |
291 and:[delegate respondsTo:delegateMessage]) ifTrue:[ |
291 and:[delegate respondsTo:delegateMessage]) ifTrue:[ |
292 " |
292 " |
293 is the delegate interested in that event ? |
293 is the delegate interested in that event ? |
294 (if it does not respond to the handlesXXX message, |
294 (if it does not respond to the handlesXXX message, |
295 we assume: NO) |
295 we assume: NO) |
296 " |
296 " |
297 ((delegate respondsTo:delegateQuery) |
297 ((delegate respondsTo:delegateQuery) |
298 and:[delegate perform:delegateQuery with:(argArray at:1) with:view]) ifTrue:[ |
298 and:[delegate perform:delegateQuery with:(argArray at:1) with:view]) ifTrue:[ |
299 " |
299 " |
300 mhmh ... have to convert to logical coordinates |
300 mhmh ... have to convert to logical coordinates |
301 " |
301 " |
302 (trans := view transformation) notNil ifTrue:[ |
302 (trans := view transformation) notNil ifTrue:[ |
303 argArray size > 2 ifTrue:[ |
303 argArray size > 2 ifTrue:[ |
304 argArray at:2 put:(trans applyInverseToX:(argArray at:2)). |
304 argArray at:2 put:(trans applyInverseToX:(argArray at:2)). |
305 argArray at:3 put:(trans applyInverseToY:(argArray at:3)). |
305 argArray at:3 put:(trans applyInverseToY:(argArray at:3)). |
306 ]. |
306 ]. |
307 ]. |
307 ]. |
308 argArray isNil ifTrue:[ |
308 ((delegateMessage startsWith:'key') |
309 delegate perform:delegateMessage with:view |
309 or:[(delegateMessage startsWith:'deviceKey')]) ifTrue:[ |
310 ] ifFalse:[ |
310 'delegate: ' print. |
311 delegate perform:delegateMessage withArguments:(argArray copyWith:view) |
311 delegate printCR. |
312 ]. |
312 delegateMessage printCR. |
313 ^ self |
313 argArray printCR. |
314 ] |
314 ]. |
315 ]. |
315 argArray isNil ifTrue:[ |
316 ]. |
316 delegate perform:delegateMessage with:view |
|
317 ] ifFalse:[ |
|
318 delegate perform:delegateMessage withArguments:(argArray copyWith:view) |
|
319 ]. |
|
320 ^ self |
|
321 ] |
|
322 ]. |
|
323 ]. |
317 ]. |
324 ]. |
318 |
325 |
319 " |
326 " |
320 if there is a controller, that one gets all user events |
327 if there is a controller, that one gets all user events |
321 " |
328 " |
322 eventReceiver := view. |
329 eventReceiver := view. |
323 (controller := view controller) notNil ifTrue:[ |
330 (controller := view controller) notNil ifTrue:[ |
324 (isKeyEvent |
331 (isKeyEvent |
325 or:[isButtonEvent |
332 or:[isButtonEvent |
326 or:[isPointerEvent |
333 or:[isPointerEvent |
327 or:[(type == #focusIn) |
334 or:[(type == #focusIn) |
328 or:[(type == #focusOut)]]]]) ifTrue:[ |
335 or:[(type == #focusOut)]]]]) ifTrue:[ |
329 eventReceiver := controller. |
336 eventReceiver := controller. |
330 ] |
337 ] |
331 ]. |
338 ]. |
332 |
339 |
333 " |
340 " |
334 finally, another one: |
341 finally, another one: |
335 if the view has a transformation, edit the selector |
342 if the view has a transformation, edit the selector |