1.97 class menu_item

A menu_item is an item of a menu. Note that class popup is a subclass of menu and therefore menu_items also describe entries of popups.

The menu_items of a menu are organised in a chain (menu<-members). The menu decides on the layout and how they are displayed. The menu also takes care of handling the user-interaction.

The menu_item<->value of a menu_item is used to address it in the menu. The menu_item<->label determines what is shown on the display, It can either be a string or a bitmap. The menu_item<->message what happens if the user selects this menu_item. The message may be @default, in which case the message associated with the menu is used. menu_item<->end_group tells the menu this is the last entry of a logical group. Used by popup's only. Finally, the menu_item<->condition is a code object that determines whether or not the item should be active when in a popup.

User interface:

Menu_items are no graphical objects. Their visual appearance and user-interface is entirely determined by the menu.

Bugs:

The menu_item<->end_group facility is at te wrong place: it harms reusability (which is not used very often anyway) and it makes changes to menu's difficult. It might be wiser to introduce a menu_item_group object to bundle menu items.

See also
- class popup
- class menu_bar
- class menu

1.97.1 Instance variables

menu_item <-> accelerator: [name]*
Used by menu->key, which will make the menu behave as if this menu_item was selected if the argument key matches this slot.
menu_item <- active: bool
When @on, the menu_item may be selected by the user. When @off, the menu_item is insensitive to events. Normally the menu will indicate this by greying the menu_item.

Defaults: @on (active to events)

See also
- menu->off
- menu_item-condition
- menu->active_all_items
menu_item <- colour: [colour]
Colour used to paint the label of this menu_item. Normally used only to create colour palets.

Defaults: @default (its default value) will paint the menu_item in the colour of its associated menu_item<-menu.

See also
- menu_item-label
- menu_item-font
menu_item <-> condition: code*
Applicable to popup-menu's only. When not @nil, the truth value of this code object is tested just before the popup menu is mapped on the screen and the item is made menu_item<-active according the this truth value.

Tested by popup->update.

Defaults: @nil (popup->update does not change activation status).

See also
- menu->off
- popup->update
- menu_item-active
- popup-update_message
menu_item <- end_group: bool
Popup-menus only. When @on, a line is painted between this item and the next.

Defaults: @off (no line is painted).

menu_item <- font: [font]
Font used to paint the menu_item<-label. Normally used to realise font-selection menus.

Defaults: When @default, menu<-value_font of the associated menu_item<-menu is used.

See also
- menu-value_font
- menu_item-label
- menu_item-colour
menu_item <- label: [name|image]
When a name, the menu will display this text in the menu_item<-colour and menu_item<-font specified with this item. When is is an image, the menu will display this image in menu_item<-colour.

The initial value is normally computed by menu_item<-default_label from the menu_item<-value by menu_item->initialise.

See also
- menu_item-value
- menu_item->initialise
- menu_item<-default_label
- menu_item-colour
- menu_item-font
menu_item <- menu: menu*
Menu I'm part of. Used to forward changes to the associated menu which is responsible for the visual representation and event-processing for this menu_item.

The menu maintains a list of menu_items manipulated in menu<-members.

See also
menu-members
menu_item <-> message: [code]*
Message executed when the item is selected. When @nil, no message will be sent. When @default, the menu_item<-message from the associated menu_item<-menu will be sent.

The arguments forwarded depend on the menu. See description with class menu.

See also
class menu
menu_item <- popup: popup*
Popup menu's only. When not @nil, this is the pullright menu associated with this item. The menu_item<-convert method transforms popup objects in menu_items with this popup associated, which allows appending popup menu's to popup menus to create pullright menus.

Defaults: @nil

See also
- menu_item<-convert
- class popup
menu_item <- selected: bool
Describes whether or not the menu_item is currently selected. Whether multiple menu_items may be selected at the same time is determined by menu<->multiple_selection. The visual feedback is determined by menu<->feedback.
See also
- menu->selection
- menu-feedback
- menu-multiple_selection
menu_item <- value: any
Value associated with this item. Menu items have both a value and a label. The latter is displayed while the value is used for internal communication in the program.

This separation is useful for two purposes. First of all menu's are often used to select some value. For example a colour in a drawing tool. In this case the colour object is used as a value, while an all-1's image with is used as label and menu_item<->colour is set to menu_item<->value. When the user selects a menu-item, the colour object to be used may be read directly from the menu_item<->value object of the menu_item.

Second, this mechanism may be used to implement multi-language interfaces. In this case the menu_item<->value represents the internal name used by the program and the menu_item<->label the external name that may be in a different language.

The default menu_item<->label is compute from the initial menu_item<->value using menu_item<-default_label.

See also
- menu_item<-default_label
- menu_item-label

1.97.2 Send methods

menu_item ->font: [font]
@see menu-value_font
menu_item ->initialise: value=any, message=[code]*, label=[name|image], end_group=[bool], condition=[code]*, accelerator=[name]*
Create a menu_item from

  1. menu_item<->value (any) This argument is the value associated with this item.
  2. menu_item<->message [code]* Message sent when item is activated. @default uses the dialog_item<->message.
  3. menu_item<->label [name|image] Visual appearance: text or image. When @default, this is computed using menu_item<-default_label from the value.
  4. menu_item<->end_group [bool] Popup menu's only. When @on, a line is drawn between this item and the next.
  5. menu_item<->condition [code]* Popup menu's only. Condition to determine menu_item<->active status. When @nil (default), this is not evaluated when the popup is mapped on the screen.
    See also
    - menu_item<-convert
    - menu_item<-default_label
    - menu_item-label
menu_item ->off:
Equivalent to menu_item->active. Backward compatibility.
See also
menu_item->on
menu_item ->on:
Equivalent to menu_item->active. Backward compatibility.
See also
menu_item->off
menu_item ->popup: popup*
Associated popup (pull-right).
menu_item ->value: value=any, label=[name|image]
Set the -value and recompute the label similar to menu_item->initialise.

1.97.3 Get methods

menu_item <-contained_in: -> menu
Return the menu in which this menu_item resides.
menu_item <-convert: value=any -> menu_item
When argument is an instance of class popup, create a menu_item from the graphical<-name and relate the popup with this menu_item using (menu_item->popup and popup->context). This conversion allows simple specification of pull-right menus:
new(P, popup(attributes)),
new(C, popup(colour)),
new(F, popup(font)),
send_list(C, append, [...]),	% fill sub-popups here
send_list(F, append, [...]),
send_list(P, append, [C, F]).	% associate as pullright

When the argument is not a popup, menu_item<-convert will create a menu-item using the argument as a value and leaving all other menu_item->initialise parameters @default.

See also
- menu_item->initialise
- menu_item-popup
- menu->append
menu_item <-default_label: value=any -> label=name|image
Computes the default label from the value. This method is normally called by menu_item<-initialise when the label argument is @default.

It performs the following steps: