added optional filterBlock
authorClaus Gittinger <cg@exept.de>
Sun, 04 Feb 1996 20:40:49 +0100
changeset 400 47fa508fd78b
parent 399 0b6e43843204
child 401 f163a93a0987
added optional filterBlock
KeybdFwd.st
KeyboardForwarder.st
--- a/KeybdFwd.st	Sun Feb 04 18:13:46 1996 +0100
+++ b/KeybdFwd.st	Sun Feb 04 20:40:49 1996 +0100
@@ -12,10 +12,10 @@
 
 
 Object subclass:#KeyboardForwarder
-	 instanceVariableNames:'sourceView destinationView destination condition'
-	 classVariableNames:''
-	 poolDictionaries:''
-	 category:'Interface-Support'
+	instanceVariableNames:'sourceView destinationView destination condition filter'
+	classVariableNames:''
+	poolDictionaries:''
+	category:'Interface-Support'
 !
 
 !KeyboardForwarder class methodsFor:'documentation'!
@@ -186,7 +186,7 @@
      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
+    ^ self to:destination condition:nil filter:nil 
 !
 
 to:destination condition:aCondition
@@ -197,7 +197,19 @@
      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
+    ^ self to:destination condition:aCondition filter:nil 
+!
+
+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
+     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
 !
 
 toView:destinationView
@@ -207,7 +219,7 @@
      the original view as argument (i.e. as #keyPress:x:y:). 
      Use this, if the destination is a view."
 
-    ^ self new destinationView:destinationView
+    ^ self toView:destinationView condition:nil filter:nil 
 !
 
 toView:destinationView condition:aCondition
@@ -218,7 +230,19 @@
      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
+    ^ self toView:destinationView condition:aCondition filter:nil 
+!
+
+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
+     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
 ! !
 
 !KeyboardForwarder methodsFor:'accessing'!
@@ -254,6 +278,14 @@
     destinationView := aView
 !
 
+filter:aOneArgBlock
+    "set the filter - if non-nil, only keys for which it returns true are forwarded"
+
+     filter := aOneArgBlock
+
+    "Created: 4.2.1996 / 20:35:15 / cg"
+!
+
 sourceView
     "get the sourceView - if nonNil, only events from this view will be forwarded"
 
@@ -274,22 +306,28 @@
      Take care of cyclic delegation (via a kludge-test for negative coordinate)."
 
     x < 0 ifTrue:[
-	"
-	 already delegated ... ignore
-	"
-	^ self
+        "
+         already delegated ... ignore
+        "
+        ^ self
+    ].
+
+    filter notNil ifTrue:[
+        (filter value:key) ifFalse:[^ self].
     ].
 
     destination notNil ifTrue:[
-	destination keyPress:key x:-1 y:-1 view:aView.
+        destination keyPress:key x:-1 y:-1 view:aView.
     ] ifFalse:[
-	destinationView notNil ifTrue:[
-	    WindowEvent
-		sendEvent:#keyPress:x:y:
-		arguments:(Array with:key with:-1 with:-1)
-		view:destinationView
-	]
+        destinationView notNil ifTrue:[
+            WindowEvent
+                sendEvent:#keyPress:x:y:
+                arguments:(Array with:key with:-1 with:-1)
+                view:destinationView
+        ]
     ]
+
+    "Modified: 4.2.1996 / 20:35:52 / cg"
 !
 
 keyRelease:key x:x y:y view:aView
@@ -298,22 +336,28 @@
      Take care of cyclic delegation (via a kludge-test for negative coordinate)."
 
     x < 0 ifTrue:[
-	"
-	 already delegated ... ignore
-	"
-	^ self
+        "
+         already delegated ... ignore
+        "
+        ^ self
+    ].
+
+    filter notNil ifTrue:[
+        (filter value:key) ifFalse:[^ self].
     ].
 
     destination notNil ifTrue:[
-	destination keyRelease:key x:-1 y:-1 view:aView
+        destination keyRelease:key x:-1 y:-1 view:aView
     ] ifFalse:[
-	destinationView notNil ifTrue:[
-	    WindowEvent
-		sendEvent:#keyRelease:x:y:
-		arguments:(Array with:key with:-1 with:-1)
-		view:destinationView
-	]
+        destinationView notNil ifTrue:[
+            WindowEvent
+                sendEvent:#keyRelease:x:y:
+                arguments:(Array with:key with:-1 with:-1)
+                view:destinationView
+        ]
     ]
+
+    "Modified: 4.2.1996 / 20:35:55 / cg"
 ! !
 
 !KeyboardForwarder methodsFor:'focus forwarding'!
@@ -333,18 +377,24 @@
 !KeyboardForwarder methodsFor:'queries'!
 
 checkCondition:type key:key view:aView
+    filter notNil ifTrue:[
+        (filter value:key) ifFalse:[^ false].
+    ].
+
     condition notNil ifTrue:[
-	condition == #noFocus ifTrue:[
-	    aView windowGroup focusView notNil ifTrue:[^ false]
-	].
-	condition isBlock ifTrue:[
-	    (condition value:type value:key value:aView) ifFalse:[^ false]
-	]
+        condition == #noFocus ifTrue:[
+            aView windowGroup focusView notNil ifTrue:[^ false]
+        ].
+        condition isBlock ifTrue:[
+            (condition value:type value:key value:aView) ifFalse:[^ false]
+        ]
     ].
     sourceView notNil ifTrue:[
-	^ aView == sourceView
+        ^ aView == sourceView
     ].
     ^ true
+
+    "Modified: 4.2.1996 / 20:36:16 / cg"
 !
 
 delegatesTo:someone
