.
--- a/KeybdFwd.st Sat May 06 16:14:58 1995 +0200
+++ b/KeybdFwd.st Sun May 07 02:06:05 1995 +0200
@@ -14,7 +14,7 @@
'From Smalltalk/X, Version:2.10.5 on 30-mar-1995 at 5:32:55 am'!
Object subclass:#KeyboardForwarder
- instanceVariableNames:'sourceView destinationView condition'
+ instanceVariableNames:'sourceView destinationView destination condition'
classVariableNames:''
poolDictionaries:''
category:'Interface-Support'
@@ -24,26 +24,36 @@
version
"
-$Header: /cvs/stx/stx/libview/Attic/KeybdFwd.st,v 1.2 1995-05-03 00:04:13 claus Exp $
+$Header: /cvs/stx/stx/libview/Attic/KeybdFwd.st,v 1.3 1995-05-07 00:06:05 claus Exp $
"
!
documentation
"
Instances of this class can be used as delegates to forward keyboard
- events to some other view.
+ events to some object or other view (via aView delegate:).
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.)
- However, instances of myself are used to forward events from elements of
- some dialogBoxes to the enterfield - this allows keyboard input to be
- forwarded to the text-field even while the mouse pointer is somewhere else.
+
+ However, I provide the most common functions required for conditional
+ event delegation and instances of myself are for example used to forward
+ events from elements of some dialogBoxes to the enterfield/fieldGroup -
+ this allows keyboard input to be forwarded to the active text-field even
+ while the mouse pointer is somewhere else.
+
+ Another application of delegation is to catch keyboard input to some standard
+ widget, optionally processing and resending the key-event.
Instance Variables:
+
destinationView <View> the view which shall receive
the forwarded keyboard events.
+ destination <Object> the object which shall receive
+ the forwarded keyboard events.
+
sourceView <ViewOrNil> if non-nil, only events from this
view are forwarded.
(currently nowhere used)
@@ -73,19 +83,69 @@
!KeyboardForwarder class methodsFor:'instance creation'!
-from:sourceView to:destinationView
+from:sourceView toView:destinationView
+ "create and return a new KeyboardForwarder to redirect key events
+ 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
!
-to:destinationView
+from:sourceView to:destination
+ "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:).
+ Use this, if the destination is not a view."
+
+ ^ self new sourceView:sourceView; destination:destination
+!
+
+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:).
+ Use this, if the destination is a view."
+
^ self new destinationView:destinationView
!
-to:destinationView condition:aCondition
- ^ self new destinationView:destinationView; condition:aCondition
+to:destination
+ "create and return a new KeyboardForwarder to redirect any key event
+ 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 new destination:destination
+!
+
+toView:destinationView condition:aConditionSymbol
+ "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 aConditionSymbol
+ is met. 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:aConditionSymbol
+!
+
+to:destination condition:aConditionSymbol
+ "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 aConditionSymbol
+ is met. 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:aConditionSymbol
! !
-!KeyboardForwarder methodsFor:'accessing'!
+!KeyboardForwarder methodsFor:'private accessing'!
condition:aCondition
condition := aCondition
@@ -95,14 +155,22 @@
destinationView := aView
!
+destinationView
+ ^ destinationView
+!
+
+destination:anObject
+ destination := anObject
+!
+
+destination
+ ^ destination
+!
+
sourceView:aView
sourceView := aView
!
-destinationView
- ^ destinationView
-!
-
sourceView
^ sourceView
! !
@@ -110,6 +178,10 @@
!KeyboardForwarder methodsFor:'queries'!
handlesKeyPress:key inView:aView
+ "this is the query from the sensor to ask me if I would like to
+ get a keyPress event for key from aView. Return true, if I want so,
+ false otherwise."
+
condition notNil ifTrue:[
condition == #noFocus ifTrue:[
aView windowGroup focusView notNil ifTrue:[^ false]
@@ -122,6 +194,10 @@
!
handlesKeyRelease:key inView:aView
+ "this is the query from the sensor to ask me if I would like to
+ get a keyRelease event for key from aView. Return true, if I want so,
+ false otherwise."
+
condition notNil ifTrue:[
condition == #noFocus ifTrue:[
aView windowGroup focusView notNil ifTrue:[^ false]
@@ -136,6 +212,10 @@
!KeyboardForwarder methodsFor:'event forwarding'!
keyPress:key x:x y:y view:aView
+ "handle a delegated event - this is sent by the sensor to actually
+ forward the event (i.e. after I returned true on handlesKeyPress:.
+ Take care of cyclic delegation (via a kludge-test for negative coordinate)."
+
x < 0 ifTrue:[
"
already delegated ... ignore
@@ -143,10 +223,18 @@
^ self
].
- destinationView keyPress:key x:-1 y:-1
+ destination notNil ifTrue:[
+ destination keyPress:key x:-1 y:-1 view:aView.
+ ] ifFalse:[
+ destinationView keyPress:key x:-1 y:-1
+ ]
!
keyRelease:key x:x y:y view:aView
+ "handle a delegated event - this is sent by the sensor to actually
+ forward the event (i.e. after I returned true on handlesKeyRelease:.
+ Take care of cyclic delegation (via a kludge-test for negative coordinate)."
+
x < 0 ifTrue:[
"
already delegated ... ignore
@@ -154,6 +242,9 @@
^ self
].
- destinationView keyRelease:key x:-1 y:-1
+ destination notNil ifTrue:[
+ destinationView keyRelease:key x:-1 y:-1 view:aView
+ ] ifFalse:[
+ destinationView keyRelease:key x:-1 y:-1
+ ]
! !
-
--- a/KeyboardForwarder.st Sat May 06 16:14:58 1995 +0200
+++ b/KeyboardForwarder.st Sun May 07 02:06:05 1995 +0200
@@ -14,7 +14,7 @@
'From Smalltalk/X, Version:2.10.5 on 30-mar-1995 at 5:32:55 am'!
Object subclass:#KeyboardForwarder
- instanceVariableNames:'sourceView destinationView condition'
+ instanceVariableNames:'sourceView destinationView destination condition'
classVariableNames:''
poolDictionaries:''
category:'Interface-Support'
@@ -24,26 +24,36 @@
version
"
-$Header: /cvs/stx/stx/libview/KeyboardForwarder.st,v 1.2 1995-05-03 00:04:13 claus Exp $
+$Header: /cvs/stx/stx/libview/KeyboardForwarder.st,v 1.3 1995-05-07 00:06:05 claus Exp $
"
!
documentation
"
Instances of this class can be used as delegates to forward keyboard
- events to some other view.
+ events to some object or other view (via aView delegate:).
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.)
- However, instances of myself are used to forward events from elements of
- some dialogBoxes to the enterfield - this allows keyboard input to be
- forwarded to the text-field even while the mouse pointer is somewhere else.
+
+ However, I provide the most common functions required for conditional
+ event delegation and instances of myself are for example used to forward
+ events from elements of some dialogBoxes to the enterfield/fieldGroup -
+ this allows keyboard input to be forwarded to the active text-field even
+ while the mouse pointer is somewhere else.
+
+ Another application of delegation is to catch keyboard input to some standard
+ widget, optionally processing and resending the key-event.
Instance Variables:
+
destinationView <View> the view which shall receive
the forwarded keyboard events.
+ destination <Object> the object which shall receive
+ the forwarded keyboard events.
+
sourceView <ViewOrNil> if non-nil, only events from this
view are forwarded.
(currently nowhere used)
@@ -73,19 +83,69 @@
!KeyboardForwarder class methodsFor:'instance creation'!
-from:sourceView to:destinationView
+from:sourceView toView:destinationView
+ "create and return a new KeyboardForwarder to redirect key events
+ 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
!
-to:destinationView
+from:sourceView to:destination
+ "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:).
+ Use this, if the destination is not a view."
+
+ ^ self new sourceView:sourceView; destination:destination
+!
+
+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:).
+ Use this, if the destination is a view."
+
^ self new destinationView:destinationView
!
-to:destinationView condition:aCondition
- ^ self new destinationView:destinationView; condition:aCondition
+to:destination
+ "create and return a new KeyboardForwarder to redirect any key event
+ 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 new destination:destination
+!
+
+toView:destinationView condition:aConditionSymbol
+ "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 aConditionSymbol
+ is met. 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:aConditionSymbol
+!
+
+to:destination condition:aConditionSymbol
+ "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 aConditionSymbol
+ is met. 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:aConditionSymbol
! !
-!KeyboardForwarder methodsFor:'accessing'!
+!KeyboardForwarder methodsFor:'private accessing'!
condition:aCondition
condition := aCondition
@@ -95,14 +155,22 @@
destinationView := aView
!
+destinationView
+ ^ destinationView
+!
+
+destination:anObject
+ destination := anObject
+!
+
+destination
+ ^ destination
+!
+
sourceView:aView
sourceView := aView
!
-destinationView
- ^ destinationView
-!
-
sourceView
^ sourceView
! !
@@ -110,6 +178,10 @@
!KeyboardForwarder methodsFor:'queries'!
handlesKeyPress:key inView:aView
+ "this is the query from the sensor to ask me if I would like to
+ get a keyPress event for key from aView. Return true, if I want so,
+ false otherwise."
+
condition notNil ifTrue:[
condition == #noFocus ifTrue:[
aView windowGroup focusView notNil ifTrue:[^ false]
@@ -122,6 +194,10 @@
!
handlesKeyRelease:key inView:aView
+ "this is the query from the sensor to ask me if I would like to
+ get a keyRelease event for key from aView. Return true, if I want so,
+ false otherwise."
+
condition notNil ifTrue:[
condition == #noFocus ifTrue:[
aView windowGroup focusView notNil ifTrue:[^ false]
@@ -136,6 +212,10 @@
!KeyboardForwarder methodsFor:'event forwarding'!
keyPress:key x:x y:y view:aView
+ "handle a delegated event - this is sent by the sensor to actually
+ forward the event (i.e. after I returned true on handlesKeyPress:.
+ Take care of cyclic delegation (via a kludge-test for negative coordinate)."
+
x < 0 ifTrue:[
"
already delegated ... ignore
@@ -143,10 +223,18 @@
^ self
].
- destinationView keyPress:key x:-1 y:-1
+ destination notNil ifTrue:[
+ destination keyPress:key x:-1 y:-1 view:aView.
+ ] ifFalse:[
+ destinationView keyPress:key x:-1 y:-1
+ ]
!
keyRelease:key x:x y:y view:aView
+ "handle a delegated event - this is sent by the sensor to actually
+ forward the event (i.e. after I returned true on handlesKeyRelease:.
+ Take care of cyclic delegation (via a kludge-test for negative coordinate)."
+
x < 0 ifTrue:[
"
already delegated ... ignore
@@ -154,6 +242,9 @@
^ self
].
- destinationView keyRelease:key x:-1 y:-1
+ destination notNil ifTrue:[
+ destinationView keyRelease:key x:-1 y:-1 view:aView
+ ] ifFalse:[
+ destinationView keyRelease:key x:-1 y:-1
+ ]
! !
-