PopUpMenu.st
changeset 63 f4eaf04d1eaf
parent 59 450ce95a72a4
child 70 14443a9ea4ec
--- a/PopUpMenu.st	Thu Nov 17 15:34:12 1994 +0100
+++ b/PopUpMenu.st	Thu Nov 17 15:38:53 1994 +0100
@@ -22,7 +22,7 @@
 COPYRIGHT (c) 1989 by Claus Gittinger
 	      All Rights Reserved
 
-$Header: /cvs/stx/stx/libwidg/PopUpMenu.st,v 1.8 1994-10-10 03:02:35 claus Exp $
+$Header: /cvs/stx/stx/libwidg/PopUpMenu.st,v 1.9 1994-11-17 14:38:25 claus Exp $
 '!
 
 !PopUpMenu class methodsFor:'documentation'!
@@ -43,7 +43,7 @@
 
 version
 "
-$Header: /cvs/stx/stx/libwidg/PopUpMenu.st,v 1.8 1994-10-10 03:02:35 claus Exp $
+$Header: /cvs/stx/stx/libwidg/PopUpMenu.st,v 1.9 1994-11-17 14:38:25 claus Exp $
 "
 !
 
@@ -56,7 +56,11 @@
     PopUpMenus are usually created with a list of labels, selectors and a
     receivier. Once activated, the specified receiver will be sent a
     'selector'-message.
+"
+!
 
+examples
+"
     Examples:
 
 	|p|
@@ -244,6 +248,12 @@
 !
 
 labels:labels selectors:selectors receiver:anObject for:aView
+    "create and return a popup menu with labels as entries.
+     Each item will send a corresponding selector from the selectors-array
+     to anObject. The menu is created on the same physical device
+     as aView (which is only of interrest in multi-Display applications; 
+     typical applications can use the sibbling message without the for: argument)."
+
     |newMenu|
 
     newMenu := self onSameDeviceAs:aView. 
@@ -255,15 +265,22 @@
     ^ newMenu
 !
 
-labels:labels selectors:selectors args:args receiver:anObject
-    ^ self labels:labels 
-	selectors:selectors 
-	     args:args 
-	 receiver:anObject 
-	      for:nil
+labels:labels selectors:selectors receiver:anObject
+    "create and return a popup menu with labels as entries.
+     Each item will send a message with a selector from the corresponding 
+     selectors-array.
+     The menu is created on the default Display."
+
+    ^ self labels:labels selectors:selectors receiver:anObject for:nil
 !
 
 labels:labels selectors:selectors args:args receiver:anObject for:aView
+    "create and return a popup menu with labels as entries.
+     Each item will send a corresponding selector:argument from the selectors-
+     and args array to anObject. The menu is created on the same physical device
+     as aView (which is only of interrest in multi-Display applications; 
+     typical applications can use the sibbling message without the for: argument)."
+
     |newMenu|
 
     newMenu := self onSameDeviceAs:aView. 
@@ -276,19 +293,25 @@
     ^ newMenu
 !
 
-labels:labels selector:aSelector args:args receiver:anObject
+labels:labels selectors:selectors args:args receiver:anObject
+    "create and return a popup menu with labels as entries.
+     Each item will send a corresponding selector:argument from the selectors-
+     and args array to anObject. The menu is created on the default Display"
+
     ^ self labels:labels 
-	 selector:aSelector 
+	selectors:selectors 
 	     args:args 
 	 receiver:anObject 
 	      for:nil
 !
 
-labels:labels selectors:selectors receiver:anObject
-    ^ self labels:labels selectors:selectors receiver:anObject for:nil
-!
+labels:labels selector:aSelector args:args receiver:anObject for:aView
+    "create and return a popup menu with labels as entries.
+     Each item will send aSelector with a corresponding argument from the
+     args array to anObject. The menu is created on the same physical device
+     as aView (which is only of interrest in multi-Display applications; 
+     typical applications can use the sibbling message without the for: argument)."
 
