The menu bar is composed of menus.
The menus are composed of items.
type item_state =
Selected
| Unselected
| Unselectable
;;
type gr_item =
{ it_window : gr_window
; mutable it_state : item_state
; mutable it_name : string
; mutable it_callback : gr_item -> event -> bool
}
;;
The objects defined by gr_item are the lines of a menu.
They are not managed directly by the main loop but by a special
function linked to the menus. They define the contents and the action
linked to a line of a menu. The variables are:
- the attached window (it_window),
- the string that must be displayed when the menu is visible
(it_name),
- the function to call when the item is selected (it_callback),
- the item state, that can take the following values:
- Selected (when it is the present selected menu line),
- Unselected (when another line is selected),
- Unselectable (when the line is visible, but the action associated
is inaccessible)
The linked functions are:
gr_draw_item : gr_item -> coord -> int -> unit
- gr_draw_item Item draws the item Item.
gr_item_managed : 'a -> 'b -> bool
- is the function used by Camlwin to manage the items.
type menu_state =
Visible
| Unvisible
;;
type gr_menu =
{ mn_window : gr_window
; mutable mn_left : int
; mutable mn_top : int
; mutable mn_state : menu_state
; mutable mn_nu_item : int
; mutable mn_name : string
; mutable mn_items : gr_item vect
; mutable mn_hide_area : image
}
;;
gr_menu defines menus. Like the items, the menus are not
elements of a window but the elements of another object: the menu bar
(gr_toolbar). A menu is defined by:
- the attached window (mn_window),
- the coordinates of the lower left corner (mn_left,mn_top),
that are set only when the menu is visible. These
variables could be set to anything when the menu is defined,
- the menu state, that indicates if the menu is open
(mn_state=Visible) or not (mn_state=Unvisible),
- the number of the selected line (mn_nu_item), which is
used only by Camlwin,
- the items that compose the menu (mn_items),
- the name of the menu in the menu bar (mn_name),
- the image where the area of the window is stored when the
menu is displayed (mn_hide_area). The image is used by Camlwin
to restore the window contents without generating a Redraw
event. This variable must be set to gr_empty_image.
The linked functions are:
gr_draw_menu : gr_menu -> unit
- gr_draw_menu Menu draws the menu Menu.
gr_erase_menu : gr_menu -> unit
- gr_erase_menu Menu erases the menu Menu present on the
screen.
gr_menu_managed : gr_menu -> event -> bool
- this function is used by Camlwin to manage the menus.
type gr_toolbar =
{ tb_window : gr_window
; mutable tb_items : gr_menu vect
}
;;
A window must not have more than one menu bar. A menu bar
is defined by the type gr_toolbar. It is a bar at the top of the
window, with the menu name inside. When the user presses the mouse
button on one name, the selected menu is opened. A menu bar is composed
of:
- the attached window (tb_window),
- the list of the menus (tb_items).
The functions linked with the menus bar are:
gr_draw_toolbar : gr_toolbar -> unit
- gr_draw_toolbar Toolb draws the menus bar Toolb.
gr_toolbar_managed : gr_toolbar -> event -> bool
- is the function used by Camlwin to manage the menu bar.