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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
48194c26a46c Initial revision
claus
parents:
diff changeset
     1
"
48194c26a46c Initial revision
claus
parents:
diff changeset
     2
 COPYRIGHT (c) 1993 by Claus Gittinger
72
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
     3
	      All Rights Reserved
0
48194c26a46c Initial revision
claus
parents:
diff changeset
     4
48194c26a46c Initial revision
claus
parents:
diff changeset
     5
 This software is furnished under a license and may be used
48194c26a46c Initial revision
claus
parents:
diff changeset
     6
 only in accordance with the terms of that license and with the
48194c26a46c Initial revision
claus
parents:
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
48194c26a46c Initial revision
claus
parents:
diff changeset
     8
 be provided or otherwise made available to, or used by, any
48194c26a46c Initial revision
claus
parents:
diff changeset
     9
 other person.  No title to or ownership of the software is
48194c26a46c Initial revision
claus
parents:
diff changeset
    10
 hereby transferred.
48194c26a46c Initial revision
claus
parents:
diff changeset
    11
"
5280
77ce8475efed category change
Claus Gittinger <cg@exept.de>
parents: 1120
diff changeset
    12
"{ Package: 'stx:libview' }"
0
48194c26a46c Initial revision
claus
parents:
diff changeset
    13
244
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
    14
IdentityDictionary subclass:#KeyboardMap
598
1a2339e902d4 commentary
Claus Gittinger <cg@exept.de>
parents: 251
diff changeset
    15
	instanceVariableNames:'current'
1a2339e902d4 commentary
Claus Gittinger <cg@exept.de>
parents: 251
diff changeset
    16
	classVariableNames:''
1a2339e902d4 commentary
Claus Gittinger <cg@exept.de>
parents: 251
diff changeset
    17
	poolDictionaries:''
5280
77ce8475efed category change
Claus Gittinger <cg@exept.de>
parents: 1120
diff changeset
    18
	category:'Interface-Support-UI'
0
48194c26a46c Initial revision
claus
parents:
diff changeset
    19
!
48194c26a46c Initial revision
claus
parents:
diff changeset
    20
46
7b331e9012fd *** empty log message ***
claus
parents: 5
diff changeset
    21
!KeyboardMap class methodsFor:'documentation'!
7b331e9012fd *** empty log message ***
claus
parents: 5
diff changeset
    22
7b331e9012fd *** empty log message ***
claus
parents: 5
diff changeset
    23
copyright
7b331e9012fd *** empty log message ***
claus
parents: 5
diff changeset
    24
"
7b331e9012fd *** empty log message ***
claus
parents: 5
diff changeset
    25
 COPYRIGHT (c) 1993 by Claus Gittinger
72
3e84121988c3 *** empty log message ***
claus
parents: 54
diff changeset
    26
	      All Rights Reserved
0
48194c26a46c Initial revision
claus
parents:
diff changeset
    27
46
7b331e9012fd *** empty log message ***
claus
parents: 5
diff changeset
    28
 This software is furnished under a license and may be used
7b331e9012fd *** empty log message ***
claus
parents: 5
diff changeset
    29
 only in accordance with the terms of that license and with the
7b331e9012fd *** empty log message ***
claus
parents: 5
diff changeset
    30
 inclusion of the above copyright notice.   This software may not
7b331e9012fd *** empty log message ***
claus
parents: 5
diff changeset
    31
 be provided or otherwise made available to, or used by, any
7b331e9012fd *** empty log message ***
claus
parents: 5
diff changeset
    32
 other person.  No title to or ownership of the software is
7b331e9012fd *** empty log message ***
claus
parents: 5
diff changeset
    33
 hereby transferred.
7b331e9012fd *** empty log message ***
claus
parents: 5
diff changeset
    34
"
7b331e9012fd *** empty log message ***
claus
parents: 5
diff changeset
    35
!
0
48194c26a46c Initial revision
claus
parents:
diff changeset
    36
46
7b331e9012fd *** empty log message ***
claus
parents: 5
diff changeset
    37
documentation
7b331e9012fd *** empty log message ***
claus
parents: 5
diff changeset
    38
"
7b331e9012fd *** empty log message ***
claus
parents: 5
diff changeset
    39
    instances of KeyboardMap are used for mapping keystrokes AND sequences
7b331e9012fd *** empty log message ***
claus
parents: 5
diff changeset
    40
    of keystrokes to a function key.
89
ea2bf46eb669 *** empty log message ***
claus
parents: 72
diff changeset
    41
    There is usually only one instance in the system - held in an instance
ea2bf46eb669 *** empty log message ***
claus
parents: 72
diff changeset
    42
    variable of Display.
