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