KeyboardProcessor.st
author sr
Mon, 13 May 2019 16:23:44 +0200
changeset 4262 b69be50550bb
parent 4141 9ddbf1c9d178
child 4397 7dff9bb71888
permissions -rw-r--r--
#BUGFIX by Stefan Reise class: ActiveHelp changed: #basicHelpTextFor:at: care for nil in #aDevicePointOrNil
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
4141
9ddbf1c9d178 #TUNING by sr
sr
parents: 3888
diff changeset
     1
"{ Encoding: utf8 }"
9ddbf1c9d178 #TUNING by sr
sr
parents: 3888
diff changeset
     2
1124
3dc83be3a3f9 moved from libcompat
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     3
"
3dc83be3a3f9 moved from libcompat
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     4
 COPYRIGHT (c) 1997 by eXept Software AG
3dc83be3a3f9 moved from libcompat
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     5
              All Rights Reserved
3dc83be3a3f9 moved from libcompat
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     6
3dc83be3a3f9 moved from libcompat
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     7
 This software is furnished under a license and may be used
3dc83be3a3f9 moved from libcompat
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     8
 only in accordance with the terms of that license and with the
3dc83be3a3f9 moved from libcompat
Claus Gittinger <cg@exept.de>
parents:
diff changeset
     9
 inclusion of the above copyright notice.   This software may not
3dc83be3a3f9 moved from libcompat
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    10
 be provided or otherwise made available to, or used by, any
3dc83be3a3f9 moved from libcompat
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    11
 other person.  No title to or ownership of the software is
3dc83be3a3f9 moved from libcompat
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    12
 hereby transferred.
3dc83be3a3f9 moved from libcompat
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    13
"
1388
b5ba6f0d434f category only
Claus Gittinger <cg@exept.de>
parents: 1310
diff changeset
    14
"{ Package: 'stx:libview2' }"
b5ba6f0d434f category only
Claus Gittinger <cg@exept.de>
parents: 1310
diff changeset
    15
3537
f53f7e886425 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3217
diff changeset
    16
"{ NameSpace: Smalltalk }"
f53f7e886425 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3217
diff changeset
    17
1124
3dc83be3a3f9 moved from libcompat
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    18
Object subclass:#KeyboardProcessor
1128
7810bca304e3 added autoAccept (editFields in dialogs)
Claus Gittinger <cg@exept.de>
parents: 1124
diff changeset
    19
	instanceVariableNames:'returnIsOKInDialog escapeIsCancelInDialog menuBar
2443
1043b37a4a5a Alt-key alone catches focus and selects first item
Claus Gittinger <cg@exept.de>
parents: 2400
diff changeset
    20
		autoAcceptListeners globalAccelerators componentWithInitialFocus
4141
9ddbf1c9d178 #TUNING by sr
sr
parents: 3888
diff changeset
    21
		altFunctionWasExecuted eventFilter returnAction cancelAction
9ddbf1c9d178 #TUNING by sr
sr
parents: 3888
diff changeset
    22
		unusedShortCutsCache'
1124
3dc83be3a3f9 moved from libcompat
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    23
	classVariableNames:''
3dc83be3a3f9 moved from libcompat
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    24
	poolDictionaries:''
2360
11ffbdb565f5 category change
Claus Gittinger <cg@exept.de>
parents: 2337
diff changeset
    25
	category:'Interface-Framework'
1124
3dc83be3a3f9 moved from libcompat
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    26
!
3dc83be3a3f9 moved from libcompat
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    27
3dc83be3a3f9 moved from libcompat
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    28
!KeyboardProcessor class methodsFor:'documentation'!
3dc83be3a3f9 moved from libcompat
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    29
3dc83be3a3f9 moved from libcompat
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    30
copyright
3dc83be3a3f9 moved from libcompat
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    31
"
3dc83be3a3f9 moved from libcompat
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    32
 COPYRIGHT (c) 1997 by eXept Software AG
3dc83be3a3f9 moved from libcompat
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    33
              All Rights Reserved
3dc83be3a3f9 moved from libcompat
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    34
3dc83be3a3f9 moved from libcompat
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    35
 This software is furnished under a license and may be used
3dc83be3a3f9 moved from libcompat
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    36
 only in accordance with the terms of that license and with the
3dc83be3a3f9 moved from libcompat
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    37
 inclusion of the above copyright notice.   This software may not
3dc83be3a3f9 moved from libcompat
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    38
 be provided or otherwise made available to, or used by, any
3dc83be3a3f9 moved from libcompat
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    39
 other person.  No title to or ownership of the software is
3dc83be3a3f9 moved from libcompat
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    40
 hereby transferred.
3dc83be3a3f9 moved from libcompat
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    41
"
3dc83be3a3f9 moved from libcompat
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    42
3dc83be3a3f9 moved from libcompat
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    43
3dc83be3a3f9 moved from libcompat
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    44
3dc83be3a3f9 moved from libcompat
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    45
3dc83be3a3f9 moved from libcompat
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    46
!
3dc83be3a3f9 moved from libcompat
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    47
3dc83be3a3f9 moved from libcompat
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    48
documentation
3dc83be3a3f9 moved from libcompat
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    49
"
3dc83be3a3f9 moved from libcompat
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    50
    ST80 compatibility (mimicry) class.
3dc83be3a3f9 moved from libcompat
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    51
3dc83be3a3f9 moved from libcompat
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    52
    The class is not completed yet and certainly not bug free.
3dc83be3a3f9 moved from libcompat
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    53
3dc83be3a3f9 moved from libcompat
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    54
    Notice: 
3dc83be3a3f9 moved from libcompat
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    55
        this class was implemented using protocol information
3dc83be3a3f9 moved from libcompat
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    56
        from alpha testers, literature and by reading public domain code
3dc83be3a3f9 moved from libcompat
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    57
        - it may not be complete or compatible to
3dc83be3a3f9 moved from libcompat
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    58
        the corresponding ST-80 class. 
3dc83be3a3f9 moved from libcompat
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    59
        If you encounter any incompatibilities, please forward a note 
3dc83be3a3f9 moved from libcompat
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    60
        describing the incompatibility verbal (i.e. no code) to the ST/X team.
3dc83be3a3f9 moved from libcompat
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    61
1160
Claus Gittinger <cg@exept.de>
parents: 1146
diff changeset
    62
    KeyboardProcessor is going to take over the focus control
Claus Gittinger <cg@exept.de>
parents: 1146
diff changeset
    63
    mechanism (which are currently located in the windowGroup).
Claus Gittinger <cg@exept.de>
parents: 1146
diff changeset
    64
    Currently, it keeps track of inputFields, and allows for
Claus Gittinger <cg@exept.de>
parents: 1146
diff changeset
    65
    a global accept to be forced.
Claus Gittinger <cg@exept.de>
parents: 1146
diff changeset
    66
    This is especially useful with dialogs, where a global accept
Claus Gittinger <cg@exept.de>
parents: 1146
diff changeset
    67
    should be performed on all inputFields, when the OK button
Claus Gittinger <cg@exept.de>
parents: 1146
diff changeset
    68
    is pressed.
Claus Gittinger <cg@exept.de>
parents: 1146
diff changeset
    69
2821
f4e296477b96 +eventFilter
Claus Gittinger <cg@exept.de>
parents: 2585
diff changeset
    70
    specials:
f4e296477b96 +eventFilter
Claus Gittinger <cg@exept.de>
parents: 2585
diff changeset
    71
        eventFilter ....................... if non-nil, a block to return false, if
