--- a/MenuPanel.st Wed Jul 19 09:12:10 2000 +0200
+++ b/MenuPanel.st Wed Jul 19 18:18:37 2000 +0200
@@ -2466,24 +2466,6 @@
!
-processShortcutKeyEventInMenuBar:event
- "an event as forwarded from the keyboardProcessor -
- if there is a short-key for that character, process it
- and return true. Otherwise, return false.
- "
- |key winGroup|
-
- key := event key.
-
- (self processShortcutKeyInMenuBar:key) ifTrue:[
- (selection notNil and:[(winGroup := self windowGroup) notNil]) ifTrue:[
- winGroup focusView:self
- ].
- ^ true
- ].
- ^ false
-!
-
sizeChanged:how
"redraw #right groups
"
@@ -2741,7 +2723,7 @@
handleKeyPress:key x:x y:y
"any key is pressed
"
- |item|
+ |item menu|
(key == #Return or:[key == Character space]) ifTrue:[
^ self accept.
@@ -2753,21 +2735,16 @@
) ifTrue:[
self handleCursorKey:key
] ifFalse:[
- self processShortcutKeyInMenuBar:key
+ self processShortcutKeyInMenuBarKey:key
+ rawKey:(device keyboardMap keyAtValue:key ifAbsent:key).
].
^ self
].
- (item := self detectItemForKey:key) notNil ifTrue:[
- self selection:item.
- ] ifFalse:[
- superMenu notNil ifTrue:[
- item := superMenu detectItemForKey:key.
-
- (item notNil or:[superMenu superMenu notNil]) ifTrue:[
- superMenu selection:item
- ]
- ]
+ menu := self hasSelection ifTrue:[self] ifFalse:[superMenu].
+
+ (menu notNil and:[(item := menu detectItemForKey:key) notNil]) ifTrue:[
+ menu selection:item
].
!
@@ -3146,7 +3123,7 @@
"grab the pointer here, when visible (but not if control has already been lost).
If the grab fails, try again and unmap myself if that fails too.
"
- |anItemList|
+ |loIndices|
enteredItem := nil.
@@ -3154,7 +3131,7 @@
self becomesActiveMenu.
super map.
- anItemList := InitialSelectionQuerySignal query.
+ loIndices := InitialSelectionQuerySignal query.
self do:[:anItem| anItem fetchImages ].
@@ -3165,9 +3142,9 @@
].
self do:[:el| el updateIndicators ].
- anItemList size > 0 ifTrue:[
+ loIndices size > 0 ifTrue:[
self redrawX:0 y:0 width:width height:height.
- self openMenusFromItems:anItemList.
+ self openMenusFromItemIndices:loIndices.
].
"Modified: / 19.11.1998 / 12:59:00 / cg"
@@ -3385,85 +3362,6 @@
!
-openMenusFromItems:anItemList
- "open all menus derived from sequence of items
- "
- |item|
-
- anItemList size == 0 ifTrue:[
- ^ self
- ].
-
- item := anItemList removeFirst.
-
- item enabled ifFalse:[
- ^ self
- ].
-
- InitialSelectionQuerySignal answer:anItemList do:[
- self selection:item
- ]
-!
-
-processShortcutKeyInMenuBar:aKey
- "if there is a short-key for that character, process it
- and return true. Otherwise, return false.
- "
- |rawKey loItems item maxDepth menu|
-
- superMenu notNil ifTrue:[
- "/ must start from topMenu
- ^ self topMenu processShortcutKeyInMenuBar:aKey
- ].
-
- "/ check whether the key can be a shortCutKey
-
- aKey isCharacter ifTrue:[^ false].
-
- ( #(
- #Meta_L #Meta_R
- #Control_R #Control_L
- #Shift_R #Shift_L
- #CursorUp #CursorDown
- #CursorLeft #CursorRight
- #Return #Tab
- #FocusNext #FocusPrevious
- #Escape
- ) includesIdentical:aKey
- ) ifTrue:[
- ^ false
- ].
-
- "/ cg: must limit the recursion (see GUIDemoToolBar - pressing CTRL in the recursive-link example)
-
- maxDepth := 10.
- rawKey := device keyboardMap keyAtValue:aKey ifAbsent:aKey.
- loItems := self selectItemsForShortcutKey:aKey rawKey:rawKey maxDepth:maxDepth.
-
- loItems size == 0 ifTrue:[
- ^ false
- ].
-
- item := loItems last.
-
- item hasSubmenu ifFalse:[
- self accept:item.
- ^ true
- ].
- menu := self.
-
- [menu selection == (loItems at:1)] whileTrue:[
- loItems removeFirst.
-
- loItems isEmpty ifTrue:[
- ^ false
- ].
- menu := selection submenu.
- ].
- menu openMenusFromItems:loItems.
- ^ true.
-!
-
registerImageOnDevice:anImage
|image|
@@ -3475,36 +3373,6 @@
image := image clearMaskedPixels.
].
^ image
-!
-
-selectItemsForShortcutKey:aKey rawKey:aRawKey maxDepth:maxDepth
- "get sequence of items up to the item providing the key (inclusive). The
- last entry into the collection is the item providing the key, the first
- entry is the item in the topMenu
- "
- |seq menu key|
-
- maxDepth <= 0 ifTrue:[^ nil].
-
- self do:[:anItem|
- key := anItem shortcutKey.
-
- (key notNil and:[(key == aKey or:[key == aRawKey])]) ifTrue:[
- anItem isEnabled ifFalse:[^ nil].
- seq := OrderedCollection new.
- ] ifFalse:[
- menu := anItem submenu.
-
- (menu notNil and:[anItem isEnabled]) ifTrue:[
- seq := menu selectItemsForShortcutKey:aKey rawKey:aRawKey maxDepth:maxDepth-1
- ]
- ].
- seq notNil ifTrue:[
- seq addFirst:anItem.
- ^ seq
- ]
- ].
- ^ nil
! !
!MenuPanel methodsFor:'private activation'!
@@ -3561,6 +3429,154 @@
"Modified: / 27.2.1998 / 17:41:18 / cg"
! !
+!MenuPanel methodsFor:'private keyboard-ctrl'!
+
+openMenusFromItemIndices:anItemIndiceList
+ "open all menus derived from sequence of item indices
+ "
+ |item|
+
+ anItemIndiceList size == 0 ifTrue:[
+ ^ self
+ ].
+ item := self itemAt:(anItemIndiceList removeFirst).
+
+ (item notNil and:[item enabled]) ifTrue:[
+ InitialSelectionQuerySignal answer:anItemIndiceList do:[
+ self selection:item
+ ]
+ ].
+
+!
+
+processShortcutKeyEventInMenuBar:ev
+ "an event as forwarded from the keyboardProcessor -
+ if there is a short-key for that character, process it
+ and return true. Otherwise, return false.
+ "
+ |winGroup|
+
+ (self processShortcutKeyInMenuBarKey:(ev key) rawKey:(ev rawKey)) ifTrue:[
+ (selection notNil and:[(winGroup := self windowGroup) notNil]) ifTrue:[
+ winGroup focusView:self
+ ].
+ ^ true
+ ].
+ ^ false
+!
+
+processShortcutKeyInMenuBarKey:aKey rawKey:rawKey
+ "if there is a short-key for that character, process it
+ and return true. Otherwise, return false.
+ "
+ |loIndices item maxDepth menu upperC lowerC|
+
+ superMenu notNil ifTrue:[
+ "/ must start from topMenu
+ ^ superMenu processShortcutKeyInMenuBarKey:aKey rawKey:rawKey
+ ].
+
+ "/ check whether the key can be a shortCutKey
+
+ aKey isCharacter ifTrue:[^ false].
+
+ ( #(
+ #Meta_L #Meta_R
+ #Control_R #Control_L
+ #Shift_R #Shift_L
+ #CursorUp #CursorDown
+ #CursorLeft #CursorRight
+ #Return #Tab
+ #FocusNext #FocusPrevious
+ #Escape
+ ) includesIdentical:aKey
+ ) ifTrue:[
+ ^ false
+ ].
+
+ "/ cg: must limit the recursion (see GUIDemoToolBar - pressing CTRL in the recursive-link example)
+
+ maxDepth := 10.
+ item := nil.
+ loIndices := self selectItemIndicesFor:[:anItem| |k|
+ item := anItem.
+ k := anItem shortcutKey.
+ k == aKey or:[k == rawKey]
+ ]
+ maxDepth:maxDepth.
+
+ loIndices size == 0 ifTrue:[
+ (rawKey size == 4 and:[rawKey startsWith:'Cmd']) ifTrue:[
+ upperC := (rawKey at:4) asUppercase.
+ lowerC := upperC asLowercase.
+
+ loIndices := self selectItemIndicesFor:[:anItem| |k|
+ k := anItem accessCharacter.
+ k == upperC or:[k == lowerC]
+ ]
+ maxDepth:maxDepth.
+ ].
+
+ loIndices size == 0 ifTrue:[
+ ^ false
+ ]
+ ] ifFalse:[
+ item hasSubmenu ifFalse:[
+ self accept:item.
+ ^ true
+ ].
+ ].
+ menu := self.
+
+ [menu selectionIndex == loIndices first] whileTrue:[
+ ( (item := menu selection) isNil "/ shouldn't happen
+ or:[(menu := item submenu) isNil] "/ no more indices; done
+ ) ifTrue:[
+ ^ true
+ ].
+ loIndices removeFirst.
+
+ loIndices isEmpty ifTrue:[
+ menu selection:nil.
+ ^ true
+ ]
+ ].
+ menu openMenusFromItemIndices:loIndices.
+ ^ true.
+!
+
+selectItemIndicesFor:aOneArgBlock maxDepth:maxDepth
+ "returns the sequence of indices up to the item for which the block
+ returns true. The first entry is the topmenu, the last entry the
+ item for which the block returns true.
+ If no item is detected, nil is returned
+ "
+ |seq menu key|
+
+ (maxDepth <= 0 or:[items isNil]) ifTrue:[
+ ^ nil
+ ].
+
+ items keysAndValuesDo:[:anIdx :anItem|
+ anItem isEnabled ifTrue:[
+ (aOneArgBlock value:anItem) ifTrue:[
+ seq := OrderedCollection new.
+ ] ifFalse:[
+ menu := anItem submenu.
+
+ (menu notNil and:[menu isEnabled]) ifTrue:[
+ seq := menu selectItemIndicesFor:aOneArgBlock maxDepth:(maxDepth - 1)
+ ]
+ ].
+ seq notNil ifTrue:[
+ seq addFirst:anIdx.
+ ^ seq
+ ]
+ ]
+ ].
+ ^ nil
+! !
+
!MenuPanel methodsFor:'private searching'!
detectGrabMenu
@@ -5774,6 +5790,6 @@
!MenuPanel class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libwidg2/MenuPanel.st,v 1.223 2000-07-13 05:42:04 ca Exp $'
+ ^ '$Header: /cvs/stx/stx/libwidg2/MenuPanel.st,v 1.224 2000-07-19 16:18:37 ca Exp $'
! !
MenuPanel initialize!