--- a/PopUpMenu.st Sat Apr 27 20:13:37 1996 +0200
+++ b/PopUpMenu.st Sat Apr 27 20:21:37 1996 +0200
@@ -65,7 +65,7 @@
"
Examples:
-
+ [exBegin]
|p|
p := PopUpMenu
labels:#('foo'
@@ -77,9 +77,11 @@
#baz)
receiver:nil.
p showAtPointer
+ [exEnd]
dynamic with action instead of selector being sent:
+ [exBegin]
|p|
p := PopUpMenu
@@ -88,9 +90,11 @@
receiver:nil.
p action:[:idx | Transcript showCr:'selected index is '; showCr:idx].
p showAtPointer
+ [exEnd]
individual actions:
+ [exBegin]
|p|
p := PopUpMenu
labels:#('foo'
@@ -104,10 +108,11 @@
p actionAt:#bar put:[Transcript showCr:'bar'].
p actionAt:#baz put:[Transcript showCr:'baz'].
p showAtPointer
+ [exEnd]
sometimes, you want to specify both selectors and some arguments
to be sent; this is done by:
-
+ [exBegin]
|p|
p := PopUpMenu
labels:#('foo' 'bar' 'baz')
@@ -115,9 +120,10 @@
args:#(1 2 3)
receiver:nil.
p showAtPointer
+ [exEnd]
or, the same selector but different arguments:
-
+ [exBegin]
|p|
p := PopUpMenu
labels:#('foo' 'bar' 'baz')
@@ -125,6 +131,7 @@
args:#(1 2 3)
receiver:nil.
p showAtPointer
+ [exEnd]
Normally, you do not show the menu explicitely, but install
it as a either as middleButtonMenu of some view or return it from
@@ -132,7 +139,7 @@
(Views/Controllers button-event handler will show it when the middle
button is pressed ...)
Static menu:
-
+ [exBegin]
|v m|
v := View new.
@@ -145,11 +152,12 @@
receiver:v.
v middleButtonMenu:m.
v open
+ [exEnd]
Dynamic menu:
(since we need some model which responds to a menu-message,
we use a plug in the example below; normally, this would be your model)
-
+ [exBegin]
|v model|
model := Plug new.
@@ -161,6 +169,7 @@
v := View new.
v model:model; menu:#getMenu.
v open
+ [exEnd]
Dynamic menus are the MVC-way (i.e. ST-80) way of doing things.
They are usually easier to use, if the menu changes depending on the models
@@ -170,7 +179,7 @@
It is also possible, to add check-mark entries, with an entry string
starting with the special sequence '\c' (for check-mark). The value
passed will be the truth-state of the check-mark.
-
+ [exBegin]
|m v|
v := View new.
@@ -181,9 +190,10 @@
receiver:[:v | Transcript show:'arg: '; showCr:v].
v middleButtonMenu:m.
v open
+ [exEnd]
The style of the checkmark can be: check (\c), box (\b) or thumbs (\t):
-
+ [exBegin]
|m v|
v := View new.
@@ -195,9 +205,10 @@
receiver:[:v | Transcript show:'arg: '; showCr:v].
v middleButtonMenu:m.
v open
+ [exEnd]
or at the end (looks better with variable fonts):
-
+ [exBegin]
|m v|
v := View new.
@@ -209,6 +220,7 @@
receiver:[:v | Transcript show:'arg: '; showCr:v].
v middleButtonMenu:m.
v open
+ [exEnd]
Finally, you can wrap other views into a popup menu (for example,
to implement menus with icons or other components).
@@ -216,7 +228,7 @@
example: #hideSubmenus, #deselectWithoutRedraw and others).
Currently there is only one class in the system, which can be used
this way (PatternMenu in the DrawTool demo):
-
+ [exBegin]
|v p|
v := View new.
@@ -226,9 +238,10 @@
with:Color blue).
v middleButtonMenu:(PopUpMenu forMenu:p).
v open
+ [exEnd]
or try:
-
+ [exBegin]
|v p|
v := View new.
@@ -243,6 +256,7 @@
with:Color blue).
v middleButtonMenu:(PopUpMenu forMenu:p).
v open
+ [exEnd]
ST-80 style:
@@ -250,18 +264,19 @@
The above menus all did some message send on selection; it is
also possible, to use Smalltalk-80 style menus (which return some value
from their startup method):
-
+ [exBegin]
|m selection|
m := PopUpMenu
labels:#('one' 'two' 'three').
selection := m startUp.
Transcript show:'the selection was: '; showCr:selection
+ [exEnd]
startUp will return the entries index, or 0 if there was no selection.
You can also specify an array of values to be returned instead of the
index:
-
+ [exBegin]
|m selection|
m := PopUpMenu
@@ -269,12 +284,13 @@
values:#(10 20 30).
selection := m startUp.
Transcript show:'the value was: '; showCr:selection
+ [exEnd]
In ST/X style menus, separating lines between entries are created
by a '-'-string as its label text (and corresponding nil-entries in the
selectors- and args-arrays).
In ST-80, you have to pass the indices of the lines in an extra array:
-
+ [exBegin]
|m selection|
m := PopUpMenu
@@ -282,8 +298,10 @@
lines:#(2 4).
selection := m startUp.
Transcript show:'the value was: '; showCr:selection
+ [exEnd]
or:
+ [exBegin]
|m selection|
m := PopUpMenu
@@ -292,6 +310,7 @@
values:#(10 20 30).
selection := m startUp.
Transcript show:'the value was: '; showCr:selection
+ [exEnd]
Use whichever interface you prefer.
"
@@ -1144,5 +1163,5 @@
!PopUpMenu class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libwidg/PopUpMenu.st,v 1.48 1996-04-25 17:30:21 cg Exp $'
+ ^ '$Header: /cvs/stx/stx/libwidg/PopUpMenu.st,v 1.49 1996-04-27 18:21:05 cg Exp $'
! !