KeyboardForwarder.st
changeset 128 9c2378152500
child 134 1a09a1d7d28d
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/KeyboardForwarder.st	Fri Mar 31 04:57:21 1995 +0200
@@ -0,0 +1,130 @@
+"
+ COPYRIGHT (c) 1995 by Claus Gittinger
+	      All Rights Reserved
+
+ This software is furnished under a license and may be used
+ only in accordance with the terms of that license and with the
+ inclusion of the above copyright notice.   This software may not
+ be provided or otherwise made available to, or used by, any
+ other person.  No title to or ownership of the software is
+ hereby transferred.
+"
+
+
+'From Smalltalk/X, Version:2.10.5 on 30-mar-1995 at 5:32:55 am'!
+
+Object subclass:#KeyboardForwarder
+	 instanceVariableNames:'sourceView destinationView'
+	 classVariableNames:''
+	 poolDictionaries:''
+	 category:'Interface-Support'
+!
+
+!KeyboardForwarder class methodsFor:'documentation'!
+
+version
+"
+$Header: /cvs/stx/stx/libview/KeyboardForwarder.st,v 1.1 1995-03-31 02:57:21 claus Exp $
+"
+!
+
+documentation
+"
+    Instances of this class can be used as delegates to forward keyboard
+    events to some other view.
+    Notice, that delegates dont have to be instances of
+    myself; any object with a protocol similar to mine can be used as
+    a delegate. 
+    (i.e. any object that responds to handlesKeyPress:view: / keyPress:x:y:view: etc.)
+
+    Instance Variables:
+	destinationView         <View>          the view which shall receive
+						the forwarded keyboard events.
+"
+!
+
+copyright
+"
+ COPYRIGHT (c) 1995 by Claus Gittinger
+	      All Rights Reserved
+
+ This software is furnished under a license and may be used
+ only in accordance with the terms of that license and with the
+ inclusion of the above copyright notice.   This software may not
+ be provided or otherwise made available to, or used by, any
+ other person.  No title to or ownership of the software is
+ hereby transferred.
+"
+
+! !
+
+!KeyboardForwarder class methodsFor:'instance creation'!
+
+from:sourceView to:destinationView
+    ^ self new sourceView:sourceView; destinationView:destinationView
+!
+
+to:destinationView
+    ^ self new destinationView:destinationView
+! !
+
+!KeyboardForwarder methodsFor:'accessing'!
+
+destinationView:aView
+    destinationView := aView
+!
+
+sourceView:aView
+    sourceView := aView
+!
+
+destinationView
+    ^ destinationView
+!
+
+sourceView
+    ^ sourceView
+! !
+
+!KeyboardForwarder methodsFor:'queries'!
+
+handlesKeyPress:key inView:aView
+    sourceView notNil ifTrue:[
+	^ aView == sourceView
+    ].
+    ^ true
+
+
+!
+
+handlesKeyRelease:key inView:aView
+    sourceView notNil ifTrue:[
+	^ aView == sourceView
+    ].
+    ^ true
+! !
+
+!KeyboardForwarder methodsFor:'event forwarding'!
+
+keyPress:key x:x y:y view:aView
+    x < 0 ifTrue:[
+	"
+	 already delegated ... ignore
+	"
+	^ self
+    ].
+
+    destinationView keyPress:key x:-1 y:-1 
+!
+
+keyRelease:key x:x y:y view:aView
+    x < 0 ifTrue:[
+	"
+	 already delegated ... ignore
+	"
+	^ self
+    ].
+
+    destinationView keyRelease:key x:-1 y:-1 
+! !
+