MenuPanel.st
changeset 687 23ce9888d76f
parent 681 62c7cdaca188
child 689 aa13913add84
--- a/MenuPanel.st	Tue Jan 27 13:17:37 1998 +0100
+++ b/MenuPanel.st	Tue Jan 27 13:56:05 1998 +0100
@@ -12,37 +12,37 @@
 
 
 SimpleView subclass:#MenuPanel
-	instanceVariableNames:'adornment shadowView mapTime mustRearrange superMenu
-		shortKeyInset selection items groupSizes receiver enableChannel
-		menuHolder enabled onLevel offLevel fgColor activeFgColor
-		activeBgColor disabledFgColor groupDividerSize itemSpace
-		fitFirstPanel rightArrow rightArrowShadow'
-	classVariableNames:'InitialSelectionQuerySignal DefaultAdornment
-		DefaultGroupDividerSize DefaultHilightLevel DefaultLevel
-		DefaultItemSpace DefaultForegroundColor DefaultBackgroundColor
-		DefaultHilightForegroundColor DefaultHilightBackgroundColor
-		DefaultDisabledForegroundColor DefaultFitFirstPanel
-		RightArrowForm RightArrowShadowForm'
-	poolDictionaries:''
-	category:'Views-Menus'
+        instanceVariableNames:'adornment shadowView mapTime mustRearrange superMenu
+                shortKeyInset selection items groupSizes receiver enableChannel
+                menuHolder enabled onLevel offLevel fgColor activeFgColor
+                lastActiveMenu activeBgColor disabledFgColor groupDividerSize
+                itemSpace fitFirstPanel rightArrow rightArrowShadow'
+        classVariableNames:'InitialSelectionQuerySignal DefaultAdornment
+                DefaultGroupDividerSize DefaultHilightLevel DefaultLevel
+                DefaultItemSpace DefaultForegroundColor DefaultBackgroundColor
+                DefaultHilightForegroundColor DefaultHilightBackgroundColor
+                DefaultDisabledForegroundColor DefaultFitFirstPanel
+                RightArrowForm RightArrowShadowForm'
+        poolDictionaries:''
+        category:'Views-Menus'
 !
 
 Object subclass:#Item
-	instanceVariableNames:'layout menuPanel subMenu adornment rawLabel enableChannel nameKey
-		accessCharacterPosition value label activeHelpKey submenuChannel
-		disabledImage isButton'
-	classVariableNames:'HorizontalInset VerticalInset HorizontalButtonInset
-		VerticalButtonInset LabelRightOffset ShortcutKeyOffset
-		IndicatorOn IndicatorOff'
-	poolDictionaries:''
-	privateIn:MenuPanel
+        instanceVariableNames:'layout menuPanel subMenu adornment rawLabel enableChannel nameKey
+                accessCharacterPosition value label activeHelpKey submenuChannel
+                disabledImage isButton'
+        classVariableNames:'HorizontalInset VerticalInset HorizontalButtonInset
+                VerticalButtonInset LabelRightOffset ShortcutKeyOffset
+                IndicatorOn IndicatorOff'
+        poolDictionaries:''
+        privateIn:MenuPanel
 !
 
 Object subclass:#Adornment
-	instanceVariableNames:'indication accessCharacterPosition shortcutKey argument'
-	classVariableNames:''
-	poolDictionaries:''
-	privateIn:MenuPanel::Item
+        instanceVariableNames:'indication accessCharacterPosition shortcutKey argument'
+        classVariableNames:''
+        poolDictionaries:''
+        privateIn:MenuPanel::Item
 !
 
 !MenuPanel class methodsFor:'documentation'!
@@ -1564,7 +1564,6 @@
 
     shown ifFalse:[^ self].
 
-    super redrawX:x y:y width:w height:h.
     self  paint:(self backgroundColor).
     self  clearRectangleX:x y:y width:w height:h.
 
@@ -1769,19 +1768,26 @@
 buttonRelease:button x:x y:y
     "button release action; accept selection and close all views
     "
-    ( self hasSelection or:[
+    |menu|
+
+    menu := self lastActiveMenu.
+
+    ( menu hasSelection or:[
         (OperatingSystem millisecondTimeDeltaBetween:(Time millisecondClockValue)
-                                    and:mapTime) > 200]
+                                    and:(menu mapTime)) > 200]
     ) ifTrue:[
-        self accept
+        menu accept
     ]
 !
 
 cursorPressed:aKey
     "handle a cursor key
     "
-    |idx next first submenu item|
-
+    |next submenu item
+     n     "{ Class:SmallInteger }"
+     idx   "{ Class:SmallInteger }"
+     first "{ Class:SmallInteger }"
+    |
     (self hasSelection not and:[superMenu notNil]) ifTrue:[
         ^ superMenu cursorPressed:aKey
     ].
@@ -1804,27 +1810,28 @@
         ].
       ^ self
     ].
