KeyboardForwarder.st
author claus
Wed, 03 May 1995 02:04:18 +0200
changeset 134 1a09a1d7d28d
parent 128 9c2378152500
child 139 2e075def9aee
permissions -rw-r--r--
.

"
 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 condition'
	 classVariableNames:''
	 poolDictionaries:''
	 category:'Interface-Support'
!

!KeyboardForwarder class methodsFor:'documentation'!

version
"
$Header: /cvs/stx/stx/libview/KeyboardForwarder.st,v 1.2 1995-05-03 00:04:13 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.)
    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.

    Instance Variables:
	destinationView         <View>          the view which shall receive
						the forwarded keyboard events.

	sourceView              <ViewOrNil>     if non-nil, only events from this
						view are forwarded.
						(currently nowhere used)

	condition               <Symbol>        an additional condition for forwarding
						currently only #noFocus is implemented.
						The #noFocus condition will only forward
						events if no explicit focus has been
						set in the windowGroup.
"
!

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
!

to:destinationView condition:aCondition
    ^ self new destinationView:destinationView; condition:aCondition
! !

!KeyboardForwarder methodsFor:'accessing'!

condition:aCondition
    condition := aCondition
!

destinationView:aView
    destinationView := aView
!

sourceView:aView
    sourceView := aView
!

destinationView
    ^ destinationView
!

sourceView
    ^ sourceView
! !

!KeyboardForwarder methodsFor:'queries'!

handlesKeyPress:key inView:aView
    condition notNil ifTrue:[
	condition == #noFocus ifTrue:[
	    aView windowGroup focusView notNil ifTrue:[^ false]
	]
    ].
    sourceView notNil ifTrue:[
	^ aView == sourceView
    ].
    ^ true
!

handlesKeyRelease:key inView:aView
    condition notNil ifTrue:[
	condition == #noFocus ifTrue:[
	    aView windowGroup focusView notNil ifTrue:[^ false]
	]
    ].
    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 
! !