preparations for Menu (instead of PopUpMenu)
authorca
Wed, 05 Mar 1997 17:09:02 +0100
changeset 1098 e60febc8c26d
parent 1097 9f3ae8f08ffe
child 1099 eccab3759ddb
preparations for Menu (instead of PopUpMenu)
PopUpList.st
--- a/PopUpList.st	Wed Mar 05 14:03:17 1997 +0100
+++ b/PopUpList.st	Wed Mar 05 17:09:02 1997 +0100
@@ -537,6 +537,11 @@
     menuAction := aOneArgBlock
 !
 
+menu:aMenu default:label
+    menu := aMenu.
+    defaultLabel := label
+!
+
 useIndex:aBoolean 
     "tell the popuplist to pass the index (instead of the value)
      to both the actionBlock and model. Notice, that if you use a model,
@@ -680,35 +685,45 @@
 !PopUpList methodsFor:'event handling'!
 
 popMenu
-    |org mv w|
+    |org mv w theMenu|
 
     menu notNil ifTrue:[
-	self turnOffWithoutRedraw. 
+        theMenu := menu value
+    ].
+
+    theMenu notNil ifTrue:[
+        self turnOffWithoutRedraw. 
 
-	menu labels size == 0 ifTrue:[
-	    ^ self
-	].
+        theMenu value labels size == 0 ifTrue:[
+            ^ self
+        ].
 
-	menu font:font.
+        theMenu isView ifTrue:[
+            "/ oldStyle - theMenu is a PopUpMenu
+            theMenu font:font.
 
-	"
-	 adjust the menus width to my current width
-	"
-	mv := menu menuView.
-	mv create.      "/ stupid: it resizes itself upon first create
-	w := mv width.  "/ to its preferred size.
-	w := w max:(self width - (2 * menu margin) - (menu borderWidth*2)).
-	mv width:w.
-	mv level:0; borderWidth:0.
+            "
+             adjust the menus width to my current width
+            "
+            mv := theMenu menuView.
+            mv create.      "/ stupid: it resizes itself upon first create
+            w := mv width.  "/ to its preferred size.
+            w := w max:(self width - (2 * theMenu margin) - (theMenu borderWidth*2)).
+            mv width:w.
+            mv level:0; borderWidth:0.
 
-	"
-	 the popupMenu wants Display coordinates in its showAt: method
-	"
-	org := device translatePoint:0@0 
-				from:(self id)
-				  to:(device rootView id).
+            "
+             the popupMenu wants Display coordinates in its showAt: method
+            "
+            org := device translatePoint:0@0 
+                                    from:(self id)
+                                      to:(device rootView id).
 
-	menu showAt:org "resizing:false"
+            theMenu showAt:org "resizing:false"
+        ] ifFalse:[
+            "/ newStyle - theMenu is a Menu
+            theMenu startUp
+        ]
     ].
 ! !
 
@@ -743,33 +758,33 @@
     |mmH mmV savedLogo longest longestWidth labels|
 
     menu isNil ifTrue:[
-	super computeLabelSize
+        super computeLabelSize
     ] ifFalse:[
-	"hack: simulate logo change to longest menu entry"
+        "hack: simulate logo change to longest menu entry"
 
-	font := font on:device.
-	longest := logo.
-	logo isNil ifTrue:[
-	    longestWidth := 0
-	] ifFalse:[
-	    longestWidth := font widthOf:logo.
-	].
-	labels := menu labels.
-	labels notNil ifTrue:[
-	    labels do:[:entry |
-		|this|
+        font := font on:device.
+        longest := logo.
+        logo isNil ifTrue:[
+            longestWidth := 0
+        ] ifFalse:[
+            longestWidth := font widthOf:logo.
+        ].
+        labels := menu value labels.
+        labels notNil ifTrue:[
+            labels do:[:entry |
+                |this|
 
-		this := font widthOf:entry printString.
-		this > longestWidth ifTrue:[
-		    longest := entry.
-		    longestWidth := this
-		].
-	    ].
-	].
-	savedLogo := logo.
-	logo := longest printString.
-	super computeLabelSize.
-	logo := savedLogo.
+                this := font widthOf:entry printString.
+                this > longestWidth ifTrue:[
+                    longest := entry.
+                    longestWidth := this
+                ].
+            ].
+        ].
+        savedLogo := logo.
+        logo := longest printString.
+        super computeLabelSize.
+        logo := savedLogo.
     ].
     mmH := device horizontalPixelPerMillimeter.
     mmV := device verticalPixelPerMillimeter.
@@ -920,5 +935,5 @@
 !PopUpList class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libwidg/PopUpList.st,v 1.47 1997-03-01 01:14:09 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libwidg/PopUpList.st,v 1.48 1997-03-05 16:09:02 ca Exp $'
 ! !