ea2bf46eb669 *** empty log message ***
claus
parents: 72
diff changeset
    43
ea2bf46eb669 *** empty log message ***
claus
parents: 72
diff changeset
    44
    The setup of this map is done in the 'smalltalk.rc' or one of the
6663
a3d11f506f57 class: KeyboardMap
Claus Gittinger <cg@exept.de>
parents: 6556
diff changeset
    45
    'keyboard.rc' files during startup.
89
ea2bf46eb669 *** empty log message ***
claus
parents: 72
diff changeset
    46
    To add a mapping (for example, to attach the logical function 'DoIt' to
ea2bf46eb669 *** empty log message ***
claus
parents: 72
diff changeset
    47
    the key-combination Cmd-'d'):
ea2bf46eb669 *** empty log message ***
claus
parents: 72
diff changeset
    48
598
1a2339e902d4 commentary
Claus Gittinger <cg@exept.de>
parents: 251
diff changeset
    49
        |m|
89
ea2bf46eb669 *** empty log message ***
claus
parents: 72
diff changeset
    50
598
1a2339e902d4 commentary
Claus Gittinger <cg@exept.de>
parents: 251
diff changeset
    51
        m := Display keyboardMap.
1a2339e902d4 commentary
Claus Gittinger <cg@exept.de>
parents: 251
diff changeset
    52
        m bindValue:#DoIt to:#Cmdd.
89
ea2bf46eb669 *** empty log message ***
claus
parents: 72
diff changeset
    53
ea2bf46eb669 *** empty log message ***
claus
parents: 72
diff changeset
    54
    Key sequences can also be defined (hey emacs fans ;-) as in:
ea2bf46eb669 *** empty log message ***
claus
parents: 72
diff changeset
    55
598
1a2339e902d4 commentary
Claus Gittinger <cg@exept.de>
parents: 251
diff changeset
    56
        |m|
89
ea2bf46eb669 *** empty log message ***
claus
parents: 72
diff changeset
    57
598
1a2339e902d4 commentary
Claus Gittinger <cg@exept.de>
parents: 251
diff changeset
    58
        m := Display keyboardMap.
1a2339e902d4 commentary
Claus Gittinger <cg@exept.de>
parents: 251
diff changeset
    59
        m bindValue:#DoIt to:#Ctrlx followedBy:#Ctrld
89
ea2bf46eb669 *** empty log message ***
claus
parents: 72
diff changeset
    60
ea2bf46eb669 *** empty log message ***
claus
parents: 72
diff changeset
    61
    Key prefixes are defined in the DeviceWorkstation>>translateKey: method.
ea2bf46eb669 *** empty log message ***
claus
parents: 72
diff changeset
    62
    Typical prefixes are Cmd (for Alt or Meta), Ctrl etc.
ea2bf46eb669 *** empty log message ***
claus
parents: 72
diff changeset
    63
    Some keyboards offer both Alt and Meta keys - on those, the first has a
ea2bf46eb669 *** empty log message ***
claus
parents: 72
diff changeset
    64
    prefix of Alt, the second has Cmd as prefix. Keyboards with only an Alt
ea2bf46eb669 *** empty log message ***
claus
parents: 72
diff changeset
    65
    key will will create prefix codes of Cmd for that.
ea2bf46eb669 *** empty log message ***
claus
parents: 72
diff changeset
    66
ea2bf46eb669 *** empty log message ***
claus
parents: 72
diff changeset
    67
    To remove a mapping, use the same value for both logical and physical key,
ea2bf46eb669 *** empty log message ***
claus
parents: 72
diff changeset
    68
    as in:
ea2bf46eb669 *** empty log message ***
claus
parents: 72
diff changeset
    69
598
1a2339e902d4 commentary
Claus Gittinger <cg@exept.de>
parents: 251
diff changeset
    70
        |m|
89
ea2bf46eb669 *** empty log message ***
claus
parents: 72
diff changeset
    71
598
1a2339e902d4 commentary
Claus Gittinger <cg@exept.de>
parents: 251
diff changeset
    72
        m := Display keyboardMap.
1a2339e902d4 commentary
Claus Gittinger <cg@exept.de>
parents: 251
diff changeset
    73
        m bindValue:#Cmdd to:#Cmdd.
1a2339e902d4 commentary
Claus Gittinger <cg@exept.de>
parents: 251
diff changeset
    74
1a2339e902d4 commentary
Claus Gittinger <cg@exept.de>
parents: 251
diff changeset
    75
    [see also:]
1a2339e902d4 commentary
Claus Gittinger <cg@exept.de>
parents: 251
diff changeset
    76
        WindowEvent WindowSensor WindowGroup
