KeyboardMap.st
author matilk
Wed, 13 Sep 2017 09:40:34 +0200
changeset 8174 2704c965b97b
parent 6663 a3d11f506f57
child 7856 7c52e7a9a087
permissions -rw-r--r--
#BUGFIX by Maren class: DeviceGraphicsContext changed: #displayDeviceOpaqueForm:x:y: nil check

"
 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.
"
"{ Package: 'stx:libview' }"

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

!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.
"
!

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
    'keyboard.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.

    [see also:]
        WindowEvent WindowSensor WindowGroup
        View DeviceWorkstation

    [author:]
        Claus Gittinger
"
! !

!KeyboardMap methodsFor:'accessing'!

bindValue:logicalKey to:aKey
    "bind aLogicalKey to a rawKey.
     The event mechanism uses this to pass logical keyboard events
     to the application (such as #Copy, #Cut etc.) 
     instead of physical ones (such as #AltC, #AltX)"

    aKey == logicalKey ifTrue:[
        self removeKey:aKey ifAbsent:nil
    ] ifFalse:[
        self at:aKey put:logicalKey
    ]

    "Modified: 12.11.1996 / 10:30:56 / cg"
!

bindValue:logicalKey to:key1 followedBy:key2
    "bind aLogicalKey to a sequence of two rawKeys.
     The event mechanism uses this to pass logical keyboard events
     to the application (such as #Copy, #Cut etc.) 
     instead of physical ones (such as #AltC, #AltX)"

    |submap|

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

    "Modified: 23.4.1996 / 21:55:04 / cg"
!

hasBindingFor:aKey
    "retrieve a logical key"

    |whichMap|

    whichMap := (current notNil ifTrue:[current] ifFalse:[self]).
    ^ whichMap includesKey:aKey
!

valueFor:aKey
    "retrieve a logical key"

    |whichMap value|

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

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

    "Modified: 23.4.1996 / 21:55:22 / cg"
! !

!KeyboardMap class methodsFor:'documentation'!

version
    ^ '$Header: /cvs/stx/stx/libview/KeyboardMap.st,v 1.15 2014-12-18 16:13:06 cg Exp $'
! !