what class for popup menu?

Boris Gaertner Boris.Gaertner at gmx.net
Sun Jun 13 18:26:06 UTC 2004

"Martin Kuball" <MartinKuball at web.de> wrote:

> Hi!
> I would like to use some popup menus (like the world menu) in a small 
> application I'm developing.  I asked myself what class should I use? 
> I browsed the available classes and found a lot of candidates, like
> MenuMorph, PopUpMorph, CustumMenu, etc.
> Now it would be really nice if somebody can tell me about the pros and 
> cons of each class - or just recommend one.
There is no best choice - every kind of a menu has its special features.
Try all these in a morphic project:

  labelArray: #('Ada' 'Basic' 'Cobol' 'Java' 'Smalltalk')
  lines: #(3))

This is the most simple type of a menu.
The method startUp answers the number of the selected item
or 0 if no item was selected. PopUpMenus can live in the
image for years and can be used again and again.

  labelList: #('Ada' 'Basic' 'Cobol' 'Java' 'Smalltalk')
  lines: #(3)
  selections: #(#useAda #useBasic #useCobol #useJava #useSmalltalk))

This is a bit more sophisticated:
The method startUp answers the selector that is associated
with the selected item or nil when no item is selected.
This is very convenient when you want to send the selector
to an instance that understands it. Like PopUpMenus,
SelectionMenus can live in the image forever.

The CustomMenu is quite different: In a Custom menu, a menu
item has not only an item name and a method selector, but also
a message receiver. This gives you the possibility to provide 
different receivers for the selectable messages. These receivers
are often short-living and  by consequence a CustomMenu
is an object for single use and disposal.
Message receivers are often some morphs and it is therefore
difficult to give an example. To see some infrequently used
possibilities,  you can try this:

 | menu |
menu := CustomMenu new.
menu add: 'red rectangle'
          target: Display
          selector: #fill:fillColor:
          argumentList: (Array with: (10 at 10 extent: 100 at 100)
                               with: Color red);
     add: 'green rectangle'
          target: Display
          selector: #fill:fillColor:
          argumentList: (Array with: (10 at 10 extent: 100 at 100)
                               with: Color green);
     add: 'browser'
          target: Browser
          selector: #fullOnClass:
          argument: nil;
     add: 'browser on Pen'
          target: Browser
          selector: #fullOnClass:
          argument: Pen;
     add: 'browser on Pen class'
          target: Browser
          selector: #fullOnClass:
          argument: Pen class;
     add: 'browser on Collection'
          target: Browser
          selector: #fullOnClass:
          argument: Collection;
     add: 'inspect' target: Inspector
          selector: #openOn:withEvalPane:
          argumentList: (Array with: menu
                               with: false).
menu  invokeOn: nil

The Display has the responsibility to implement the action
for the first and the second menu option. The implementors
of the other options are various classes.

In your application, most menu items will possibly have
the target  "self". 

As to PopUpMorph, MenuMorph, MenuItemMorph, 
MenuLineMorph, I think these are implementation details
that are unimportant for application development.
Greetings, Boris

More information about the Squeak-dev mailing list