#REFACTORING by cg
authorClaus Gittinger <cg@exept.de>
Sat, 12 May 2018 14:25:01 +0200
changeset 8362 573b5a8cc1c5
parent 8361 8d425e982530
child 8363 49c00052b118
#REFACTORING by cg class: KeyboardForwarder comment/format in: #checkCondition:key:view: #keyPress:x:y:view: changed: #keyRelease:x:y:view: class: KeyboardForwarder class comment/format in: #from:to: #from:toView: #to: #to:condition: #to:condition:filter: #toView: #toView:condition: #toView:condition:filter:
KeyboardForwarder.st
--- a/KeyboardForwarder.st	Fri May 11 09:24:54 2018 +0200
+++ b/KeyboardForwarder.st	Sat May 12 14:25:01 2018 +0200
@@ -1,3 +1,5 @@
+"{ Encoding: utf8 }"
+
 "
  COPYRIGHT (c) 1995 by Claus Gittinger
 	      All Rights Reserved
@@ -174,7 +176,8 @@
     "create and return a new KeyboardForwarder to redirect key events
      for sourceView to destination. Events from other than the sourceView
      will not be forwarded. The forwarded event will be reported including
-     the original view as argument (i.e. as #keyPress:x:y:view:). 
+     the original view as argument (i.e. as #keyPress:x:y:view:).
+
      Use this, if the destination is not a view."
 
     ^ self new sourceView:sourceView; destination:destination
@@ -185,6 +188,7 @@
      for sourceView to destinationView. Events from other than the sourceView
      will not be forwarded. The forwarded event will be reported excluding
      the original view as argument (i.e. as #keyPress:x:y:). 
+
      Use this, if the destination is a view."
 
     ^ self new sourceView:sourceView; destinationView:destinationView
@@ -192,9 +196,10 @@
 
 to:destination
     "create and return a new KeyboardForwarder to redirect any key event
-     to destination (Independent of the view in which the event originally
+     to destination (independent of the view in which the event originally
      occurred). The forwarded event will be reported including
      the original view as argument (i.e. as #keyPress:x:y:view:). 
+
      Use this, if the destination is not a view."
 
     ^ self to:destination condition:nil filter:nil 
@@ -202,10 +207,12 @@
 
 to:destination condition:aCondition
     "create and return a new KeyboardForwarder to redirect any key event
-     to destinationView (Independent of the view in which the event originally
-     occurred) but only, if some condition as specified by aCondition
+     to destination 
+     (independent of the view in which the event originally occurred) 
+     but only, if some condition as specified by aCondition
      is met. The forwarded event will be reported including
-     the original view as argument (i.e. as #keyPress:x:y:view:). 
+     the original view as argument (i.e. as #keyPress:x:y:view:).
+
      Use this, if the destination is not a view."
 
     ^ self to:destination condition:aCondition filter:nil 
@@ -213,11 +220,13 @@
 
 to:destination condition:aCondition filter:aFilterBlock
     "create and return a new KeyboardForwarder to redirect any key event
-     to destinationView (Independent of the view in which the event originally
-     occurred) but only, if some condition as specified by aCondition
+     to destination
+     (independent of the view in which the event originally occurred) 
+     but only, if some condition as specified by aCondition
      is met and aFilterBlock returns true for that key.
      The forwarded event will be reported including
      the original view as argument (i.e. as #keyPress:x:y:view:). 
+
      Use this, if the destination is not a view."
 
     ^ self new destination:destination; condition:aCondition; filter:aFilterBlock
@@ -225,9 +234,11 @@
 
 toView:destinationView
     "create and return a new KeyboardForwarder to redirect any key event
-     to destinationView (Independent of the view in which the event originally
-     occurred). The forwarded event will be reported excluding
-     the original view as argument (i.e. as #keyPress:x:y:). 
+     to destinationView 
+     (independent of the view in which the event originally occurred). 
+     The forwarded event will be reported excluding
+     the original view as argument (i.e. as #keyPress:x:y:).
+
      Use this, if the destination is a view."
 
     ^ self toView:destinationView condition:nil filter:nil 
@@ -235,10 +246,12 @@
 
 toView:destinationView condition:aCondition
     "create and return a new KeyboardForwarder to redirect any key event
-     to destinationView (Independent of the view in which the event originally
-     occurred) but only, if some condition as specified by aCondition
+     to destinationView 
+     (independent of the view in which the event originally occurred) but only, 
+     if some condition as specified by aCondition
      is met. The forwarded event will be reported excluding
-     the original view as argument (i.e. as #keyPress:x:y:). 
+     the original view as argument (i.e. as #keyPress:x:y:).
+
      Use this, if the destination is a view."
 
     ^ self toView:destinationView condition:aCondition filter:nil 
@@ -246,11 +259,13 @@
 
 toView:destinationView condition:aCondition filter:aFilterBlock
     "create and return a new KeyboardForwarder to redirect any key event
-     to destinationView (Independent of the view in which the event originally
-     occurred) but only, if some condition as specified by aCondition
+     to destinationView 
+     (independent of the view in which the event originally occurred) 
+     but only, if some condition as specified by aCondition
      is met and aFilterBlock returns true for that key.
      The forwarded event will be reported excluding
      the original view as argument (i.e. as #keyPress:x:y:). 
+
      Use this, if the destination is a view."
 
     ^ self new destinationView:destinationView; condition:aCondition; filter:aFilterBlock
@@ -341,9 +356,11 @@
     ].
 
     destination notNil ifTrue:[
+        "delegating to an app (or anything else)"
         destination keyPress:key x:nil y:nil view:aView.
     ] ifFalse:[
         destinationView notNil ifTrue:[
+            "delegating to another view"
             forwardedEvent := WindowEvent keyPress:key x:xDel y:yDel view:destinationView.
             destinationView
                 dispatchEvent:forwardedEvent
@@ -360,9 +377,9 @@
      forward the event (i.e. after I returned true on handlesKeyRelease:.
      Take care of cyclic delegation (via a kludge-test for negative coordinate)."
 
-    |forwardedEvent|
+    |forwardedEvent xDel yDel|
 
-    x < 0 ifTrue:[
+    (x isNil or:[x < 0]) ifTrue:[
         "
          already delegated ... ignore
         "
@@ -373,10 +390,22 @@
         (filter value:key) ifFalse:[^ self].
     ].
 
+    xDel := x.
+    yDel := y.
+
+    x == 0 ifTrue:[
+        "
+         already delegated ... care to not delegate twice
+        "
+        xDel := nil.
+        yDel := nil.
+    ].
     destination notNil ifTrue:[
+        "delegating to an app (or anything else)"
         destination keyRelease:key x:-1 y:-1 view:aView
     ] ifFalse:[
         destinationView notNil ifTrue:[
+            "delegating to another view"
             forwardedEvent := WindowEvent keyRelease:key x:-1 y:-1 view:destinationView.
             destinationView dispatchEvent:forwardedEvent withFocusOn:nil delegate:false
         ]
@@ -433,9 +462,9 @@
 
 !KeyboardForwarder methodsFor:'queries'!
 
-checkCondition:type key:key view:aView
-    "return true, if I am interested in an event with type (#keyPress or
-     #keyRelease) and key for aView."
+checkCondition:typeOfEvent key:key view:aView
+    "return true, if I am interested in an event with type 
+     (#keyPress or #keyRelease) and key for aView."
 
     |wg|
 
@@ -449,7 +478,7 @@
             (wg isNil or:[wg focusView notNil]) ifTrue:[^ false]
         ].
         condition isBlock ifTrue:[
-            (condition value:type value:key value:aView) ifFalse:[^ false]
+            (condition value:typeOfEvent value:key value:aView) ifFalse:[^ false]
         ]
     ].
     sourceView notNil ifTrue:[