f4e296477b96 +eventFilter
Claus Gittinger <cg@exept.de>
parents: 2585
diff changeset
    72
                                            the event is to be ignored.
f4e296477b96 +eventFilter
Claus Gittinger <cg@exept.de>
parents: 2585
diff changeset
    73
1124
3dc83be3a3f9 moved from libcompat
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    74
    [author:]
1160
Claus Gittinger <cg@exept.de>
parents: 1146
diff changeset
    75
        Claus Gittinger
1124
3dc83be3a3f9 moved from libcompat
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    76
"
3dc83be3a3f9 moved from libcompat
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    77
! !
3dc83be3a3f9 moved from libcompat
Claus Gittinger <cg@exept.de>
parents:
diff changeset
    78
1422
3d33f87160bf mnemonic-key support;
ca
parents: 1388
diff changeset
    79
!KeyboardProcessor class methodsFor:'defaults'!
3d33f87160bf mnemonic-key support;
ca
parents: 1388
diff changeset
    80
2488
ed0fabedfe4e also allow F-keys to be used as shortCuts (accelerators)
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
    81
isCommandKey:aKeyCode
ed0fabedfe4e also allow F-keys to be used as shortCuts (accelerators)
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
    82
    "returns true if the keyCode is for a Command key (such as Cmda)"
ed0fabedfe4e also allow F-keys to be used as shortCuts (accelerators)
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
    83
ed0fabedfe4e also allow F-keys to be used as shortCuts (accelerators)
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
    84
    ^ aKeyCode size == 4                   "/ only CMD-single letter !!
ed0fabedfe4e also allow F-keys to be used as shortCuts (accelerators)
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
    85
        and:[aKeyCode startsWith:'Cmd']    "/ CmdMenu for right-alt in vmware ???
ed0fabedfe4e also allow F-keys to be used as shortCuts (accelerators)
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
    86
!
ed0fabedfe4e also allow F-keys to be used as shortCuts (accelerators)
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
    87
ed0fabedfe4e also allow F-keys to be used as shortCuts (accelerators)
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
    88
isFunctionKey:aKeyCode
ed0fabedfe4e also allow F-keys to be used as shortCuts (accelerators)
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
    89
    "returns true if the key code is for a Function key (such as F10)"
ed0fabedfe4e also allow F-keys to be used as shortCuts (accelerators)
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
    90
ed0fabedfe4e also allow F-keys to be used as shortCuts (accelerators)
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
    91
    (aKeyCode startsWith:'F') ifTrue:[
ed0fabedfe4e also allow F-keys to be used as shortCuts (accelerators)
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
    92
        (aKeyCode size between:2 and:3) ifTrue:[   
ed0fabedfe4e also allow F-keys to be used as shortCuts (accelerators)
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
    93
            (aKeyCode at:2) isDigit ifFalse:[^ false].
ed0fabedfe4e also allow F-keys to be used as shortCuts (accelerators)
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
    94
            aKeyCode size == 2 ifTrue:[^ true].
ed0fabedfe4e also allow F-keys to be used as shortCuts (accelerators)
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
    95
            ^ (aKeyCode at:3) isDigit
ed0fabedfe4e also allow F-keys to be used as shortCuts (accelerators)
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
    96
        ].
ed0fabedfe4e also allow F-keys to be used as shortCuts (accelerators)
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
    97
    ].
ed0fabedfe4e also allow F-keys to be used as shortCuts (accelerators)
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
    98
    ^ false
ed0fabedfe4e also allow F-keys to be used as shortCuts (accelerators)
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
    99
!
ed0fabedfe4e also allow F-keys to be used as shortCuts (accelerators)
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
   100
1455
6d385add9b96 shortcut key processing (too slow)
Claus Gittinger <cg@exept.de>
parents: 1453
diff changeset
   101
isKeyEventIgnoredAsShortcut:aKeyEvent
6d385add9b96 shortcut key processing (too slow)
Claus Gittinger <cg@exept.de>
parents: 1453
diff changeset
   102
    "returns true if the key event ignored is a shortCut key
6d385add9b96 shortcut key processing (too slow)
Claus Gittinger <cg@exept.de>
parents: 1453
diff changeset
   103
    "
6d385add9b96 shortcut key processing (too slow)
Claus Gittinger <cg@exept.de>
parents: 1453
diff changeset
   104
    |rawKey|
6d385add9b96 shortcut key processing (too slow)
Claus Gittinger <cg@exept.de>
parents: 1453
diff changeset
   105
6d385add9b96 shortcut key processing (too slow)
Claus Gittinger <cg@exept.de>
parents: 1453
diff changeset
   106
    rawKey := aKeyEvent rawKey.
6d385add9b96 shortcut key processing (too slow)
Claus Gittinger <cg@exept.de>
parents: 1453
diff changeset
   107
    rawKey isSymbol ifFalse:[^ true].
