--- a/WindowEvent.st Mon Mar 06 22:02:16 1995 +0100
+++ b/WindowEvent.st Tue Mar 07 22:57:31 1995 +0100
@@ -21,7 +21,7 @@
COPYRIGHT (c) 1993 by Claus Gittinger
All Rights Reserved
-$Header: /cvs/stx/stx/libview/WindowEvent.st,v 1.11 1995-02-06 00:38:02 claus Exp $
+$Header: /cvs/stx/stx/libview/WindowEvent.st,v 1.12 1995-03-07 21:56:53 claus Exp $
'!
!WindowEvent class methodsFor:'documentation'!
@@ -42,7 +42,7 @@
version
"
-$Header: /cvs/stx/stx/libview/WindowEvent.st,v 1.11 1995-02-06 00:38:02 claus Exp $
+$Header: /cvs/stx/stx/libview/WindowEvent.st,v 1.12 1995-03-07 21:56:53 claus Exp $
"
!
@@ -157,78 +157,127 @@
^ nil
! !
-!WindowEvent methodsFor:'sending'!
+!WindowEvent class methodsFor:'forwarding events'!
+
+sendEvent:type arguments:arguments view:view
+ "forward the event represented by type and arguments to the views delegate,
+ the views controller or the view.
-sendEvent
- "forward the event represented by the receiver to the delegate,
- the controller or the view. Only messages which are understood by
- the delegate are forwarded.
- Delegated messages get the original view as an extra argument."
+ If there is a delegate, only messages which are understood by it are
+ forwarded. Also, the delegate is asked if it is willing to handle the event
+ before.
+ Delegated messages get the original view as an extra argument.
+ Delegation has higher priority than controller forwarding."
- self sendEventWithFocusOn:nil
+ self sendEvent:type arguments:arguments view:view withFocusOn:nil
!
-sendEventWithFocusOn:focusView
- "forward the event represented by the receiver to the delegate,
- the controller or the view. If focusView is nonNil, and its a keyboard
- event, the event is forwarded to it (but not if there is a delegate).
+sendEvent:type arguments:argArray view:view withFocusOn:focusView
+ "forward the event represented by type and arguments to the views delegate,
+ the views controller or the view.
+ If focusView is nonNil, and it is a keyboard event, it is forwarded to this
+ view (but not if there was a delegate in the first place).
+
If there is a delegate, only messages which are understood by it are
- forwarded. Delegated messages get the original view as an extra argument.
+ forwarded. Also, the delegate is asked if it is willing to handle the event
+ before.
+ Delegated messages get the original view as an extra argument.
Delegation has higher priority than both controller or focusView
forwarding."
- |delegate selector eventReceiver controller|
+ |delegate selector delegateMessage delegateQuery
+ eventReceiver controller deviceMessage
+ isKeyEvent isButtonEvent isPointerEvent trans|
+
+ isKeyEvent := isButtonEvent := isPointerEvent := false.
- selector := type.
+ (type == #'keyPress:x:y:') ifTrue:[
+ isKeyEvent := true.
+ deviceMessage := #'deviceKeyPress:x:y:'.
+ delegateMessage := #'keyPress:x:y:view:'.
+ delegateQuery := #'handlesKeyPress:inView:'.
+ ] ifFalse:[ (type == #'keyRelease:x:y:') ifTrue:[
+ isKeyEvent := true.
+ deviceMessage := #'deviceKeyRelease:x:y:'.
+ delegateMessage := #'keyRelease:x:y:view:'.
+ delegateQuery := #'handlesKeyRelease:inView:'.
+ ] ifFalse:[ (type == #'buttonPress:x:y:') ifTrue:[
+ isButtonEvent := true.
+ deviceMessage := #'deviceButtonPress:x:y:'.
+ delegateMessage := #'buttonPress:x:y:view:'.
+ delegateQuery := #'handlesButtonPress:inView:'.
+ ] ifFalse:[ (type == #'buttonRelease:x:y:') ifTrue:[
+ isButtonEvent := true.
+ deviceMessage := #'deviceButtonRelease:x:y:'.
+ delegateMessage := #'buttonRelease:x:y:view:'.
+ delegateQuery := #'handlesButtonRelease:inView:'.
+ ] ifFalse:[ (type == #'buttonShiftPress:x:y:') ifTrue:[
+ isButtonEvent := true.
+ deviceMessage := #'deviceButtonShiftPress:x:y:'.
+ delegateMessage := #'buttonShiftPress:x:y:view:'.
+ delegateQuery := #'handlesButtonShiftPress:inView:'.
+ ] ifFalse:[ (type == #'buttonMultiPress:x:y:') ifTrue:[
+ isButtonEvent := true.
+ deviceMessage := #'deviceButtonMultiPress:x:y:'.
+ delegateMessage := #'buttonMultiPress:x:y:view:'.
+ delegateQuery := #'handlesButtonMultiPress:inView:'.
+ ] ifFalse:[ (type == #'buttonMotion:x:y:') ifTrue:[
+ isButtonEvent := true.
+ deviceMessage := #'deviceButtonMotion:x:y:'.
+ delegateMessage := #'buttonMotion:x:y:view:'.
+ delegateQuery := #'handlesButtonMotion:inView:'.
+ ] ifFalse:[ (type == #'pointerEnter:x:y:') ifTrue:[
+ isPointerEvent := true.
+ deviceMessage := #'devicePointerEnter:x:y:'.
+ delegateMessage := #'pointerEnter:x:y:view:'.
+ delegateQuery := #'handlesPointerEnter:inView:'.
+ ] ifFalse:[ (type == #'pointerLeave:') ifTrue:[
+ isPointerEvent := true.
+ delegateMessage := #'pointerLeave:view:'.
+ delegateQuery := #'handlesPointerLeave:inView:'.
+ ] ifFalse:[ (type == #'exposeX:y:width:height:') ifTrue:[
+ deviceMessage := #'deviceExposeX:y:width:height:'.
+ ] ifFalse:[ (type == #'graphicExposeX:y:width:height:') ifTrue:[
+ deviceMessage := #'deviceGraphicExposeX:y:width:height:'.
+ ]]]]]]]]]]].
- delegate := view delegate.
- delegate notNil ifTrue:[
+ "
+ handle delegated messages
+ "
+ (isKeyEvent
+ or:[isButtonEvent
+ or:[isPointerEvent]]) ifTrue:[
+ delegate := view delegate.
+
"
- what a kludge - sending to delegate needs another
- selector and an additional argument.
- have to edit the selector ...
+ what a kludge - sending to delegate requires
+ another selector and an additional argument ...
"
- (selector endsWith:':') ifTrue:[
- selector := (selector , 'view:') asSymbol.
- ] ifFalse:[
- selector := (selector , 'View:') asSymbol.
- ].
- (delegate respondsTo:selector) ifTrue:[
+ (delegate respondsTo:delegateMessage) ifTrue:[
"
- mhmh have to convert to logical coordinates ...
- "
- view transformation notNil ifTrue:[
- (#(
- #'buttonPress:x:y:'
- #'buttonRelease:x:y:'
- #'buttonShiftPress:x:y:'
- #'buttonMultiPress:x:y:'
- #'buttonMotion:x:y:'
- #'keyPress:x:y:'
- #'keyRelease:x:y:'
- #'pointerEnter:x:y:'
- #'exposeX:y:width:height:'
- #'graphicExposeX:y:width:height:'
- )includes:type) ifTrue:[
- arguments at:2 put:(view transformation applyInverseToX:(arguments at:2)).
- arguments at:3 put:(view transformation applyInverseToY:(arguments at:3)).
- (#(
- #'exposeX:y:width:height:'
- #'graphicExposeX:y:width:height:'
- )includes:type) ifTrue:[
- arguments at:4 put:(view transformation applyInverseScaleX:(arguments at:4)).
- arguments at:5 put:(view transformation applyInverseScaleY:(arguments at:5)).
+ is the delegate interrested in that event ?
+ (if it does not respond to the handlesXXX message,
+ we assume: yes)
+ "
+ ((delegate respondsTo:delegateQuery) not
+ or:[delegate perform:delegateQuery with:view]) ifTrue:[
+ "
+ mhmh ... have to convert to logical coordinates
+ "
+ (trans := view transformation) notNil ifTrue:[
+ argArray size > 2 ifTrue:[
+ argArray at:2 put:(trans applyInverseToX:(argArray at:2)).
+ argArray at:3 put:(trans applyInverseToY:(argArray at:3)).
].
].
- ].
- arguments isNil ifTrue:[
- delegate perform:selector with:view
- ] ifFalse:[
- delegate perform:selector withArguments:(arguments copyWith:view)
- ].
- ^ self
+ argArray isNil ifTrue:[
+ delegate perform:delegateMessage with:view
+ ] ifFalse:[
+ delegate perform:delegateMessage withArguments:(argArray copyWith:view)
+ ].
+ ^ self
+ ]
].
- selector := type.
].
"
@@ -236,46 +285,37 @@
"
eventReceiver := view.
(controller := view controller) notNil ifTrue:[
- (#(
- #'buttonPress:x:y:'
- #'buttonRelease:x:y:'
- #'buttonShiftPress:x:y:'
- #'buttonMultiPress:x:y:'
- #'buttonMotion:x:y:'
- #'keyPress:x:y:'
- #'keyRelease:x:y:'
- #'focusIn'
- #'focusOut'
- #'pointerEnter:x:y:'
- #'pointerLeave:'
- ) includes:selector) ifTrue:[
+ (isKeyEvent
+ or:[isButtonEvent
+ or:[isPointerEvent
+ or:[(type == #focusIn)
+ or:[(type == #focusOut)]]]]) ifTrue:[
eventReceiver := controller.
]
].
"
if there is a focusView, and its a keyboard event, pass it
- to that view (or its controller). In this case, some coordinate which is outside of
- the focusView is passed as x/y coordinates.
+ to that view (or its controller).
+ In this case, a coordinate which is outside of
+ the focusView (-1 @ -1) is passed as x/y coordinates.
+ Q: should we follow its delegate again ?
"
- focusView notNil ifTrue:[
- (#(#'keyPress:x:y:'
- #'keyRelease:x:y:'
- )includes:selector) ifTrue:[
- eventReceiver := focusView.
- (controller := focusView controller) notNil ifTrue:[
- eventReceiver := controller.
- ].
- eventReceiver perform:selector
- withArguments:(Array with:(arguments at:1)
- with:-1
- with:-1).
- ^ self
- ]
+ (focusView notNil
+ and:[isKeyEvent]) ifTrue:[
+ eventReceiver := focusView.
+ (controller := focusView controller) notNil ifTrue:[
+ eventReceiver := controller.
+ ].
+ eventReceiver perform:type
+ withArguments:(Array with:(argArray at:1)
+ with:-1
+ with:-1).
+ ^ self
].
"
- another one:
+ finally, another one:
if the view has a transformation, edit the selector
from #foo to #deviceFoo...
This allows the view to handle the event either in device or
@@ -285,25 +325,35 @@
(event sending is no high frequency operation), but that just adds
another context to any debuggers walkback, making things less clear.
"
+ selector := type.
+
view transformation notNil ifTrue:[
- (#(
- #'buttonPress:x:y:'
- #'buttonRelease:x:y:'
- #'buttonShiftPress:x:y:'
- #'buttonMultiPress:x:y:'
- #'buttonMotion:x:y:'
- #'keyPress:x:y:'
- #'keyRelease:x:y:'
- #'exposeX:y:width:height:'
- #'graphicExposeX:y:width:height:'
- #'pointerEnter:x:y:'
- ) includes:selector) ifTrue:[
- selector := selector asString.
- selector at:1 put:(selector at:1) asUppercase.
- selector := ('device' , selector) asSymbol
+ (isKeyEvent
+ or:[isButtonEvent
+ or:[(type == #'pointerEnter:x:y:')
+ or:[(type == #'exposeX:y:width:height:')
+ or:[(type == #'graphicExposeX:y:width:height:')]]]]) ifTrue:[
+ selector := deviceMessage
]
].
- eventReceiver perform:selector withArguments:arguments
+ eventReceiver perform:selector withArguments:argArray
+! !
+
+!WindowEvent methodsFor:'sending'!
+
+sendEvent
+ "forward the event represented by the receiver to the delegate,
+ the controller or the view."
+
+ self sendEventWithFocusOn:nil
+!
+
+sendEventWithFocusOn:focusView
+ "forward the event represented by the receiver to the delegate,
+ the controller or the view. If focusView is nonNil, and its a keyboard
+ event, the event is forwarded to it."
+
+ self class sendEvent:type arguments:arguments view:view withFocusOn:focusView
! !
!WindowEvent methodsFor:'private accessing'!