logo

class

fwt::MenuItem

sys::Obj
  fwt::Widget
    fwt::MenuItem
//
// Copyright (c) 2008, Brian Frank and Andy Frank
// Licensed under the Academic Free License version 3.0
//
// History:
//   16 Jun 08  Brian Frank  Creation
//

**
** MenuItem is an individual item on a Menu.
**
class MenuItem : Widget
{

  **
  ** Callback function when menu is selected.
  **
  |Event event| onAction

  **
  ** Mode defines the menu item's style.  Normal items are
  ** one of check, push, radio, or sep.  The default is push.
  ** All instances of `Menu` have a mode of menu.  This field
  ** cannot be changed once the item is constructed.
  **
  const MenuItemMode mode := this is Menu ? MenuItemMode.menu : MenuItemMode.push

  **
  ** The button's selection state (if check or radio)
  **
  Bool selected
  {
    get { return send(getSelectedId, null) }
    set { send(setSelectedId, val) }
  }
  internal static const Str getSelectedId := "getSelected"
  internal static const Str setSelectedId := "setSelected"

  **
  ** Text of the menu item's label. Defaults to "".
  **
  Str text := "" { set { @text = val; sync(textId) } }
  internal static const Str textId := "text"

  **
  ** Image to display on menu item. Defaults to null.
  **
  Image image := null { set { @image = val; sync(imageId) } }
  internal static const Str imageId := "image"

  **
  ** Command associated with this menu item.  Setting the
  ** command automatically maps the text, icon, enable state,
  ** and eventing to the command.
  **
  Command command
  {
    set
    {
      @command?.unregister(this)
      @command = val
      if (val != null)
      {
        enabled  = val.enabled
        text     = val.name
        image    = val.icon
        onAction = |Event e| { val.invoke(e) }
        val.register(this)
      }
    }
  }

}