# GraffitiMenu
Class Inherits GraffitiWebUIControl
## About
A powerful menu component with far too many features to list!
## Compatibility
### Framework API Version
| 1.0 | 2.0 |
| :---: | :---: |
| True | True |
### Web
| 32-Bit | 64-Bit |
| :---: | :---: |
| True | True |
## Enumerations
| Name | Value | Description |
| --- | :---: | --- |
| TriggerOn | None <br> Right <br> Left <br> Hover | Supported menu response types. |
## Event Definitions
| Name | Parameters | Return Type | Description |
| --- | :---: | :---: | --- |
| MenuAction | InMenu as GraffitiMenuItem <br> ChildItem as GraffitiMenuItem | (None) | Fires when the user selects an item from a displayed menu. |
| MenuHidden | Menu as GraffitiMenuItem | (None) | Fired when the menu is hidden. |
| MenuShown | Menu as GraffitiMenuItem | (None) | Fires when a menu becomes visible. |
## Methods
| Name | Parameters | Return Type | Description |
| --- | :---: | :---: | --- |
| AddMenu | theMenu as GraffitiMenuItem <br> AutoHide as Boolean = False <br> Position as Xojo.Point = Nil | (None) | Adds an “Unattached” context menu, which can displayed anywhere and from any control. |
| AddMenu | ToolbarItem as GraffitiToolbarItem <br> theMenu as GraffitiMenuItem <br> Trigger as TriggerOn <br> AutoHide as Boolean = False <br> Position as REALbasic.Point = nil | (None) | Adds an “Unattached” context menu, which can displayed anywhere and from any control. |
| AddMenu | theControl as WebControl <br> Trigger as TriggerOn <br> theMenu as GraffitiMenuItem <br> AutoHide as Boolean = False <br> Position as Xojo.Point = nil | (None) | Adds an “Unattached” context menu, which can displayed anywhere and from any control. |
| AddMenu | theControl as WebListBox <br> theMenu as GraffitiMenuItem <br> AutoHide as Boolean = False | (None) | Adds an “Unattached” context menu, which can displayed anywhere and from any control. |
| Constructor | (None) | (None) | Creates a new instance of the class. |
| HideMenu | theMenu as GraffitiMenuItem | (None) | Hides the menu with the specified ID, if it is currently visible. |
| HideMenu | theControl as WebControl | (None) | Hides the menu with the specified ID, if it is currently visible. |
| MenuAt | menuIndex as Integer | GraffitiMenuItem | Returns the GraffitiMenu currently managed by the component instance at the specified index. |
| MenuByName | menuName as String | GraffitiMenuItem | Returns the first GraffitiMenu currently managed by the component instance with the specified name. |
| MenuLastIndex | (None) | Integer | Returns the maximum index of items managed by this instance. |
| ShowMenu | theMenu as GraffitiMenuItem <br> X as Integer = -1 <br> Y as Integer = -1 | (None) | Shows the specified menu, at the specified coordinates. If both are -1, will show at cursor. |
| ShowMenu | theControl as WebControl <br> X as Integer = -1 <br> Y as Integer = -1 | (None) | Shows the specified menu, at the specified coordinates. If both are -1, will show at cursor. |
| Unbind | toolbarItem as GraffitiToolbarItem | (None) | Removes the menu from the specified GraffitiWebToolbarItem |
| Unbind | theControl as WebControl | (None) | Removes the menu from the specified GraffitiWebToolbarItem |
## Properties
| Name | Type | Default Value | Description |
| --- | :---: | :---: | --- |
| Menus() | GraffitiMenuItem | Nil | All currently added menus. |
## Examples
### GraffitiToolbar
The easiest method to add a GraffitiMenu to a GraffitiToolbarButton is to first create your menu:
```
dim EditMenuItem as new GraffitiMenuItem( "AddMenu" )
EditMenuItem.Children.Append( new GraffitiMenuItem( "text", "Plain Text" ) )
EditMenuItem.Children.Append( new GraffitiMenuItem( "undo", "Undo", "fa fa-undo", false, "u" ) )
EditMenuItem.Children.Append( new GraffitiMenuItem( True ) )
EditMenuItem.Children.Append( new GraffitiMenuItem( "cut", "Cut", "fa fa-cut", false, "t" ) )
EditMenuItem.Children.Append( new GraffitiMenuItem( "copy", "Copy", "fa fa-copy", false, "c" ) )
EditMenuItem.Children.Append( new GraffitiMenuItem( "paste", "Paste", "fa fa-paste", True, "p" ) )
EditMenuItem.Children.Append( new GraffitiMenuItem( "delete", "Delete", "fa fa-times", false, "d" ) )
EditMenuItem.Children.Append( new GraffitiMenuItem( True ) )
EditMenuItem.Children.Append( new GraffitiMenuItem( "selall", "Select All", "fa fa-i-cursor", false, "s" ) )
EditMenuItem.Children.Append( new GraffitiMenuItem( True ) )
```
Then call the AddMenu method of GraffitiMenu that accepts a GraffitiToolbarButton parameter which has the following signature:
```
AddMenu( ToolbarItem as GraffitiToolbarButton, theMenu as GraffitiMenuItem, Trigger as Integer, AutoHide as Boolean = False, Position as REALbasic.Point = nil )
```
As:
### Styles
GraffitiMenuItems have a Style property, to which you can assign a WebStyle. If this is the top-level item used in the AddMenu call, then that style is used to style the backdrop of the contextmenu and all sub-menus. If it is an item within the top-level or sub- menu, then it is used to style the individual item.
### Unbound Menus
To create an unbound menu (one which is not attached to a control), you simply call the AddMenu overloaded method:
```
dim unattachedMenu as new GraffitiMenuItem( "unattachedMenu" )
unattachedMenu.Children.Append( new GraffitiMenuItem( "unattached1", "Item 1" ) )
unattachedMenu.Children.Append( new GraffitiMenuItem( "unattached2", "Item 2" ) )
gwcmDemo.AddMenu( "unattachedMenu", unattachedMenu )
```
And to show this menu:
```
gwcmDemo.ShowMenu( "unattachedMenu" )
```
This method is recommended for instances where you wish to have multiple menus tied to a single control.
### Xojo WebListBox
To implement in the MouseUp event, you must provide the X and Y parameters for where the menu should appear.
if Details.Button = 2 then
gwcmDemo.ShowMenu( me, me.left + X, me.top + Y )
end if