-labels:labels selector:aSelector args:args receiver:anObject for:aView
     |newMenu|
 
     newMenu := self onSameDeviceAs:aView. 
@@ -299,6 +322,25 @@
 		    receiver:anObject
 		    in:newMenu).
     ^ newMenu
+!
+
+labels:labels selector:aSelector args:args receiver:anObject
+    "create and return a popup menu with labels as entries.
+     Each item will send aSelector with a corresponding argument from the
+     args array to anObject. The menu is created on the default DIsplay"
+
+    ^ self labels:labels 
+	 selector:aSelector 
+	     args:args 
+	 receiver:anObject 
+	      for:nil
+!
+
+labels:labels selectors:selectors 
+    "create and return a menu with label-items and selectors. The receiver
+     will either be defined later, or not used at all (if opened via startUp)"
+
+    ^ self labels:labels selectors:selectors receiver:nil for:nil
 ! !
 
 !PopUpMenu class methodsFor:'ST-80 instance creation'!
@@ -332,21 +374,17 @@
 initialize
     super initialize.
 
-    "dont need any fancy colors"
-"/    viewBackground := White on:device.
-
     memorize := true.
     hideOnLeave := false.
-    style == #iris ifTrue:[
-	borderWidth := 1
-    ].
-    (style == #st80) ifTrue:[
-"/        viewBackground := White.
-	borderWidth := 1.
-	level := 0.
-	margin := 0.
-	shadowView := nil
-    ].
+"/    style == #iris ifTrue:[
+"/        borderWidth := 1
+"/    ].
+"/    (style == #st80) ifTrue:[
+"/        borderWidth := 1.
+"/        level := 0.
+"/        margin := 0.
+"/        shadowView := nil
+"/    ].
 !
 
 initEvents
@@ -598,7 +636,7 @@
 XXregainControl
 " "
     device ungrabPointer.
-    device grabPointerIn:drawableId
+    device grabPointerInView:self 
 " "
 ! !
 
@@ -611,29 +649,37 @@
      Modal - i.e. stay in the menu until finished.
      This is the ST-80 way of launching a menu."
 
+    |return|
+
     menuView action:[:selected |
-	|actionIndex value|
+	|actionIndex value sel retVal|
 
+	retVal := 0.
 	menuView args isNil ifTrue:[
-	    menuView selectors isNil ifTrue:[
-		^ 0
-	    ].
-	    ^ menuView receiver perform:(menuView selectors at:selected)
+	    menuView selectors notNil ifTrue:[
+		sel := menuView selectors at:selected.
+		sel notNil ifTrue:[menuView receiver perform:sel].
+	    ]
+	] ifFalse:[
+	    actionIndex := menuView args at:selected.
+	    actionIndex notNil ifTrue:[
+		actionValues isNil ifTrue:[
+		    retVal := actionIndex
+		] ifFalse:[
+		    retVal := actionValues at:actionIndex.
+		    (retVal isKindOf:PopUpMenu) ifTrue:[
+			retVal := retVal startUp
+		    ]
+		]
+	    ]
 	].
-	actionIndex := menuView args at:selected.
-	actionIndex isNil ifTrue:[^ 0].
-	actionValues isNil ifTrue:[^ actionIndex].
-	value := actionValues at:actionIndex.
-	(value isKindOf:PopUpMenu) ifTrue:[
-	    ^ value startUp
-	].
-	^ value
+	return := retVal
     ].
     self showAtPointer.
-    ^ 0
+    ^ return
 
     "
-     Transcript showCr:(PopUpMenu labels:#('foo' 'bar' 'baz')) startUp
+     Transcript showCr:(PopUpMenu labels:#('foo' 'bar' 'baz')) startUp 
      Transcript showCr:(PopUpMenu labels:#('foo' 'bar' 'baz')
 				  values:#(foo bar baz)) startUp
     "