KeyboardMap.st
author Claus Gittinger <cg@exept.de>
Sat, 11 Nov 1995 16:54:10 +0100
changeset 219 9ff0660f447f
parent 89 ea2bf46eb669
child 244 83218faf792c
permissions -rw-r--r--
uff - version methods changed to return stings

"
 COPYRIGHT (c) 1993 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.
"

IdentityDictionary  subclass:#KeyboardMap 
       instanceVariableNames:'current'
       classVariableNames:''
       poolDictionaries:''
       category:'Interface-Support'
!

!KeyboardMap class methodsFor:'documentation'!

copyright
"
 COPYRIGHT (c) 1993 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.
"
!

version
    ^ '$Header: /cvs/stx/stx/libview/KeyboardMap.st,v 1.7 1995-11-11 15:51:38 cg Exp $'
!

documentation
"
    instances of KeyboardMap are used for mapping keystrokes AND sequences
    of keystrokes to a function key.
    There is usually only one instance in the system - held in an instance
    variable of Display.

    The setup of this map is done in the 'smalltalk.rc' or one of the
    'display.rc' files during startup.
    To add a mapping (for example, to attach the logical function 'DoIt' to
    the key-combination Cmd-'d'):

	|m|

	m := Display keyboardMap.
	m bindValue:#DoIt to:#Cmdd.

    Key sequences can also be defined (hey emacs fans ;-) as in:

	|m|

	m := Display keyboardMap.
	m bindValue:#DoIt to:#Ctrlx followedBy:#Ctrld

    Key prefixes are defined in the DeviceWorkstation>>translateKey: method.
    Typical prefixes are Cmd (for Alt or Meta), Ctrl etc.
    Some keyboards offer both Alt and Meta keys - on those, the first has a
    prefix of Alt, the second has Cmd as prefix. Keyboards with only an Alt
    key will will create prefix codes of Cmd for that.

    To remove a mapping, use the same value for both logical and physical key,
    as in:

	|m|

	m := Display keyboardMap.
	m bindValue:#Cmdd to:#Cmdd.
"
! !

!KeyboardMap methodsFor:'accessing'!

bindValue:logicalKey to:aKey
    aKey == logicalKey ifTrue:[
	self removeKey:aKey
    ] ifFalse:[
	self at:aKey put:logicalKey
    ]
!

bindValue:logicalKey to:key1 followedBy:key2
    |submap|

    submap := self at:key1 ifAbsent:[].
    submap isNil ifTrue:[
	submap := KeyboardMap new.
	self at:key1 put:submap.
    ].
    submap at:key2 put:logicalKey
!

valueFor:aKey
    |where value|

    where := (current notNil ifTrue:[current] ifFalse:[self]).

    value := where at:aKey ifAbsent:aKey.
    (value isMemberOf:KeyboardMap) ifTrue:[
	current := value.
	^ nil.
    ].
    current := nil.
    ^ value
! !