'From Squeak3.2alpha of 2 October 2001 [latest update: #4593] on 10 December 2001 at 8:21 am'! "Change Set: MenuFocusTweak Date: 10 December 2001 Author: Dan Ingalls A couple of minor changes for better keyboard control of menus: Keyboard focus feedback (the narrow inner border on menus) is now only shown on menus in which keyboard control is being used. Menus that are popped up with no mouse button pressed now have their first item selected for better feedback and simpler operation from the keyboard. Removed the gratuitous balloon help on menus invoked by ESC. "! !MenuMorph methodsFor: 'accessing' stamp: 'di 12/9/2001 19:56'! rootMenu ((popUpOwner ifNil: [^ self]) owner ifNil: [^ self]) rootMenu! ! !MenuMorph methodsFor: 'keyboard control' stamp: 'di 12/10/2001 06:45'! keyStroke: evt | matchString char asc selectable | self deleteBalloon. (self rootMenu hasProperty: #hasUsedKeyboard) ifFalse: [self rootMenu setProperty: #hasUsedKeyboard toValue: true. self changed]. (evt commandKeyPressed and: [self commandKeyHandler notNil]) ifTrue: [self commandKeyHandler commandKeyTypedIntoMenu: evt. ^ self deleteIfPopUp: evt]. char _ evt keyCharacter. char = Character cr ifTrue: [selectedItem ifNotNil: [selectedItem hasSubMenu ifTrue: [evt hand newMouseFocus: selectedItem subMenu. ^ evt hand newKeyboardFocus: selectedItem subMenu] ifFalse: ["self delete." ^ selectedItem invokeWithEvent: evt]]. (selectable _ self items) size = 1 ifTrue: [^ selectable first invokeWithEvent: evt]. ^ self]. ((asc _ char asciiValue) between: 27 and: 31) ifTrue: [asc = 27 ifTrue: "escape key" [(self hasProperty: #matchString) ifTrue: ["If filtered, first ESC removes filter" self selectItem: nil event: evt. self removeProperty: #matchString. self removeAllMorphs. ^ self addAllMorphs: (self valueOfProperty: #originalSubmorphs)]. "If a stand-alone menu, just delete it" popUpOwner == nil ifTrue: [^ self delete]. "If a sub-menu, then deselect, and return focus to outer menu" self selectItem: nil event: evt. evt hand newMouseFocus: popUpOwner owner. ^ evt hand newKeyboardFocus: popUpOwner owner]. (asc = 28 or: [asc = 29]) ifTrue: "left or right arrow key" [(selectedItem ~~ nil and: [selectedItem hasSubMenu]) ifTrue: [evt hand newMouseFocus: selectedItem subMenu. selectedItem subMenu moveSelectionDown: 1 event: evt. ^ evt hand newKeyboardFocus: selectedItem subMenu]]. asc = 30 ifTrue: [^ self moveSelectionDown: -1 event: evt]. "up arrow key" asc = 31 ifTrue: [^ self moveSelectionDown: 1 event: evt]. "down arrow key" ]. asc = 11 ifTrue: [^ self moveSelectionDown: -5 event: evt]. "page up key" asc = 12 ifTrue: [^ self moveSelectionDown: 5 event: evt]. "page down key" matchString _ self valueOfProperty: #matchString ifAbsent: [self setProperty: #matchString toValue: String new. self setProperty: #originalSubmorphs toValue: submorphs copy. String new]. matchString _ char = Character backspace ifTrue: [matchString isEmpty ifTrue: [matchString] ifFalse: [matchString allButLast]] ifFalse: [matchString copyWith: evt keyCharacter]. self setProperty: #matchString toValue: matchString. self displayFiltered: evt! ! !MenuMorph methodsFor: 'control' stamp: 'di 12/10/2001 08:08'! popUpAt: aPoint forHand: hand in: aWorld "Present this menu at the given point under control of the given hand." | evt | self items isEmpty ifTrue: [^ self]. self positionAt: aPoint relativeTo: (selectedItem ifNil:[self items first]) inWorld: aWorld. aWorld addMorphFront: self; startSteppingSubmorphsOf: self. "Aquire focus for valid pop up behavior" hand newMouseFocus: self. hand newKeyboardFocus: self. evt _ hand lastEvent. (evt isKeyboard or: [evt isMouse and: [evt anyButtonPressed not]]) ifTrue: ["Select first item if button not down" self moveSelectionDown: 1 event: evt]. self changed! ! !MenuMorph methodsFor: 'drawing' stamp: 'di 12/9/2001 20:03'! drawOn: aCanvas "Draw the menu. Add keyboard-focus feedback if appropriate" super drawOn: aCanvas. (ActiveHand keyboardFocus == self and: [self rootMenu hasProperty: #hasUsedKeyboard]) ifTrue: [aCanvas frameAndFillRectangle: self innerBounds fillColor: Color transparent borderWidth: 1 borderColor: Preferences keyboardFocusColor]! ! !PasteUpMorph methodsFor: 'world menu' stamp: 'di 12/10/2001 08:19'! putUpWorldMenuFromEscapeKey (self putUpWorldMenu: ActiveEvent) setProperty: #hasUsedKeyboard toValue: true; changed! !