1a2339e902d4 commentary
Claus Gittinger <cg@exept.de>
parents: 251
diff changeset
    77
        View DeviceWorkstation
612
8758d0c9933e documentation
Claus Gittinger <cg@exept.de>
parents: 598
diff changeset
    78
8758d0c9933e documentation
Claus Gittinger <cg@exept.de>
parents: 598
diff changeset
    79
    [author:]
8758d0c9933e documentation
Claus Gittinger <cg@exept.de>
parents: 598
diff changeset
    80
        Claus Gittinger
46
7b331e9012fd *** empty log message ***
claus
parents: 5
diff changeset
    81
"
7b331e9012fd *** empty log message ***
claus
parents: 5
diff changeset
    82
! !
0
48194c26a46c Initial revision
claus
parents:
diff changeset
    83
48194c26a46c Initial revision
claus
parents:
diff changeset
    84
!KeyboardMap methodsFor:'accessing'!
48194c26a46c Initial revision
claus
parents:
diff changeset
    85
89
ea2bf46eb669 *** empty log message ***
claus
parents: 72
diff changeset
    86
bindValue:logicalKey to:aKey
598
1a2339e902d4 commentary
Claus Gittinger <cg@exept.de>
parents: 251
diff changeset
    87
    "bind aLogicalKey to a rawKey.
1a2339e902d4 commentary
Claus Gittinger <cg@exept.de>
parents: 251
diff changeset
    88
     The event mechanism uses this to pass logical keyboard events
