15. StdMenu
Prev |  | Next

## 15. StdMenu

### 15.1. Definition

    --      Menus:

    data    Menu        m ls ps = Menu        Title         (m ls ps)        [MenuAttribute ls ps]
    data    PopUpMenu   m ls ps = PopUpMenu                 (m ls ps)

    --      Menu elements:

    data    MenuItem      ls ps = MenuItem    Title                            [MenuAttribute ls ps]
    data    MenuSeparator ls ps = MenuSeparator                                [MenuAttribute ls ps]
    data    RadioMenu     ls ps = RadioMenu   [MenuRadioItem (ls,ps) ps] Index [MenuAttribute ls ps]
    data    SubMenu     m ls ps = SubMenu     Title        (m ls ps)           [MenuAttribute ls ps]

    type    MenuRadioItem st ps = (Title,Maybe Id,Maybe Char,st -> GUI ps st)

    data    MenuAttribute ls ps                                                     -- Default:
     --     Attributes for Menus and MenuElements:
            =       MenuId                  Id                                      -- no Id
            |       MenuSelectState         SelectState                             -- menu(item) Able
     --     Attributes only for Menus:
            |       MenuIndex               Int                                     -- at the end of the current menu list
            |       MenuInit                (ps -> GUI ps ps)                       -- no actions after opening menu
     --     Attributes ignored by (Sub)Menus:
            |       MenuFunction            (GUIFun ls ps)                          -- return
            |       MenuMarkState           MarkState                               -- NoMark
            |       MenuModsFunction        (ModifiersFunction ls ps)               -- MenuFunction
            |       MenuShortKey            Char                                    -- no ShortKey

    class MenuElements m where
            menuElementToHandles    :: m ls ps -> GUI ps [MenuElementState ls ps]

    class PopUpMenuElements m where
            popUpMenuElementToHandles :: m ls ps -> GUI ps [MenuElementState ls ps]

    class Menus mdef where
            openMenu :: ls -> mdef ls ps -> ps -> GUI ps ps

    instance MenuElements m => MenuElements (AddLS m)
    instance MenuElements m => MenuElements (NewLS m)
    instance MenuElements m => MenuElements (ListLS m)
    instance MenuElements NilLS
    instance (MenuElements m1, MenuElements m2) => MenuElements (TupLS m1 m2)
    instance MenuElements m => MenuElements (SubMenu m)
    instance MenuElements m => Menus (Menu m)
    instance MenuElements RadioMenu
    instance MenuElements MenuItem
    instance MenuElements MenuSeparator

    instance PopUpMenuElements m => PopUpMenuElements (AddLS m)
    instance PopUpMenuElements m => PopUpMenuElements (NewLS m)
    instance PopUpMenuElements m => PopUpMenuElements (ListLS m)
    instance PopUpMenuElements NilLS
    instance (PopUpMenuElements m1, PopUpMenuElements m2) => PopUpMenuElements (TupLS m1 m2)
    instance PopUpMenuElements m => Menus (PopUpMenu m)
    instance PopUpMenuElements RadioMenu
    instance PopUpMenuElements MenuItem
    instance PopUpMenuElements MenuSeparator

There are two kinds of menus:

- the standard menus (Menu type) are usually placed at the top of the process window and can be selected at any time;

- the popup menus (PopUpMenu type) can be created and shown at any time as a response to any other event (usually to the click of the right mouse button).

The menus have four kinds of items:

- the simple menu item (MenuItem type) is just an item with a specified title and an event handler which is called when the item is clicked;

- the menu separator (MenuSeparator type) is nonselectable item which can be used to separate menu items in different groups;

- the radio menu (RadioMenu type) is a group of items which can be used as `RadioControl`;

- the sub menu (SubMenu type) item is an item which shows a sub menu when the user selects it.

The menu items can be combined with :+: (TupLS type) and ListLS constructors. The local state for a given group of items can be extended and changed by AddLS and NewLS constructors. NilLS specifies an empty menu.