-
     first := self findFirst:[:el| el canSelect ].
     first == 0 ifTrue:[^ self].
 
     idx := self selectionIndex.
-
-    next ifTrue:[
-        [((idx := idx + 1) <= items size and:[(items at:idx) canSelect not])
-        ] whileTrue.
-
-        idx > items size ifTrue:[
-            idx := first
-        ].
-    ] ifFalse:[    
-        [((idx := idx - 1) > 0  and:[(items at:idx) canSelect not])
-        ] whileTrue.
-        
-        idx < 1 ifTrue:[ idx := self findLast:[:el| el canSelect ] ]
+    n   := 1 + (self sensor compressKeyPressEventsWithKey:aKey).
+
+    n timesRepeat:[
+        next ifTrue:[
+            [((idx := idx + 1) <= items size and:[(items at:idx) canSelect not])
+            ] whileTrue.
+
+            idx > items size ifTrue:[
+                idx := first
+            ].
+        ] ifFalse:[    
+            [((idx := idx - 1) > 0  and:[(items at:idx) canSelect not])
+            ] whileTrue.
+            
+            idx < 1 ifTrue:[ idx := self findLast:[:el| el canSelect ] ]
+        ]
     ].
     self selectionIndex:idx
-
 !
 
 keyPress:key x:x y:y
@@ -1909,6 +1916,10 @@
 
 !
 
+pointerLeave:aState
+    super pointerLeave:aState.
+!
+
 sizeChanged:how
     self isFitPanel ifTrue:[
         self mustRearrange.
@@ -1965,6 +1976,7 @@
                 sensor flushKeyboardFor:nil
             ].
             device grabKeyboardInView:self.
+
             superMenu notNil ifTrue:[
                 self getKeyboardFocus
             ]
@@ -1988,7 +2000,7 @@
     ] ifFalse:[
         sensor anyButtonPressed ifTrue:[
             ^ self grabMouseAndKeyboard
-        ]        
+        ]
     ].
 
     device activePointerGrab == self ifTrue:[
@@ -2004,9 +2016,10 @@
         ].
         device ungrabKeyboard.
     ].
+
     (superMenu notNil and:[superMenu shown and:[superMenu isPopUpView]]) ifTrue:[
         superMenu grabMouseAndKeyboard
-    ]
+    ].
 ! !
 
 !MenuPanel methodsFor:'initialize / release'!
@@ -2016,7 +2029,6 @@
     "
 
     super create.
-    self do:[:anItem| anItem fetchImages ].
 
     self isPopUpView ifTrue:[
         (PopUpView styleSheet at:'popup.shadow' default:false) ifTrue:[
@@ -2143,7 +2155,9 @@
     "
     |anItemList|
 
+    self do:[:anItem| anItem fetchImages ].
     mapTime := Time millisecondClockValue.
+    self topMenu lastActiveMenu:self.
     super mapped.
 
     anItemList := InitialSelectionQuerySignal raise.
@@ -2346,6 +2360,31 @@
 
 ! !
 
+!MenuPanel methodsFor:'private activation'!
+
+lastActiveMenu
+
+    superMenu notNil ifTrue:[
+        ^ superMenu lastActiveMenu
+    ].
+    ^ lastActiveMenu ? self
+
+!
+
+lastActiveMenu:aMenu
+
+    superMenu notNil ifTrue:[
+        superMenu lastActiveMenu:aMenu
+    ] ifFalse:[
+        lastActiveMenu := aMenu
+    ]
+
+!
+
+mapTime
+    ^ mapTime
+! !
+
 !MenuPanel methodsFor:'private searching'!
 
 itemAtX:x y:y
@@ -2524,7 +2563,6 @@
         hlp := ActiveHelp currentHelpListener.
         hlp initiateHelpFor:self atX:1 y:1 now:true.
     ].
-
     selection selected:true
 !
 
@@ -3508,11 +3546,19 @@
 fetchImages
     "fetch images
     "
+    |img|
+
     rawLabel isImage ifTrue:[
         self indicator isNil
             ifTrue:  [rawLabel := rawLabel onDevice:(menuPanel device)]
             ifFalse: [rawLabel := LabelAndIcon form:self indicator image:rawLabel]
+    ] ifFalse:[
+        rawLabel class == LabelAndIcon ifTrue:[
+            img := rawLabel icon onDevice:(menuPanel device).
+            rawLabel icon:img.
+        ]
     ]
+
 !
 
 in:aPanel
@@ -4017,6 +4063,6 @@
 !MenuPanel class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libwidg2/MenuPanel.st,v 1.51 1998-01-26 18:52:53 tz Exp $'
+    ^ '$Header: /cvs/stx/stx/libwidg2/MenuPanel.st,v 1.52 1998-01-27 12:56:05 ca Exp $'
 ! !
 MenuPanel initialize!