@@ -372,5 +422,5 @@
 !KeyboardForwarder class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libview/Attic/KeybdFwd.st,v 1.10 1996-01-27 15:34:55 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libview/Attic/KeybdFwd.st,v 1.11 1996-02-04 19:40:49 cg Exp $'
 ! !
--- a/KeyboardForwarder.st	Sun Feb 04 18:13:46 1996 +0100
+++ b/KeyboardForwarder.st	Sun Feb 04 20:40:49 1996 +0100
@@ -12,10 +12,10 @@
 
 
 Object subclass:#KeyboardForwarder
-	 instanceVariableNames:'sourceView destinationView destination condition'
-	 classVariableNames:''
-	 poolDictionaries:''
-	 category:'Interface-Support'
+	instanceVariableNames:'sourceView destinationView destination condition filter'
+	classVariableNames:''
+	poolDictionaries:''
+	category:'Interface-Support'
 !
 
 !KeyboardForwarder class methodsFor:'documentation'!
@@ -186,7 +186,7 @@
      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
+    ^ self to:destination condition:nil filter:nil 
 !
 
 to:destination condition:aCondition
@@ -197,7 +197,19 @@
      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
+    ^ self to:destination condition:aCondition filter:nil 
+!
+
+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
+     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
 !
 
 toView:destinationView
@@ -207,7 +219,7 @@
      the original view as argument (i.e. as #keyPress:x:y:). 
      Use this, if the destination is a view."
 
-    ^ self new destinationView:destinationView
+    ^ self toView:destinationView condition:nil filter:nil 
 !
 
 toView:destinationView condition:aCondition
@@ -218,7 +230,19 @@
      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
+    ^ self toView:destinationView condition:aCondition filter:nil 
+!
+
+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
+     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
 ! !
 
 !KeyboardForwarder methodsFor:'accessing'!
@@ -254,6 +278,14 @@
     destinationView := aView
 !
 
+filter:aOneArgBlock
+    "set the filter - if non-nil, only keys for which it returns true are forwarded"
+
+     filter := aOneArgBlock
+
+    "Created: 4.2.1996 / 20:35:15 / cg"
+!
+
 sourceView
     "get the sourceView - if nonNil, only events from this view will be forwarded"
 
@@ -274,22 +306,28 @@
      Take care of cyclic delegation (via a kludge-test for negative coordinate)."
 
     x < 0 ifTrue:[
-	"
-	 already delegated ... ignore
-	"
-	^ self
+        "
+         already delegated ... ignore
+        "
+        ^ self
+    ].
+
+    filter notNil ifTrue:[
+        (filter value:key) ifFalse:[^ self].
     ].
 
     destination notNil ifTrue:[
-	destination keyPress:key x:-1 y:-1 view:aView.
+        destination keyPress:key x:-1 y:-1 view:aView.
     ] ifFalse:[
-	destinationView notNil ifTrue:[
-	    WindowEvent
-		sendEvent:#keyPress:x:y:
-		arguments:(Array with:key with:-1 with:-1)
-		view:destinationView
-	]
+        destinationView notNil ifTrue:[
+            WindowEvent
+                sendEvent:#keyPress:x:y:
+                arguments:(Array with:key with:-1 with:-1)
+                view:destinationView
+        ]
     ]
+
+    "Modified: 4.2.1996 / 20:35:52 / cg"
 !
 
 keyRelease:key x:x y:y view:aView
@@ -298,22 +336,28 @@
      Take care of cyclic delegation (via a kludge-test for negative coordinate)."
 
     x < 0 ifTrue:[
-	"
-	 already delegated ... ignore
-	"
-	^ self
+        "
+         already delegated ... ignore
+        "
+        ^ self
+    ].
+
+    filter notNil ifTrue:[
+        (filter value:key) ifFalse:[^ self].
     ].
 
     destination notNil ifTrue:[
-	destination keyRelease:key x:-1 y:-1 view:aView
+        destination keyRelease:key x:-1 y:-1 view:aView
     ] ifFalse:[
-	destinationView notNil ifTrue:[
-	    WindowEvent
-		sendEvent:#keyRelease:x:y:
-		arguments:(Array with:key with:-1 with:-1)
-		view:destinationView
-	]
+        destinationView notNil ifTrue:[
+            WindowEvent
+                sendEvent:#keyRelease:x:y:
+                arguments:(Array with:key with:-1 with:-1)
+                view:destinationView
+        ]
     ]
+
+    "Modified: 4.2.1996 / 20:35:55 / cg"
 ! !
 
 !KeyboardForwarder methodsFor:'focus forwarding'!
@@ -333,18 +377,24 @@
 !KeyboardForwarder methodsFor:'queries'!
 
 checkCondition:type key:key view:aView
+    filter notNil ifTrue:[
+        (filter value:key) ifFalse:[^ false].
+    ].
+
     condition notNil ifTrue:[
-	condition == #noFocus ifTrue:[
-	    aView windowGroup focusView notNil ifTrue:[^ false]
-	].
-	condition isBlock ifTrue:[
-	    (condition value:type value:key value:aView) ifFalse:[^ false]
-	]
+        condition == #noFocus ifTrue:[
+            aView windowGroup focusView notNil ifTrue:[^ false]
+        ].
+        condition isBlock ifTrue:[
+            (condition value:type value:key value:aView) ifFalse:[^ false]
+        ]
     ].
     sourceView notNil ifTrue:[
-	^ aView == sourceView
+        ^ aView == sourceView
     ].
     ^ true
+
+    "Modified: 4.2.1996 / 20:36:16 / cg"
 !
 
 delegatesTo:someone
@@ -372,5 +422,5 @@
 !KeyboardForwarder class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libview/KeyboardForwarder.st,v 1.10 1996-01-27 15:34:55 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libview/KeyboardForwarder.st,v 1.11 1996-02-04 19:40:49 cg Exp $'
 ! !