### 15.2. Menu access functions

    closeMenu :: Id -> GUI ps ()

    enableMenuSystem :: GUI ps ()
    disableMenuSystem :: GUI ps ()

    enableMenus :: [Id] -> GUI ps ()
    disableMenus :: [Id] -> GUI ps ()
    getMenuSelectState :: Id -> GUI ps (Maybe SelectState)

    openMenuElements :: MenuElements m => Id -> Index -> ls -> m ls ps -> GUI ps ()
    openSubMenuElements :: MenuElements m => Id -> Index -> ls -> m ls ps -> GUI ps ()
    openRadioMenuItems :: Id -> Index -> [MenuRadioItem ps ps] -> GUI ps ()

    closeMenuElements :: Id -> [Id] -> GUI ps ()
    closeMenuIndexElements :: Id -> [Index] -> GUI ps ()
    closeSubMenuIndexElements :: Id -> [Index] -> GUI ps ()
    closeRadioMenuIndexElements :: Id -> [Index] -> GUI ps ()

    getMenus :: GUI ps [Id]

    getMenuPos :: Id -> GUI ps (Maybe Index)

    setMenuTitle :: Id -> Title -> GUI ps ()
    getMenuTitle :: Id -> GUI ps (Maybe Title)

`closeMenu`

  closes the specified menu.

`enableMenuSystem`

  enables all menus.

`disableMenuSystem`

  disables all menus.

`enableMenus`

  enables the menus with the specified Ids.

`disableMenus`

  disables the menus with the specified Ids.

`getMenuSelectState`

  returns `SelectState` of the specified menu.

`openMenuElements`

  dynamically creates additional elements to the specified menu.

`openSubMenuElements`

  dynamically creates additional elements to the specified sub menu (here the Id is an Id of the sub menu).

`openRadioMenuItems`

  dynamically creates additional radio menu elements.

`closeMenuElements`

  closes the elements with specified Ids from the specified menu.

`closeMenuIndexElements`

  closes the elements with specified indexes from the specified menu.

`closeSubMenuIndexElements`

  closes the elements with specified indexes from the specified sub menu.

`closeRadioMenuIndexElements`

  closes the radio menu elements with specified indexes from the specified menu.

`getMenus`

  returns the list of ids of all existing menus for the current process.

`getMenuPos`

  returns the menu item index from the item Id.

`setMenuTitle`

  sets the menu title.

`getMenuTitle`

  returns the menu title.

### 15.3. Menu elements access functions

#### 15.3.1. Enable/Disable menu items

    enableMenuElements :: [Id] -> GUI ps ()
    disableMenuElements :: [Id] -> GUI ps ()

    getMenuElementSelectStates :: Id -> [Id] -> GUI ps [(Bool,SelectState)]
    getMenuElementSelectState :: Id -> Id -> GUI ps (Bool,SelectState)

#### 15.3.2. Mark/Unmark menu items

Just like CheckControl, the menu items also can be checked and unchecked.

    markMenuItems :: [Id] -> GUI ps ()
    unmarkMenuItems :: [Id] -> GUI ps ()

    getMenuElementMarkStates :: Id -> [Id] -> GUI ps [(Bool,MarkState)]
    getMenuElementMarkState :: Id -> Id -> GUI ps (Bool,MarkState)

#### 15.3.3. Getting and setting of menu item titles

    setMenuElementTitles :: [(Id,Title)] -> GUI ps ()

    getMenuElementTitles :: Id -> [Id] -> GUI ps [(Bool,Maybe String)]
    getMenuElementTitle :: Id -> Id -> GUI ps (Bool,Maybe String)

#### 15.3.4. Radio menu items selection

Radio menu is just like `RadioControl`. Only one item from the radio menu can be selected at a certain time.

    selectRadioMenuItem :: Id -> Id -> GUI ps ()
    selectRadioMenuIndexItem :: Id -> Index -> GUI ps ()

    getSelectedRadioMenuItems :: Id -> [Id] -> GUI ps [(Index,Maybe Id)]
    getSelectedRadioMenuItem :: Id -> Id -> GUI ps (Index,Maybe Id)

#### 15.3.5. Menu elements access functions

    getMenuElementShortKeys :: Id -> [Id] -> GUI ps [(Bool,Maybe Char)]
    getMenuElementShortKey :: Id -> Id -> GUI ps (Bool,Maybe Char)

`getMenuElementShortKeys`, `getMenuElementShortKey`

  returns the shortcut key associated with the menu element.

Prev |  | Next
14. StdControlReceiver, StdMenuReceiver, StdTimerReceiver | Home | 16. StdTimer