implement button behaviour
authorca
Mon, 09 Mar 1998 17:13:28 +0100
changeset 816 8f8f8e19d983
parent 815 c5d303ab52d2
child 817 f6d08ea5b82b
implement button behaviour
MenuPanel.st
--- a/MenuPanel.st	Mon Mar 09 17:10:52 1998 +0100
+++ b/MenuPanel.st	Mon Mar 09 17:13:28 1998 +0100
@@ -19,7 +19,7 @@
 		itemSpace fitFirstPanel rightArrow rightArrowShadow
 		selectionFrameBrightColor selectionFrameDarkColor
 		buttonLightColor buttonShadowColor buttonHalfLightColor
-		buttonHalfShadowColor'
+		buttonHalfShadowColor lastButtonSelected'
 	classVariableNames:'InitialSelectionQuerySignal DefaultAdornment
 		DefaultGroupDividerSize DefaultHilightLevel DefaultLevel
 		DefaultItemSpace DefaultForegroundColor DefaultBackgroundColor
@@ -499,7 +499,7 @@
     self superMenu notNil ifTrue:[
         ^ self topMenu accept:anItem
     ].
-
+    lastButtonSelected := nil.
     self selection:nil.
     self forceUngrabMouseAndKeyboard.
 
@@ -1948,7 +1948,7 @@
 buttonMotion:state x:x y:y
     "open or close the corresponding submenus
     "
-    |menu point sensor|
+    |menu point sensor sel|
 
     (    (sensor := self sensor) notNil
      and:[sensor hasButtonMotionEventFor:nil]
@@ -1956,8 +1956,17 @@
         ^ self
     ].
 
+    lastButtonSelected notNil ifTrue:[
+        ^ self
+    ].
+
     (self containsPointX:x y:y) ifTrue:[
-        ^ self selection:(self itemAtX:x y:y)
+        ((sel := self itemAtX:x y:y) notNil and:[sel isButton and:[superMenu isNil]]) ifTrue:[
+            sel canSelect ifTrue:[
+                lastButtonSelected := sel
+            ]
+        ].
+        ^ self selection:sel
     ].
 
     menu := self superMenuAtX:x y:y.
@@ -1988,7 +1997,7 @@
 buttonRelease:button x:x y:y
     "button release action; accept selection and close all views
     "
-    |menu|
+    |menu item|
 
     menu := self topMenu activeMenu.
 
@@ -1997,7 +2006,22 @@
      or:[(OperatingSystem millisecondTimeDeltaBetween:(Time millisecondClockValue)
                                 and:(menu mapTime)) > 200]]
     ) ifTrue:[
-        menu accept
+        item := nil.
+
+        (     (menu := self superMenuAtX:x y:y) notNil
+         and:[(item := menu selection) notNil
+         and:[item submenu notNil]]
+        ) ifTrue:[
+            menu selection:nil
+        ] ifFalse:[
+            (    lastButtonSelected isNil
+             or:[item isNil
+             or:[(menu itemAtX:x y:y) == lastButtonSelected]]
+            ) ifFalse:[
+                item := nil
+            ].
+            self topMenu accept:item
+        ]
     ].
 
     "Modified: / 27.2.1998 / 17:41:23 / cg"
@@ -2402,6 +2426,7 @@
     |anItemList|
 
     self do:[:anItem| anItem fetchImages ].
+    lastButtonSelected := nil.
     self becomesActiveMenu.
     super mapped.
 
@@ -4397,7 +4422,7 @@
     ].
     subMenu fixSize.
     subMenu origin:aPoint.
-    subMenu makeFullyVisible.
+"/    subMenu makeFullyVisible.
     top := menuPanel topMenu.
 
     subMenu realized ifFalse:[
@@ -4405,6 +4430,8 @@
     ] ifTrue:[
         top device mapWindow:subMenu id.
     ].
+    subMenu makeFullyVisible.
+
 
 "/    (top styleSheet at:'menu.autoSelectFirst') ifTrue:[
 "/        subMenu selectionIndex:1
@@ -4501,6 +4528,6 @@
 !MenuPanel class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libwidg2/MenuPanel.st,v 1.77 1998-02-27 17:44:54 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libwidg2/MenuPanel.st,v 1.78 1998-03-09 16:13:28 ca Exp $'
 ! !
 MenuPanel initialize!