1a2339e902d4 commentary
Claus Gittinger <cg@exept.de>
parents: 251
diff changeset
    89
     to the application (such as #Copy, #Cut etc.) 
1a2339e902d4 commentary
Claus Gittinger <cg@exept.de>
parents: 251
diff changeset
    90
     instead of physical ones (such as #AltC, #AltX)"
1a2339e902d4 commentary
Claus Gittinger <cg@exept.de>
parents: 251
diff changeset
    91
89
ea2bf46eb669 *** empty log message ***
claus
parents: 72
diff changeset
    92
    aKey == logicalKey ifTrue:[
1120
616388474f7e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 612
diff changeset
    93
        self removeKey:aKey ifAbsent:nil
89
ea2bf46eb669 *** empty log message ***
claus
parents: 72
diff changeset
    94
    ] ifFalse:[
598
1a2339e902d4 commentary
Claus Gittinger <cg@exept.de>
parents: 251
diff changeset
    95
        self at:aKey put:logicalKey
89
ea2bf46eb669 *** empty log message ***
claus
parents: 72
diff changeset
    96
    ]
598
1a2339e902d4 commentary
Claus Gittinger <cg@exept.de>
parents: 251
diff changeset
    97
1120
616388474f7e checkin from browser
Claus Gittinger <cg@exept.de>
parents: 612
diff changeset
    98
    "Modified: 12.11.1996 / 10:30:56 / cg"
0
48194c26a46c Initial revision
claus
parents:
diff changeset
    99
!
48194c26a46c Initial revision
claus
parents:
diff changeset
   100
89
ea2bf46eb669 *** empty log message ***
claus
parents: 72
diff changeset
   101
bindValue:logicalKey to:key1 followedBy:key2
598
1a2339e902d4 commentary
Claus Gittinger <cg@exept.de>
parents: 251
diff changeset
   102
    "bind aLogicalKey to a sequence of two rawKeys.
1a2339e902d4 commentary
Claus Gittinger <cg@exept.de>
parents: 251
diff changeset
   103
     The event mechanism uses this to pass logical keyboard events
1a2339e902d4 commentary
Claus Gittinger <cg@exept.de>
parents: 251
diff changeset
   104
     to the application (such as #Copy, #Cut etc.) 
1a2339e902d4 commentary
Claus Gittinger <cg@exept.de>
parents: 251
diff changeset
   105
     instead of physical ones (such as #AltC, #AltX)"
1a2339e902d4 commentary
Claus Gittinger <cg@exept.de>
parents: 251
diff changeset
   106
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   107
    |submap|
48194c26a46c Initial revision
claus
parents:
diff changeset
   108
89
ea2bf46eb669 *** empty log message ***
claus
parents: 72
diff changeset
   109
    submap := self at:key1 ifAbsent:[].
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   110
    submap isNil ifTrue:[
598
1a2339e902d4 commentary
Claus Gittinger <cg@exept.de>
parents: 251
diff changeset
   111
        submap := KeyboardMap new.
1a2339e902d4 commentary
Claus Gittinger <cg@exept.de>
parents: 251
diff changeset
   112
        self at:key1 put:submap.
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   113
    ].
89
ea2bf46eb669 *** empty log message ***
claus
parents: 72
diff changeset
   114
    submap at:key2 put:logicalKey
598
1a2339e902d4 commentary
Claus Gittinger <cg@exept.de>
parents: 251
diff changeset
   115
1a2339e902d4 commentary
Claus Gittinger <cg@exept.de>
parents: 251
diff changeset
   116
    "Modified: 23.4.1996 / 21:55:04 / cg"
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   117
!
48194c26a46c Initial revision
claus
parents:
diff changeset
   118
6556
f2418ba5d1c5 class: KeyboardMap
Claus Gittinger <cg@exept.de>
parents: 5280
diff changeset
   119
hasBindingFor:aKey
f2418ba5d1c5 class: KeyboardMap
Claus Gittinger <cg@exept.de>
parents: 5280
diff changeset
   120
    "retrieve a logical key"
f2418ba5d1c5 class: KeyboardMap
Claus Gittinger <cg@exept.de>
parents: 5280
diff changeset
   121
f2418ba5d1c5 class: KeyboardMap
Claus Gittinger <cg@exept.de>
parents: 5280
diff changeset
   122
    |whichMap|
f2418ba5d1c5 class: KeyboardMap
Claus Gittinger <cg@exept.de>
parents: 5280
diff changeset
   123
f2418ba5d1c5 class: KeyboardMap
Claus Gittinger <cg@exept.de>
parents: 5280
diff changeset
   124
    whichMap := (current notNil ifTrue:[current] ifFalse:[self]).
f2418ba5d1c5 class: KeyboardMap
Claus Gittinger <cg@exept.de>
parents: 5280
diff changeset
   125
    ^ whichMap includesKey:aKey
f2418ba5d1c5 class: KeyboardMap
Claus Gittinger <cg@exept.de>
parents: 5280
diff changeset
   126
!
f2418ba5d1c5 class: KeyboardMap
Claus Gittinger <cg@exept.de>
parents: 5280
diff changeset
   127
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   128
valueFor:aKey
598
1a2339e902d4 commentary
Claus Gittinger <cg@exept.de>
parents: 251
diff changeset
   129
    "retrieve a logical key"
1a2339e902d4 commentary
Claus Gittinger <cg@exept.de>
parents: 251
diff changeset
   130
6556
f2418ba5d1c5 class: KeyboardMap
Claus Gittinger <cg@exept.de>
parents: 5280
diff changeset
   131
    |whichMap value|
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   132
6556
f2418ba5d1c5 class: KeyboardMap
Claus Gittinger <cg@exept.de>
parents: 5280
diff changeset
   133
    whichMap := (current notNil ifTrue:[current] ifFalse:[self]).
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   134
6556
f2418ba5d1c5 class: KeyboardMap
Claus Gittinger <cg@exept.de>
parents: 5280
diff changeset
   135
    value := whichMap at:aKey ifAbsent:aKey.
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   136
    (value isMemberOf:KeyboardMap) ifTrue:[
598
1a2339e902d4 commentary
Claus Gittinger <cg@exept.de>
parents: 251
diff changeset
   137
        current := value.
1a2339e902d4 commentary
Claus Gittinger <cg@exept.de>
parents: 251
diff changeset
   138
        ^ nil.
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   139
    ].
48194c26a46c Initial revision
claus
parents:
diff changeset
   140
    current := nil.
48194c26a46c Initial revision
claus
parents:
diff changeset
   141
    ^ value
598
1a2339e902d4 commentary
Claus Gittinger <cg@exept.de>
parents: 251
diff changeset
   142
1a2339e902d4 commentary
Claus Gittinger <cg@exept.de>
parents: 251
diff changeset
   143
    "Modified: 23.4.1996 / 21:55:22 / cg"
0
48194c26a46c Initial revision
claus
parents:
diff changeset
   144
! !
244
83218faf792c checkin from browser
Claus Gittinger <cg@exept.de>
parents: 219
diff changeset
   145
251
915de9a65169 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 244
diff changeset
   146
!KeyboardMap class methodsFor:'documentation'!
915de9a65169 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 244
diff changeset
   147
915de9a65169 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 244
diff changeset
   148
version
6663
a3d11f506f57 class: KeyboardMap
Claus Gittinger <cg@exept.de>
parents: 6556
diff changeset
   149
    ^ '$Header: /cvs/stx/stx/libview/KeyboardMap.st,v 1.15 2014-12-18 16:13:06 cg Exp $'
251
915de9a65169 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 244
diff changeset
   150
! !
6556
f2418ba5d1c5 class: KeyboardMap
Claus Gittinger <cg@exept.de>
parents: 5280
diff changeset
   151