1503
b3c4b1b1bfbb cursor keys ARE allowed as accelerators (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1499
diff changeset
   108
"/    "/ ignore cursor keys
b3c4b1b1bfbb cursor keys ARE allowed as accelerators (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1499
diff changeset
   109
"/    (#(
b3c4b1b1bfbb cursor keys ARE allowed as accelerators (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1499
diff changeset
   110
"/        Up Down Left Right 
b3c4b1b1bfbb cursor keys ARE allowed as accelerators (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1499
diff changeset
   111
"/        CursorUp CursorDown CursorLeft CursorRight
b3c4b1b1bfbb cursor keys ARE allowed as accelerators (is this a good idea ?)
Claus Gittinger <cg@exept.de>
parents: 1499
diff changeset
   112
"/    ) includes:rawKey) ifTrue:[^ true].
1455
6d385add9b96 shortcut key processing (too slow)
Claus Gittinger <cg@exept.de>
parents: 1453
diff changeset
   113
6d385add9b96 shortcut key processing (too slow)
Claus Gittinger <cg@exept.de>
parents: 1453
diff changeset
   114
    "/ ignore some meta keys
6d385add9b96 shortcut key processing (too slow)
Claus Gittinger <cg@exept.de>
parents: 1453
diff changeset
   115
    (#( 
1499
391ec6b1e6d9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1498
diff changeset
   116
        #'Control_L' #'Control_R' #'Control' #'Ctrl' 
391ec6b1e6d9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1498
diff changeset
   117
        #'CmdMenu' #'BackSpace' #Tab
2443
1043b37a4a5a Alt-key alone catches focus and selects first item
Claus Gittinger <cg@exept.de>
parents: 2400
diff changeset
   118
        #'Cmd_L' #'Cmd_R' #'Cmd' #'Menu' 
1499
391ec6b1e6d9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1498
diff changeset
   119
        #'Shift_L' #'Shift_R' Shift 
391ec6b1e6d9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1498
diff changeset
   120
        #'Alt_L' #'Alt_R' #'Alt'
391ec6b1e6d9 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1498
diff changeset
   121
        #'Super_R' #'Super_L' #'Super'
1455
6d385add9b96 shortcut key processing (too slow)
Claus Gittinger <cg@exept.de>
parents: 1453
diff changeset
   122
    ) includes:aKeyEvent key) ifTrue:[^ true].
6d385add9b96 shortcut key processing (too slow)
Claus Gittinger <cg@exept.de>
parents: 1453
diff changeset
   123
6d385add9b96 shortcut key processing (too slow)
Claus Gittinger <cg@exept.de>
parents: 1453
diff changeset
   124
    ^ false
6d385add9b96 shortcut key processing (too slow)
Claus Gittinger <cg@exept.de>
parents: 1453
diff changeset
   125
6d385add9b96 shortcut key processing (too slow)
Claus Gittinger <cg@exept.de>
parents: 1453
diff changeset
   126
    "Created: / 17.1.2001 / 11:57:07 / cg"
1457
59014aba97fe *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1456
diff changeset
   127
    "Modified: / 17.1.2001 / 13:05:46 / cg"
1455
6d385add9b96 shortcut key processing (too slow)
Claus Gittinger <cg@exept.de>
parents: 1453
diff changeset
   128
!
6d385add9b96 shortcut key processing (too slow)
Claus Gittinger <cg@exept.de>
parents: 1453
diff changeset
   129
1422
3d33f87160bf mnemonic-key support;
ca
parents: 1388
diff changeset
   130
isMnemonicKeyEvent:aKeyEvent
2386
db199be1fdff *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 2360
diff changeset
   131
    "returns true if the key event is a mnemonic key (such as Cmda)
1422
3d33f87160bf mnemonic-key support;
ca
parents: 1388
diff changeset
   132
    "
3d33f87160bf mnemonic-key support;
ca
parents: 1388
diff changeset
   133
    |rawKey|
3d33f87160bf mnemonic-key support;
ca
parents: 1388
diff changeset
   134
3d33f87160bf mnemonic-key support;
ca
parents: 1388
diff changeset
   135
    rawKey := aKeyEvent rawKey.
2488
ed0fabedfe4e also allow F-keys to be used as shortCuts (accelerators)
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
   136
    rawKey isSymbol ifFalse:[^ false].
ed0fabedfe4e also allow F-keys to be used as shortCuts (accelerators)
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
   137
    (self isCommandKey:rawKey) ifTrue:[^ true].
ed0fabedfe4e also allow F-keys to be used as shortCuts (accelerators)
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
   138
    (self isFunctionKey:rawKey) ifTrue:[^ true].
ed0fabedfe4e also allow F-keys to be used as shortCuts (accelerators)
Claus Gittinger <cg@exept.de>
parents: 2447
diff changeset
   139
    ^ false
1443
fecba7db7523 - rename #mnemonicViewNext: to #processMnemonic:
ca
parents: 1423
diff changeset
   140
! !
1422
3d33f87160bf mnemonic-key support;
ca
parents: 1388
diff changeset
   141
1763
fabe0b506e33 method category rename
Claus Gittinger <cg@exept.de>
parents: 1637
diff changeset
   142
!KeyboardProcessor methodsFor:'Compatibility-VW'!
1124
3dc83be3a3f9 moved from libcompat
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   143
3dc83be3a3f9 moved from libcompat
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   144
keyboardConsumers
3dc83be3a3f9 moved from libcompat
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   145
    ^ #()
3dc83be3a3f9 moved from libcompat
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   146
3dc83be3a3f9 moved from libcompat
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   147
    "Created: 6.3.1997 / 15:16:32 / cg"
3dc83be3a3f9 moved from libcompat
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   148
!
3dc83be3a3f9 moved from libcompat
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   149
3dc83be3a3f9 moved from libcompat
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   150
removeKeyboardReceiver:aController
3dc83be3a3f9 moved from libcompat
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   151
3dc83be3a3f9 moved from libcompat
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   152
    "Created: / 31.10.1997 / 01:56:54 / cg"
3dc83be3a3f9 moved from libcompat
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   153
!
3dc83be3a3f9 moved from libcompat
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   154
3dc83be3a3f9 moved from libcompat
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   155
sendKeyboardTo:aController
3dc83be3a3f9 moved from libcompat
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   156
3dc83be3a3f9 moved from libcompat
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   157
    "Created: / 31.10.1997 / 01:57:15 / cg"
3dc83be3a3f9 moved from libcompat
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   158
!
3dc83be3a3f9 moved from libcompat
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   159
3dc83be3a3f9 moved from libcompat
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   160
setActive:aWidget
3dc83be3a3f9 moved from libcompat
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   161
3dc83be3a3f9 moved from libcompat
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   162
    "Created: 3.3.1997 / 18:31:09 / cg"
3dc83be3a3f9 moved from libcompat
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   163
! !
3dc83be3a3f9 moved from libcompat
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   164
3dc83be3a3f9 moved from libcompat
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   165
!KeyboardProcessor methodsFor:'accessing'!
3dc83be3a3f9 moved from libcompat
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   166
1251
2b4223c2e092 added global accelerator
Claus Gittinger <cg@exept.de>
parents: 1160
diff changeset
   167
addAccelerator:aKey action:aSelectorOrBlock
2b4223c2e092 added global accelerator
Claus Gittinger <cg@exept.de>
parents: 1160
diff changeset
   168
    "add a global accelerator - these are handled even if no corresponding
2b4223c2e092 added global accelerator
Claus Gittinger <cg@exept.de>
parents: 1160
diff changeset
   169
     menu shortcut is defined"
2b4223c2e092 added global accelerator
Claus Gittinger <cg@exept.de>
parents: 1160
diff changeset
   170
2b4223c2e092 added global accelerator
Claus Gittinger <cg@exept.de>
parents: 1160
diff changeset
   171
    globalAccelerators isNil ifTrue:[
2b4223c2e092 added global accelerator
Claus Gittinger <cg@exept.de>
parents: 1160
diff changeset
   172
        globalAccelerators := Dictionary new
2b4223c2e092 added global accelerator
Claus Gittinger <cg@exept.de>
parents: 1160
diff changeset
   173
    ].
2b4223c2e092 added global accelerator
Claus Gittinger <cg@exept.de>
parents: 1160
diff changeset
   174
    globalAccelerators at:aKey put:aSelectorOrBlock
2b4223c2e092 added global accelerator
Claus Gittinger <cg@exept.de>
parents: 1160
diff changeset
   175
!
2b4223c2e092 added global accelerator
Claus Gittinger <cg@exept.de>
parents: 1160
diff changeset
   176
3537
f53f7e886425 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3217
diff changeset
   177
cancelAction:aBlock
f53f7e886425 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3217
diff changeset
   178
    "this entry allows for another cancel action to be installed,
f53f7e886425 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3217
diff changeset
   179
     to overwrite the default action, which closes a dialog without accept"
f53f7e886425 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3217
diff changeset
   180
     
f53f7e886425 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3217
diff changeset
   181
    cancelAction := aBlock.
f53f7e886425 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3217
diff changeset
   182
!
f53f7e886425 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3217
diff changeset
   183
1983
868f48812257 initial focus
Claus Gittinger <cg@exept.de>
parents: 1794
diff changeset
   184
componentWithInitialFocus
868f48812257 initial focus
Claus Gittinger <cg@exept.de>
parents: 1794
diff changeset
   185
    ^ componentWithInitialFocus
868f48812257 initial focus
Claus Gittinger <cg@exept.de>
parents: 1794
diff changeset
   186
!
868f48812257 initial focus
Claus Gittinger <cg@exept.de>
parents: 1794
diff changeset
   187
868f48812257 initial focus
Claus Gittinger <cg@exept.de>
parents: 1794
diff changeset
   188
componentWithInitialFocus:aComponent
868f48812257 initial focus
Claus Gittinger <cg@exept.de>
parents: 1794
diff changeset
   189
    componentWithInitialFocus := aComponent
868f48812257 initial focus
Claus Gittinger <cg@exept.de>
parents: 1794
diff changeset
   190
!
868f48812257 initial focus
Claus Gittinger <cg@exept.de>
parents: 1794
diff changeset
   191
1124
3dc83be3a3f9 moved from libcompat
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   192
escapeIsCancelInDialog:aBoolean
1128
7810bca304e3 added autoAccept (editFields in dialogs)
Claus Gittinger <cg@exept.de>
parents: 1124
diff changeset
   193
    "set the escapeIsCancel flag.
1635
f65f19dc255a escapeIsCancel/returnIsOK default
ca
parents: 1552
diff changeset
   194
     If off, Escape is NOT handled as cancel (the builder defaults it to true,)"
1128
7810bca304e3 added autoAccept (editFields in dialogs)
Claus Gittinger <cg@exept.de>
parents: 1124
diff changeset
   195
1124
3dc83be3a3f9 moved from libcompat
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   196
    escapeIsCancelInDialog := aBoolean
3dc83be3a3f9 moved from libcompat
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   197
!
3dc83be3a3f9 moved from libcompat
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   198
2821
f4e296477b96 +eventFilter
Claus Gittinger <cg@exept.de>
parents: 2585
diff changeset
   199
eventFilter:something
f4e296477b96 +eventFilter
Claus Gittinger <cg@exept.de>
parents: 2585
diff changeset
   200
    eventFilter := something.
f4e296477b96 +eventFilter
Claus Gittinger <cg@exept.de>
parents: 2585
diff changeset
   201
!
f4e296477b96 +eventFilter
Claus Gittinger <cg@exept.de>
parents: 2585
diff changeset
   202
1124
3dc83be3a3f9 moved from libcompat
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   203
menuBar
3dc83be3a3f9 moved from libcompat
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   204
    "return the value of the instance variable 'menuBar' (automatically generated)"
3dc83be3a3f9 moved from libcompat
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   205
1443
fecba7db7523 - rename #mnemonicViewNext: to #processMnemonic:
ca
parents: 1423
diff changeset
   206
    ^ menuBar
fecba7db7523 - rename #mnemonicViewNext: to #processMnemonic:
ca
parents: 1423
diff changeset
   207
!
1124
3dc83be3a3f9 moved from libcompat
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   208
3dc83be3a3f9 moved from libcompat
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   209
menuBar:something
3dc83be3a3f9 moved from libcompat
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   210
    "set the value of the instance variable 'menuBar' (automatically generated)"
3dc83be3a3f9 moved from libcompat
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   211
1443
fecba7db7523 - rename #mnemonicViewNext: to #processMnemonic:
ca
parents: 1423
diff changeset
   212
    menuBar := something.
fecba7db7523 - rename #mnemonicViewNext: to #processMnemonic:
ca
parents: 1423
diff changeset
   213
!
1124
3dc83be3a3f9 moved from libcompat
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   214
3537
f53f7e886425 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3217
diff changeset
   215
returnAction:aBlock
f53f7e886425 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3217
diff changeset
   216
    "this entry allows for another return action to be installed,
3695
9da18164cbfa #OTHER by mawalch
mawalch
parents: 3537
diff changeset
   217
     to overwrite the default action, which closes a dialog with accept"
3537
f53f7e886425 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3217
diff changeset
   218
f53f7e886425 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3217
diff changeset
   219
    returnAction := aBlock.
f53f7e886425 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3217
diff changeset
   220
!
f53f7e886425 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3217
diff changeset
   221
1124
3dc83be3a3f9 moved from libcompat
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   222
returnIsOKInDialog:aBoolean
1128
7810bca304e3 added autoAccept (editFields in dialogs)
Claus Gittinger <cg@exept.de>
parents: 1124
diff changeset
   223
    "set the returnIsOK flag.
1635
f65f19dc255a escapeIsCancel/returnIsOK default
ca
parents: 1552
diff changeset
   224
     If off, Return is NOT handled as accept (the builder defaults it to true,)"
1128
7810bca304e3 added autoAccept (editFields in dialogs)
Claus Gittinger <cg@exept.de>
parents: 1124
diff changeset
   225
1124
3dc83be3a3f9 moved from libcompat
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   226
    returnIsOKInDialog := aBoolean
3dc83be3a3f9 moved from libcompat
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   227
! !
3dc83be3a3f9 moved from libcompat
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   228
3dc83be3a3f9 moved from libcompat
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   229
!KeyboardProcessor methodsFor:'event handling'!
3dc83be3a3f9 moved from libcompat
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   230
1135
ee997fc311e2 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1134
diff changeset
   231
processEvent:event forModalView:modalTopOrNil
1128
7810bca304e3 added autoAccept (editFields in dialogs)
Claus Gittinger <cg@exept.de>
parents: 1124
diff changeset
   232
    "process a key-event; return true, if handled & eaten; false if not.
1251
2b4223c2e092 added global accelerator
Claus Gittinger <cg@exept.de>
parents: 1160
diff changeset
   233
     Here, first, we look for a globalAccelerator,
2b4223c2e092 added global accelerator
Claus Gittinger <cg@exept.de>
parents: 1160
diff changeset
   234
     then for Return and Escape in modal applications,
2b4223c2e092 added global accelerator
Claus Gittinger <cg@exept.de>
parents: 1160
diff changeset
   235
     (which lead to Accept & Cancel resp.)
2b4223c2e092 added global accelerator
Claus Gittinger <cg@exept.de>
parents: 1160
diff changeset
   236
     Finally, menu-shortcuts are handled."
1128
7810bca304e3 added autoAccept (editFields in dialogs)
Claus Gittinger <cg@exept.de>
parents: 1124
diff changeset
   237
3217
e055f3128039 class: KeyboardProcessor
Claus Gittinger <cg@exept.de>
parents: 2929
diff changeset
   238
    <resource: #keyboard (#Return #Escape #CloseWindowRequest)>
e055f3128039 class: KeyboardProcessor
Claus Gittinger <cg@exept.de>
parents: 2929
diff changeset
   239
4141
9ddbf1c9d178 #TUNING by sr
sr
parents: 3888
diff changeset
   240
    |key rawKey topView wg app view action explicitFocusView focusView isUnusedShortCut|
1124
3dc83be3a3f9 moved from libcompat
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   241
2443
1043b37a4a5a Alt-key alone catches focus and selects first item
Claus Gittinger <cg@exept.de>
parents: 2400
diff changeset
   242
    event isKeyEvent ifFalse:[ ^ false ].
1043b37a4a5a Alt-key alone catches focus and selects first item
Claus Gittinger <cg@exept.de>
parents: 2400
diff changeset
   243
2821
f4e296477b96 +eventFilter
Claus Gittinger <cg@exept.de>
parents: 2585
diff changeset
   244
    eventFilter notNil ifTrue:[
f4e296477b96 +eventFilter
Claus Gittinger <cg@exept.de>
parents: 2585
diff changeset
   245
        (eventFilter value:event) ifFalse:[
f4e296477b96 +eventFilter
Claus Gittinger <cg@exept.de>
parents: 2585
diff changeset
   246
            ^ false.
f4e296477b96 +eventFilter
Claus Gittinger <cg@exept.de>
parents: 2585
diff changeset
   247
        ]
f4e296477b96 +eventFilter
Claus Gittinger <cg@exept.de>
parents: 2585
diff changeset
   248
    ].
f4e296477b96 +eventFilter
Claus Gittinger <cg@exept.de>
parents: 2585
diff changeset
   249
2443
1043b37a4a5a Alt-key alone catches focus and selects first item
Claus Gittinger <cg@exept.de>
parents: 2400
diff changeset
   250
    key := event key.
1043b37a4a5a Alt-key alone catches focus and selects first item
Claus Gittinger <cg@exept.de>
parents: 2400
diff changeset
   251
    rawKey := event rawKey.
1043b37a4a5a Alt-key alone catches focus and selects first item
Claus Gittinger <cg@exept.de>
parents: 2400
diff changeset
   252
1124
3dc83be3a3f9 moved from libcompat
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   253
    view := event view.
3dc83be3a3f9 moved from libcompat
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   254
2929
fcf03ac9e8f5 changed: #processEvent:forModalView:
Claus Gittinger <cg@exept.de>
parents: 2821
diff changeset
   255
    topView := modalTopOrNil notNil ifTrue:[ modalTopOrNil ] ifFalse:[ view topView ].
2443
1043b37a4a5a Alt-key alone catches focus and selects first item
Claus Gittinger <cg@exept.de>
parents: 2400
diff changeset
   256
    wg := topView windowGroup.
1043b37a4a5a Alt-key alone catches focus and selects first item
Claus Gittinger <cg@exept.de>
parents: 2400
diff changeset
   257
    app := topView application.
1043b37a4a5a Alt-key alone catches focus and selects first item
Claus Gittinger <cg@exept.de>
parents: 2400
diff changeset
   258
1043b37a4a5a Alt-key alone catches focus and selects first item
Claus Gittinger <cg@exept.de>
parents: 2400
diff changeset
   259
    "/ little state machine, to detect if the alt-key was pressed
1043b37a4a5a Alt-key alone catches focus and selects first item
Claus Gittinger <cg@exept.de>
parents: 2400
diff changeset
   260
    "/ without a concrete command key.
1043b37a4a5a Alt-key alone catches focus and selects first item
Claus Gittinger <cg@exept.de>
parents: 2400
diff changeset
   261
    "/ this will bring the focus to the menuPanel, if there is one.
2447
ecb0212e1c8d ALT-key processing disabled (temporarily)
Claus Gittinger <cg@exept.de>
parents: 2443
diff changeset
   262
"/ cg: disabled for now;
ecb0212e1c8d ALT-key processing disabled (temporarily)
Claus Gittinger <cg@exept.de>
parents: 2443
diff changeset
   263
"/ leads to occasional leftover popupmenus floating around;
ecb0212e1c8d ALT-key processing disabled (temporarily)
Claus Gittinger <cg@exept.de>
parents: 2443
diff changeset
   264
"/ ca has to look for this first.
ecb0212e1c8d ALT-key processing disabled (temporarily)
Claus Gittinger <cg@exept.de>
parents: 2443
diff changeset
   265
false ifTrue:[
2443
1043b37a4a5a Alt-key alone catches focus and selects first item
Claus Gittinger <cg@exept.de>
parents: 2400
diff changeset
   266
    key = #'Cmd' ifTrue:[
1043b37a4a5a Alt-key alone catches focus and selects first item
Claus Gittinger <cg@exept.de>
parents: 2400
diff changeset
   267
        event isKeyPressEvent ifTrue:[
1043b37a4a5a Alt-key alone catches focus and selects first item
Claus Gittinger <cg@exept.de>
parents: 2400
diff changeset
   268
            altFunctionWasExecuted := false.
1043b37a4a5a Alt-key alone catches focus and selects first item
Claus Gittinger <cg@exept.de>
parents: 2400
diff changeset
   269
        ] ifFalse:[
1043b37a4a5a Alt-key alone catches focus and selects first item
Claus Gittinger <cg@exept.de>
parents: 2400
diff changeset
   270
            event isKeyReleaseEvent ifTrue:[
1043b37a4a5a Alt-key alone catches focus and selects first item
Claus Gittinger <cg@exept.de>
parents: 2400
diff changeset
   271
                altFunctionWasExecuted ifFalse:[
1043b37a4a5a Alt-key alone catches focus and selects first item
Claus Gittinger <cg@exept.de>
parents: 2400
diff changeset
   272
                    (wg processShortcut:event) ifTrue:[
1043b37a4a5a Alt-key alone catches focus and selects first item
Claus Gittinger <cg@exept.de>
parents: 2400
diff changeset
   273
                        ^ true
1043b37a4a5a Alt-key alone catches focus and selects first item
Claus Gittinger <cg@exept.de>
parents: 2400
diff changeset
   274
                    ].
1043b37a4a5a Alt-key alone catches focus and selects first item
Claus Gittinger <cg@exept.de>
parents: 2400
diff changeset
   275
                ].
1043b37a4a5a Alt-key alone catches focus and selects first item
Claus Gittinger <cg@exept.de>
parents: 2400
diff changeset
   276
            ].
1043b37a4a5a Alt-key alone catches focus and selects first item
Claus Gittinger <cg@exept.de>
parents: 2400
diff changeset
   277
        ].
1043b37a4a5a Alt-key alone catches focus and selects first item
Claus Gittinger <cg@exept.de>
parents: 2400
diff changeset
   278
    ] ifFalse:[
1043b37a4a5a Alt-key alone catches focus and selects first item
Claus Gittinger <cg@exept.de>
parents: 2400
diff changeset
   279
        altFunctionWasExecuted := true.
1043b37a4a5a Alt-key alone catches focus and selects first item
Claus Gittinger <cg@exept.de>
parents: 2400
diff changeset
   280
    ].
2447
ecb0212e1c8d ALT-key processing disabled (temporarily)
Claus Gittinger <cg@exept.de>
parents: 2443
diff changeset
   281
].
2443
1043b37a4a5a Alt-key alone catches focus and selects first item
Claus Gittinger <cg@exept.de>
parents: 2400
diff changeset
   282
1124
3dc83be3a3f9 moved from libcompat
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   283
    event isKeyPressEvent ifTrue:[
2443
1043b37a4a5a Alt-key alone catches focus and selects first item
Claus Gittinger <cg@exept.de>
parents: 2400
diff changeset
   284
        "/ key startsWith:'Cmd'
1124
3dc83be3a3f9 moved from libcompat
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   285
1251
2b4223c2e092 added global accelerator
Claus Gittinger <cg@exept.de>
parents: 1160
diff changeset
   286
        "/ how about global accelerators ?
2b4223c2e092 added global accelerator
Claus Gittinger <cg@exept.de>
parents: 1160
diff changeset
   287
        (globalAccelerators notNil
2b4223c2e092 added global accelerator
Claus Gittinger <cg@exept.de>
parents: 1160
diff changeset
   288
        and:[(action := globalAccelerators at:key ifAbsent:nil) notNil])
2b4223c2e092 added global accelerator
Claus Gittinger <cg@exept.de>
parents: 1160
diff changeset
   289
        ifTrue:[
1492
8a92a2d071ab *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1488
diff changeset
   290
            event consumed:true.
1251
2b4223c2e092 added global accelerator
Claus Gittinger <cg@exept.de>
parents: 1160
diff changeset
   291
            action isSymbol ifTrue:[
1422
3d33f87160bf mnemonic-key support;
ca
parents: 1388
diff changeset
   292
                app notNil ifTrue:[
2585
8b60021d3d15 return-key handling (dont care for non-keyboard-consumers)
Claus Gittinger <cg@exept.de>
parents: 2488
diff changeset
   293
                    app perform:action withOptionalArgument:event
1422
3d33f87160bf mnemonic-key support;
ca
parents: 1388
diff changeset
   294
                ]
1251
2b4223c2e092 added global accelerator
Claus Gittinger <cg@exept.de>
parents: 1160
diff changeset
   295
            ] ifFalse:[
2585
8b60021d3d15 return-key handling (dont care for non-keyboard-consumers)
Claus Gittinger <cg@exept.de>
parents: 2488
diff changeset
   296
                action valueWithOptionalArgument:event
1251
2b4223c2e092 added global accelerator
Claus Gittinger <cg@exept.de>
parents: 1160
diff changeset
   297
            ].
1492
8a92a2d071ab *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1488
diff changeset
   298
            "/ ^ true
8a92a2d071ab *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1488
diff changeset
   299
            ^ event consumed
1251
2b4223c2e092 added global accelerator
Claus Gittinger <cg@exept.de>
parents: 1160
diff changeset
   300
        ].
1488
9fa3505d2d85 optionBox: cancel-value corrected
Claus Gittinger <cg@exept.de>
parents: 1458
diff changeset
   301
9fa3505d2d85 optionBox: cancel-value corrected
Claus Gittinger <cg@exept.de>
parents: 1458
diff changeset
   302
        topView isModal ifTrue:[
3537
f53f7e886425 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3217
diff changeset
   303
            (key == #Return) ifTrue:[
f53f7e886425 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3217
diff changeset
   304
                returnAction notNil ifTrue:[
f53f7e886425 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3217
diff changeset
   305
                    returnAction value.
f53f7e886425 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3217
diff changeset
   306
                    ^ true.
f53f7e886425 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3217
diff changeset
   307
                ].    
f53f7e886425 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3217
diff changeset
   308
                (returnIsOKInDialog ? true) ifTrue:[
f53f7e886425 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3217
diff changeset
   309
                    (wg notNil 
f53f7e886425 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3217
diff changeset
   310
                    and:[(explicitFocusView := wg explicitFocusView) isNil
f53f7e886425 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3217
diff changeset
   311
                          or:[ false "explicitFocusView isKeyboardConsumer not" 
f53f7e886425 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3217
diff changeset
   312
                          or:[ explicitFocusView isInputField ]]
f53f7e886425 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3217
diff changeset
   313
                    ]) ifTrue:[
f53f7e886425 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3217
diff changeset
   314
                        ((focusView := wg focusView) notNil and:[focusView isTextView]) ifTrue:[
f53f7e886425 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3217
diff changeset
   315
                            focusView isInputField ifFalse:[
f53f7e886425 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3217
diff changeset
   316
                                "/ modalBox with a TextView
f53f7e886425 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3217
diff changeset
   317
                                ^ false
f53f7e886425 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3217
diff changeset
   318
                            ].
f53f7e886425 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3217
diff changeset
   319
                            "/ this is a kludge for subcanvases input-fields, which
f53f7e886425 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3217
diff changeset
   320
                            "/ are not affected by #requestGlobalAutoAccept below.
f53f7e886425 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3217
diff changeset
   321
                            focusView isAcceptOnReturn ifTrue:[
f53f7e886425 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3217
diff changeset
   322
                                focusView accept
f53f7e886425 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3217
diff changeset
   323
                            ].
f53f7e886425 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3217
diff changeset
   324
                        ].
f53f7e886425 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3217
diff changeset
   325
f53f7e886425 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3217
diff changeset
   326
                        self requestGlobalAutoAccept ifFalse:[^ true].
f53f7e886425 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3217
diff changeset
   327
f53f7e886425 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3217
diff changeset
   328
                        "/ only care for RETURN and ESC if the window is the
3888
72dcf9d128f0 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3695
diff changeset
   329
                        "/ apps topView (not if it's a popup or dialog of it)
3537
f53f7e886425 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3217
diff changeset
   330
                        (app notNil and:[app window == topView]) ifTrue:[
f53f7e886425 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3217
diff changeset
   331
                            app doAcceptByReturnKey.
f53f7e886425 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3217
diff changeset
   332
                        ] ifFalse:[
f53f7e886425 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3217
diff changeset
   333
                            "/ oldStyle modalBox - for now, let Box handle it itself
2007
014e4bfe31f1 must accept an inputField before
Claus Gittinger <cg@exept.de>
parents: 2006
diff changeset
   334
                            ^ false
014e4bfe31f1 must accept an inputField before
Claus Gittinger <cg@exept.de>
parents: 2006
diff changeset
   335
                        ].
3537
f53f7e886425 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3217
diff changeset
   336
                        ^ true
2006
83d2e7259fcf ignore return (do not close) if the current
Claus Gittinger <cg@exept.de>
parents: 1983
diff changeset
   337
                    ].
3537
f53f7e886425 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3217
diff changeset
   338
                ].
f53f7e886425 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3217
diff changeset
   339
            ].
f53f7e886425 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3217
diff changeset
   340
            (key == #Escape) ifTrue:[
f53f7e886425 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3217
diff changeset
   341
                cancelAction notNil ifTrue:[
f53f7e886425 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3217
diff changeset
   342
                    cancelAction value.
f53f7e886425 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3217
diff changeset
   343
                    ^ true.
f53f7e886425 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3217
diff changeset
   344
                ].    
f53f7e886425 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3217
diff changeset
   345
                (escapeIsCancelInDialog ? true) ifTrue:[
1636
c9ed206b5d32 escapeIsCancel/returnIsOK in popup with same app as mainapp
ca
parents: 1635
diff changeset
   346
                    "/ only care for RETURN and ESC if the window is the
c9ed206b5d32 escapeIsCancel/returnIsOK in popup with same app as mainapp
ca
parents: 1635
diff changeset
   347
                    "/ apps topView (not if its a popup or dialog of it)
c9ed206b5d32 escapeIsCancel/returnIsOK in popup with same app as mainapp
ca
parents: 1635
diff changeset
   348
                    (app notNil and:[app window == topView]) ifTrue:[
3537
f53f7e886425 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3217
diff changeset
   349
                        app doCancelByEscapeKey.
1488
9fa3505d2d85 optionBox: cancel-value corrected
Claus Gittinger <cg@exept.de>
parents: 1458
diff changeset
   350
                    ] ifFalse:[
9fa3505d2d85 optionBox: cancel-value corrected
Claus Gittinger <cg@exept.de>
parents: 1458
diff changeset
   351
                        "/ oldStyle modalBox - for now, let Box handle it itself
9fa3505d2d85 optionBox: cancel-value corrected
Claus Gittinger <cg@exept.de>
parents: 1458
diff changeset
   352
                        ^ false
1422
3d33f87160bf mnemonic-key support;
ca
parents: 1388
diff changeset
   353
                    ].
1134
758151d73aac only do autoAccept, if there is no focus view.
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   354
                    ^ true
758151d73aac only do autoAccept, if there is no focus view.
Claus Gittinger <cg@exept.de>
parents: 1133
diff changeset
   355
                ].
1124
3dc83be3a3f9 moved from libcompat
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   356
            ].
1422
3d33f87160bf mnemonic-key support;
ca
parents: 1388
diff changeset
   357
        ].
1488
9fa3505d2d85 optionBox: cancel-value corrected
Claus Gittinger <cg@exept.de>
parents: 1458
diff changeset
   358
1455
6d385add9b96 shortcut key processing (too slow)
Claus Gittinger <cg@exept.de>
parents: 1453
diff changeset
   359
        wg notNil ifTrue:[
6d385add9b96 shortcut key processing (too slow)
Claus Gittinger <cg@exept.de>
parents: 1453
diff changeset
   360
            (self class isMnemonicKeyEvent:event) ifTrue:[
1456
025fa88bf498 debug print
Claus Gittinger <cg@exept.de>
parents: 1455
diff changeset
   361
"/Transcript showCR:event rawKey.
025fa88bf498 debug print
Claus Gittinger <cg@exept.de>
parents: 1455
diff changeset
   362
"/Transcript showCR:event key.
1455
6d385add9b96 shortcut key processing (too slow)
Claus Gittinger <cg@exept.de>
parents: 1453
diff changeset
   363
                (wg processMnemonic:event) ifTrue:[
6d385add9b96 shortcut key processing (too slow)
Claus Gittinger <cg@exept.de>
parents: 1453
diff changeset
   364
                    ^ true
6d385add9b96 shortcut key processing (too slow)
Claus Gittinger <cg@exept.de>
parents: 1453
diff changeset
   365
                ]
6d385add9b96 shortcut key processing (too slow)
Claus Gittinger <cg@exept.de>
parents: 1453
diff changeset
   366
            ].
6d385add9b96 shortcut key processing (too slow)
Claus Gittinger <cg@exept.de>
parents: 1453
diff changeset
   367
            (self class isKeyEventIgnoredAsShortcut:event) ifFalse:[
1456
025fa88bf498 debug print
Claus Gittinger <cg@exept.de>
parents: 1455
diff changeset
   368
"/Transcript showCR:event rawKey.
025fa88bf498 debug print
Claus Gittinger <cg@exept.de>
parents: 1455
diff changeset
   369
"/Transcript showCR:event key.
4141
9ddbf1c9d178 #TUNING by sr
sr
parents: 3888
diff changeset
   370
9ddbf1c9d178 #TUNING by sr
sr
parents: 3888
diff changeset
   371
                "sr: after discussion with cg,
9ddbf1c9d178 #TUNING by sr
sr
parents: 3888
diff changeset
   372
                 we decided to cache shortcuts with no actions.
9ddbf1c9d178 #TUNING by sr
sr
parents: 3888
diff changeset
   373
                 we also know about the fact that this will ignore short cuts 
9ddbf1c9d178 #TUNING by sr
sr
parents: 3888
diff changeset
   374
                 from dynamic menus/views (but we decided to dont care)"
9ddbf1c9d178 #TUNING by sr
sr
parents: 3888
diff changeset
   375
                isUnusedShortCut := false.
9ddbf1c9d178 #TUNING by sr
sr
parents: 3888
diff changeset
   376
9ddbf1c9d178 #TUNING by sr
sr
parents: 3888
diff changeset
   377
                (rawKey notNil 
9ddbf1c9d178 #TUNING by sr
sr
parents: 3888
diff changeset
   378
                and:[unusedShortCutsCache notNil]) ifTrue:[
9ddbf1c9d178 #TUNING by sr
sr
parents: 3888
diff changeset
   379
                    (unusedShortCutsCache includesIdentical:rawKey asSymbol) ifTrue:[
9ddbf1c9d178 #TUNING by sr
sr
parents: 3888
diff changeset
   380
                        isUnusedShortCut := true.
9ddbf1c9d178 #TUNING by sr
sr
parents: 3888
diff changeset
   381
                    ].    
9ddbf1c9d178 #TUNING by sr
sr
parents: 3888
diff changeset
   382
                ].    
9ddbf1c9d178 #TUNING by sr
sr
parents: 3888
diff changeset
   383
9ddbf1c9d178 #TUNING by sr
sr
parents: 3888
diff changeset
   384
                isUnusedShortCut ifFalse:[
9ddbf1c9d178 #TUNING by sr
sr
parents: 3888
diff changeset
   385
                    (wg processShortcut:event) ifTrue:[
9ddbf1c9d178 #TUNING by sr
sr
parents: 3888
diff changeset
   386
                        ^ true
9ddbf1c9d178 #TUNING by sr
sr
parents: 3888
diff changeset
   387
                    ] ifFalse:[
9ddbf1c9d178 #TUNING by sr
sr
parents: 3888
diff changeset
   388
                        unusedShortCutsCache isNil ifTrue:[
9ddbf1c9d178 #TUNING by sr
sr
parents: 3888
diff changeset
   389
                            "sr: I dont care about sync here,
9ddbf1c9d178 #TUNING by sr
sr
parents: 3888
diff changeset
   390
                             because in worst case some shortcuts are calculated (to be unused) twice"
9ddbf1c9d178 #TUNING by sr
sr
parents: 3888
diff changeset
   391
                            unusedShortCutsCache := IdentitySet new.    
9ddbf1c9d178 #TUNING by sr
sr
parents: 3888
diff changeset
   392
                        ].    
9ddbf1c9d178 #TUNING by sr
sr
parents: 3888
diff changeset
   393
9ddbf1c9d178 #TUNING by sr
sr
parents: 3888
diff changeset
   394
                        unusedShortCutsCache add:rawKey asSymbol
9ddbf1c9d178 #TUNING by sr
sr
parents: 3888
diff changeset
   395
                    ].
9ddbf1c9d178 #TUNING by sr
sr
parents: 3888
diff changeset
   396
                ].    
1124
3dc83be3a3f9 moved from libcompat
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   397
            ].
2400
b47e642dd9bc support ALT-F4 (close window)
Claus Gittinger <cg@exept.de>
parents: 2398
diff changeset
   398
        ].
b47e642dd9bc support ALT-F4 (close window)
Claus Gittinger <cg@exept.de>
parents: 2398
diff changeset
   399
        "/ support ALT-F4 (close window)
b47e642dd9bc support ALT-F4 (close window)
Claus Gittinger <cg@exept.de>
parents: 2398
diff changeset
   400
        (key == #CloseWindowRequest) ifTrue:[
b47e642dd9bc support ALT-F4 (close window)
Claus Gittinger <cg@exept.de>
parents: 2398
diff changeset
   401
            app notNil ifTrue:[
b47e642dd9bc support ALT-F4 (close window)
Claus Gittinger <cg@exept.de>
parents: 2398
diff changeset
   402
                app closeRequest
b47e642dd9bc support ALT-F4 (close window)
Claus Gittinger <cg@exept.de>
parents: 2398
diff changeset
   403
            ] ifFalse:[
b47e642dd9bc support ALT-F4 (close window)
Claus Gittinger <cg@exept.de>
parents: 2398
diff changeset
   404
                topView closeRequest
b47e642dd9bc support ALT-F4 (close window)
Claus Gittinger <cg@exept.de>
parents: 2398
diff changeset
   405
            ].
b47e642dd9bc support ALT-F4 (close window)
Claus Gittinger <cg@exept.de>
parents: 2398
diff changeset
   406
        ].
1124
3dc83be3a3f9 moved from libcompat
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   407
    ].
3dc83be3a3f9 moved from libcompat
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   408
1423
0e391ec230be *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1422
diff changeset
   409
    "/ let view dispatch it.
1128
7810bca304e3 added autoAccept (editFields in dialogs)
Claus Gittinger <cg@exept.de>
parents: 1124
diff changeset
   410
    ^ false
1455
6d385add9b96 shortcut key processing (too slow)
Claus Gittinger <cg@exept.de>
parents: 1453
diff changeset
   411
2929
fcf03ac9e8f5 changed: #processEvent:forModalView:
Claus Gittinger <cg@exept.de>
parents: 2821
diff changeset
   412
    "Modified: / 18-07-2011 / 09:47:57 / cg"
3888
72dcf9d128f0 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3695
diff changeset
   413
    "Modified (comment): / 13-02-2017 / 20:26:23 / cg"
4141
9ddbf1c9d178 #TUNING by sr
sr
parents: 3888
diff changeset
   414
    "Modified: / 03-07-2018 / 16:14:09 / sr"
1423
0e391ec230be *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1422
diff changeset
   415
!
1124
3dc83be3a3f9 moved from libcompat
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   416
3dc83be3a3f9 moved from libcompat
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   417
requestForWindowClose
1128
7810bca304e3 added autoAccept (editFields in dialogs)
Claus Gittinger <cg@exept.de>
parents: 1124
diff changeset
   418
     "about to close the window."
1124
3dc83be3a3f9 moved from libcompat
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   419
1128
7810bca304e3 added autoAccept (editFields in dialogs)
Claus Gittinger <cg@exept.de>
parents: 1124
diff changeset
   420
     ^ true
1124
3dc83be3a3f9 moved from libcompat
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   421
!
3dc83be3a3f9 moved from libcompat
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   422
3dc83be3a3f9 moved from libcompat
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   423
requestGlobalAutoAccept
1128
7810bca304e3 added autoAccept (editFields in dialogs)
Claus Gittinger <cg@exept.de>
parents: 1124
diff changeset
   424
     "about to close the window via return ok accept.
7810bca304e3 added autoAccept (editFields in dialogs)
Claus Gittinger <cg@exept.de>
parents: 1124
diff changeset
   425
      Ask all acceptListeners to accept their value and return true, if all of those fields
7810bca304e3 added autoAccept (editFields in dialogs)
Claus Gittinger <cg@exept.de>
parents: 1124
diff changeset
   426
      did."
1124
3dc83be3a3f9 moved from libcompat
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   427
1128
7810bca304e3 added autoAccept (editFields in dialogs)
Claus Gittinger <cg@exept.de>
parents: 1124
diff changeset
   428
    autoAcceptListeners notNil ifTrue:[
2249
150a384a74a6 code cleanup: use #contains/#conform instead of explicit loop
Claus Gittinger <cg@exept.de>
parents: 2008
diff changeset
   429
        ^ autoAcceptListeners conform:[:aListener | (aListener requestAutoAccept)]
1128
7810bca304e3 added autoAccept (editFields in dialogs)
Claus Gittinger <cg@exept.de>
parents: 1124
diff changeset
   430
    ].
1458
43c22152a2f5 accept autoAccept (RETURN) if no input field widget is present
Claus Gittinger <cg@exept.de>
parents: 1457
diff changeset
   431
    "/ if no input field (or comparable widget) is present ...
43c22152a2f5 accept autoAccept (RETURN) if no input field widget is present
Claus Gittinger <cg@exept.de>
parents: 1457
diff changeset
   432
"/    ^ false     <- wrong.
43c22152a2f5 accept autoAccept (RETURN) if no input field widget is present
Claus Gittinger <cg@exept.de>
parents: 1457
diff changeset
   433
    ^ true.
2249
150a384a74a6 code cleanup: use #contains/#conform instead of explicit loop
Claus Gittinger <cg@exept.de>
parents: 2008
diff changeset
   434
150a384a74a6 code cleanup: use #contains/#conform instead of explicit loop
Claus Gittinger <cg@exept.de>
parents: 2008
diff changeset
   435
    "Modified: / 13-10-2006 / 12:56:02 / cg"
1124
3dc83be3a3f9 moved from libcompat
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   436
! !
3dc83be3a3f9 moved from libcompat
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   437
1128
7810bca304e3 added autoAccept (editFields in dialogs)
Claus Gittinger <cg@exept.de>
parents: 1124
diff changeset
   438
!KeyboardProcessor methodsFor:'setup'!
7810bca304e3 added autoAccept (editFields in dialogs)
Claus Gittinger <cg@exept.de>
parents: 1124
diff changeset
   439
7810bca304e3 added autoAccept (editFields in dialogs)
Claus Gittinger <cg@exept.de>
parents: 1124
diff changeset
   440
addAutoAcceptListener:aListener
7810bca304e3 added autoAccept (editFields in dialogs)
Claus Gittinger <cg@exept.de>
parents: 1124
diff changeset
   441
    "add a aListener to my autoAcceptListeners.
7810bca304e3 added autoAccept (editFields in dialogs)
Claus Gittinger <cg@exept.de>
parents: 1124
diff changeset
   442
     Typically, inputFields add themself, to be notified (via requestForAutoAccept)
7810bca304e3 added autoAccept (editFields in dialogs)
Claus Gittinger <cg@exept.de>
parents: 1124
diff changeset
   443
     when the dialog is about to be closed with returnIsOK or accept.
7810bca304e3 added autoAccept (editFields in dialogs)
Claus Gittinger <cg@exept.de>
parents: 1124
diff changeset
   444
     (of course, other listeners are also invited ;-)"
7810bca304e3 added autoAccept (editFields in dialogs)
Claus Gittinger <cg@exept.de>
parents: 1124
diff changeset
   445
7810bca304e3 added autoAccept (editFields in dialogs)
Claus Gittinger <cg@exept.de>
parents: 1124
diff changeset
   446
    autoAcceptListeners isNil ifTrue:[
7810bca304e3 added autoAccept (editFields in dialogs)
Claus Gittinger <cg@exept.de>
parents: 1124
diff changeset
   447
        autoAcceptListeners := IdentitySet new.
7810bca304e3 added autoAccept (editFields in dialogs)
Claus Gittinger <cg@exept.de>
parents: 1124
diff changeset
   448
    ].
7810bca304e3 added autoAccept (editFields in dialogs)
Claus Gittinger <cg@exept.de>
parents: 1124
diff changeset
   449
    autoAcceptListeners add:aListener
7810bca304e3 added autoAccept (editFields in dialogs)
Claus Gittinger <cg@exept.de>
parents: 1124
diff changeset
   450
! !
7810bca304e3 added autoAccept (editFields in dialogs)
Claus Gittinger <cg@exept.de>
parents: 1124
diff changeset
   451
1124
3dc83be3a3f9 moved from libcompat
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   452
!KeyboardProcessor class methodsFor:'documentation'!
3dc83be3a3f9 moved from libcompat
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   453
3dc83be3a3f9 moved from libcompat
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   454
version
3537
f53f7e886425 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3217
diff changeset
   455
    ^ '$Header$'
2821
f4e296477b96 +eventFilter
Claus Gittinger <cg@exept.de>
parents: 2585
diff changeset
   456
!
f4e296477b96 +eventFilter
Claus Gittinger <cg@exept.de>
parents: 2585
diff changeset
   457
f4e296477b96 +eventFilter
Claus Gittinger <cg@exept.de>
parents: 2585
diff changeset
   458
version_CVS
3537
f53f7e886425 #FEATURE
Claus Gittinger <cg@exept.de>
parents: 3217
diff changeset
   459
    ^ '$Header$'
1124
3dc83be3a3f9 moved from libcompat
Claus Gittinger <cg@exept.de>
parents:
diff changeset
   460
! !
3217
e055f3128039 class: KeyboardProcessor
Claus Gittinger <cg@exept.de>
parents: 2929
diff changeset
   461