WindowEvent.st
changeset 89 ea2bf46eb669
parent 84 e2d388e4e03f
child 115 1d93fd8c5371
equal deleted inserted replaced
88:8f9c629a4245 89:ea2bf46eb669
    19 
    19 
    20 WindowEvent comment:'
    20 WindowEvent comment:'
    21 COPYRIGHT (c) 1993 by Claus Gittinger
    21 COPYRIGHT (c) 1993 by Claus Gittinger
    22 	      All Rights Reserved
    22 	      All Rights Reserved
    23 
    23 
    24 $Header: /cvs/stx/stx/libview/WindowEvent.st,v 1.10 1994-11-22 14:32:22 claus Exp $
    24 $Header: /cvs/stx/stx/libview/WindowEvent.st,v 1.11 1995-02-06 00:38:02 claus Exp $
    25 '!
    25 '!
    26 
    26 
    27 !WindowEvent class methodsFor:'documentation'!
    27 !WindowEvent class methodsFor:'documentation'!
    28 
    28 
    29 copyright
    29 copyright
    40 "
    40 "
    41 !
    41 !
    42 
    42 
    43 version
    43 version
    44 "
    44 "
    45 $Header: /cvs/stx/stx/libview/WindowEvent.st,v 1.10 1994-11-22 14:32:22 claus Exp $
    45 $Header: /cvs/stx/stx/libview/WindowEvent.st,v 1.11 1995-02-06 00:38:02 claus Exp $
    46 "
    46 "
    47 !
    47 !
    48 
    48 
    49 documentation
    49 documentation
    50 "
    50 "
    82 !WindowEvent methodsFor:'queries'!
    82 !WindowEvent methodsFor:'queries'!
    83 
    83 
    84 isKeyEvent
    84 isKeyEvent
    85     "return true, if this event is a keyboard event"
    85     "return true, if this event is a keyboard event"
    86 
    86 
    87     ^ (type == #keyPress:x:y) or:[type == #keyRelease:x:y]
    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:']]]]
    88 !
   104 !
    89 
   105 
    90 isDamage
   106 isDamage
    91     "return true, if this is a damage event"
   107     "return true, if this is a damage event"
    92 
   108 
   127 
   143 
   128 rectangle
   144 rectangle
   129     "return the damage rectangle"
   145     "return the damage rectangle"
   130 
   146 
   131     ^ arguments "consider this a kludge"
   147     ^ arguments "consider this a kludge"
       
   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
   132 ! !
   158 ! !
   133 
   159 
   134 !WindowEvent methodsFor:'sending'!
   160 !WindowEvent methodsFor:'sending'!
   135 
   161 
   136 sendEvent
   162 sendEvent
   137     "forward the event represented by the receiver to the delegate,
   163     "forward the event represented by the receiver to the delegate,
   138      the controller or the view.
   164      the controller or the view. Only messages which are understood by
       
   165      the delegate are forwarded.
   139      Delegated messages get the original view as an extra argument."
   166      Delegated messages get the original view as an extra argument."
   140 
   167 
       
   168     self sendEventWithFocusOn:nil
       
   169 !
       
   170 
       
   171 sendEventWithFocusOn:focusView
       
   172     "forward the event represented by the receiver to the delegate,
       
   173      the controller or the view. If focusView is nonNil, and its a keyboard
       
   174      event, the event is forwarded to it (but not if there is a delegate).
       
   175      If there is a delegate, only messages which are understood by it are 
       
   176      forwarded. Delegated messages get the original view as an extra argument.
       
   177      Delegation has higher priority than both controller or focusView 
       
   178      forwarding."
       
   179 
   141     |delegate selector eventReceiver controller|
   180     |delegate selector eventReceiver controller|
   142 
   181 
   143     selector := type.
   182     selector := type.
       
   183 
   144     delegate := view delegate.
   184     delegate := view delegate.
   145     delegate notNil ifTrue:[
   185     delegate notNil ifTrue:[
   146 	"
   186 	"
   147 	 what a kludge - sending to delegate needs another
   187 	 what a kludge - sending to delegate needs another
   148 	 selector and an additional argument.
   188 	 selector and an additional argument.
   151 	(selector endsWith:':') ifTrue:[
   191 	(selector endsWith:':') ifTrue:[
   152 	    selector := (selector , 'view:') asSymbol.
   192 	    selector := (selector , 'view:') asSymbol.
   153 	] ifFalse:[
   193 	] ifFalse:[
   154 	    selector := (selector , 'View:') asSymbol.
   194 	    selector := (selector , 'View:') asSymbol.
   155 	].
   195 	].
   156 	arguments isNil ifTrue:[
   196 	(delegate respondsTo:selector) ifTrue:[
   157 	    delegate perform:selector with:view
   197 	    "
   158 	] ifFalse:[
   198 	     mhmh have to convert to logical coordinates ...
   159 	    delegate perform:selector withArguments:(arguments copyWith:view)
   199 	    "        
       
   200 	    view transformation notNil ifTrue:[
       
   201 		(#(
       
   202 		  #'buttonPress:x:y:'
       
   203 		  #'buttonRelease:x:y:'
       
   204 		  #'buttonShiftPress:x:y:'
       
   205 		  #'buttonMultiPress:x:y:'
       
   206 		  #'buttonMotion:x:y:'
       
   207 		  #'keyPress:x:y:'
       
   208 		  #'keyRelease:x:y:'
       
   209 		  #'pointerEnter:x:y:'
       
   210 		  #'exposeX:y:width:height:'
       
   211 		  #'graphicExposeX:y:width:height:'
       
   212 		)includes:type) ifTrue:[
       
   213 		    arguments at:2 put:(view transformation applyInverseToX:(arguments at:2)).
       
   214 		    arguments at:3 put:(view transformation applyInverseToY:(arguments at:3)).
       
   215 		    (#(
       
   216 		      #'exposeX:y:width:height:'
       
   217 		      #'graphicExposeX:y:width:height:'
       
   218 		    )includes:type) ifTrue:[
       
   219 			arguments at:4 put:(view transformation applyInverseScaleX:(arguments at:4)).
       
   220 			arguments at:5 put:(view transformation applyInverseScaleY:(arguments at:5)).
       
   221 		    ].
       
   222 		].
       
   223 	    ].
       
   224 	    arguments isNil ifTrue:[
       
   225 		delegate perform:selector with:view
       
   226 	    ] ifFalse:[
       
   227 		delegate perform:selector withArguments:(arguments copyWith:view)
       
   228 	    ].
       
   229 	    ^ self
       
   230 	].
       
   231 	selector := type.
       
   232     ].
       
   233 
       
   234     "
       
   235      if there is a controller, that one gets all user events
       
   236     "
       
   237     eventReceiver := view.
       
   238     (controller := view controller) notNil ifTrue:[  
       
   239 	(#(
       
   240 	  #'buttonPress:x:y:'
       
   241 	  #'buttonRelease:x:y:'
       
   242 	  #'buttonShiftPress:x:y:'
       
   243 	  #'buttonMultiPress:x:y:'
       
   244 	  #'buttonMotion:x:y:'
       
   245 	  #'keyPress:x:y:'
       
   246 	  #'keyRelease:x:y:'
       
   247 	  #'focusIn'
       
   248 	  #'focusOut'
       
   249 	  #'pointerEnter:x:y:'
       
   250 	  #'pointerLeave:'
       
   251 	) includes:selector) ifTrue:[
       
   252 	    eventReceiver := controller.
   160 	]
   253 	]
   161     ] ifFalse:[
   254     ].
   162 	"
   255 
   163 	 another one:
   256     "
   164 	 if the view has a transformation, edit the selector
   257      if there is a focusView, and its a keyboard event, pass it
   165 	 from #foo to #deviceFoo...
   258      to that view (or its controller). In this case, some coordinate which is outside of
   166 	 This allows the view to handle the event either in device or
   259      the focusView is passed as x/y coordinates.
   167 	 logical coordinates. (since the deviceFoo-messages default implementation
   260     "
   168 	 in PseudoView translates and resends).
   261     focusView notNil ifTrue:[
   169 	 Actually, I could always send deviceXXX without speed penalty
   262 	(#(#'keyPress:x:y:'
   170 	 (event sending is no high frequency operation), but that just adds 
   263 	   #'keyRelease:x:y:'
   171 	 another context to any debuggers walkback, making things less clear.
   264 	)includes:selector) ifTrue:[
   172 	"
   265 	    eventReceiver := focusView.
   173 	eventReceiver := view.
   266 	    (controller := focusView controller) notNil ifTrue:[  
   174 	(controller := view controller) notNil ifTrue:[  
       
   175 	    (#(
       
   176 	      #'buttonPress:x:y:'
       
   177 	      #'buttonRelease:x:y:'
       
   178 	      #'buttonShiftPress:x:y:'
       
   179 	      #'buttonMultiPress:x:y:'
       
   180 	      #'buttonMotion:x:y:'
       
   181 	      #'keyPress:x:y:'
       
   182 	      #'keyRelease:x:y:'
       
   183 	      #'exposeX:y:width:height:'
       
   184 	      #'graphicExposeX:y:width:height:'
       
   185 	      #'pointerEnter:x:y:'
       
   186 	    ) includes:selector) ifTrue:[
       
   187 		eventReceiver := controller.
   267 		eventReceiver := controller.
   188 	    ]
   268 	    ].
   189 	].
   269 	    eventReceiver perform:selector 
   190 
   270 		    withArguments:(Array with:(arguments at:1)
   191 	view transformation notNil ifTrue:[
   271 					 with:-1
   192 	    (#(
   272 					 with:-1).
   193 	      #'buttonPress:x:y:'
   273 	    ^ self
   194 	      #'buttonRelease:x:y:'
   274 	]
   195 	      #'buttonShiftPress:x:y:'
   275     ].
   196 	      #'buttonMultiPress:x:y:'
   276 
   197 	      #'buttonMotion:x:y:'
   277     "
   198 	      #'keyPress:x:y:'
   278      another one:
   199 	      #'keyRelease:x:y:'
   279      if the view has a transformation, edit the selector
   200 	      #'exposeX:y:width:height:'
   280      from #foo to #deviceFoo...
   201 	      #'graphicExposeX:y:width:height:'
   281      This allows the view to handle the event either in device or
   202 	      #'pointerEnter:x:y:'
   282      logical coordinates. (since the deviceFoo-messages default implementation
   203 	    )includes:selector) ifTrue:[
   283      in PseudoView translates and resends).
   204 		selector := selector asString.
   284      Actually, I could always send deviceXXX without speed penalty
   205 		selector at:1 put:(selector at:1) asUppercase.
   285      (event sending is no high frequency operation), but that just adds 
   206 		selector := ('device' , selector) asSymbol
   286      another context to any debuggers walkback, making things less clear.
   207 	    ]        
   287     "
   208 	].
   288     view transformation notNil ifTrue:[
   209 	eventReceiver perform:selector withArguments:arguments
   289 	(#(
   210     ]
   290 	  #'buttonPress:x:y:'
       
   291 	  #'buttonRelease:x:y:'
       
   292 	  #'buttonShiftPress:x:y:'
       
   293 	  #'buttonMultiPress:x:y:'
       
   294 	  #'buttonMotion:x:y:'
       
   295 	  #'keyPress:x:y:'
       
   296 	  #'keyRelease:x:y:'
       
   297 	  #'exposeX:y:width:height:'
       
   298 	  #'graphicExposeX:y:width:height:'
       
   299 	  #'pointerEnter:x:y:'
       
   300 	) includes:selector) ifTrue:[
       
   301 	    selector := selector asString.
       
   302 	    selector at:1 put:(selector at:1) asUppercase.
       
   303 	    selector := ('device' , selector) asSymbol
       
   304 	]        
       
   305     ].
       
   306     eventReceiver perform:selector withArguments:arguments
   211 ! !
   307 ! !
   212 
   308 
   213 !WindowEvent methodsFor:'private accessing'!
   309 !WindowEvent methodsFor:'private accessing'!
   214 
   310 
   215 for:aView type:aSymbol arguments:argArray
   311 for:aView type:aSymbol arguments:argArray