Context Menu Design
- public class MenuItem
- Base class for all items of menu.
- private string label
- public string GetLabel()
- Access method to get label of menu item.
- Returns label string
- public void SetLabel(string label)
- Access method to set label string.
- Parameter label is new label string.
- public event EventHandler clicked
- What happens when it is clicked in this item.
- public MenuItem(string label)
- This is constructor, sets new label string.
- Parameter label is new label string.
- public class TextMenuItem: MenuItem
- Menu item class for standrad text item with possible submenu. This item can contain icon.
- private string imagePath
- Path to icon of menu item.
- public string GetImagePath()
- Access method to get icon path string.
- Returns path to menu item icon.
- public void SetImagePath(string imagePath)
- Access method to set new icon path.
- Parameter imagePath is new path to icon.
- private Menu subMenu
- Possible submenu for this menu item. If there is no submenu, value of SubMenu is null.
- public Menu GetSubMenu()
- Access method to get submenu.
- Returns submenu of this menu item.
- public void SetSubMenu(Menu subMenu)
- Access method to set new submenu.
- Parameter subMenu is new submenu of this menu item.
- public void SetSubMenu(Menu subMenu)
- Access method to set new submenu.
- Parameter subMenu is new submenu of this menu item.
- public class CheckMenuItem: MenuItem
- Menu item class for check box item. This item contains label information.
- private bool checkedValue
- Is this menu item checked.
- public bool IsChecked()
- Access method to get if this menu item is checked.
- Returns if this menu item is checked.
- public void SetChecked(bool val)
- Access method to set this menu item checked.
- Parameter val is new value fo Checked attribute.
- public CheckMenuItem(string label, bool val)
- Standard constructor for initializing attributes.
- Parameter label is new label string for this menu item.
- Parameter val is new value for Checked attribute.
- public class RadioMenuItem: MenuItem
- Menu item class for grouped check box item. This item contains label information.
- private bool checkedValue
- Is this menu item checked.
- public bool IsChecked()
- Access method to get if this menu item is checked.
- Returns if this menu item is checked.
- public void SetChecked()
- Access method to set this menu item checked.
- private ArrayList group
- Group to this radio menu item belongs.
- public ArrayList GetGroup()
- Access method to get Group attribute.
- Returns group this item belongs to.
-
- public RadioMenuItem(string label, bool val, ArrayList group)
- Standard constructor.
- Parameter label is new label for this menu item.
- Parameter val is new value for Checked attribute. If this parameter is true, constructor should
set Checked attribute for all Radio menu items in group list (excluding this) to false value.
- Parameter group is the group into this radio menu item belongs. Constructor must add itself into group list.
- public class SeparatorMenuItem: MenuItem
- Menu item class for separator item.
- public SeparatorMenuItem()
- Standard constructor. This constructor should set attribute Label (derivated from MenuItem class)
to "" (empty string) value.
- public class Menu
- Container for menu items.
- private ArrayList items
- List of all items inside this menu.
- public void AddItem(MenuItem item)
- This adds new item into Items list.
- Parameter item will be added into Items list.
- public void RemoveItem(MenuItem item)
- This removes item from Items list.
- Parameter item will be removed from Items list.
- public void ClearItems()
- This method clears Items list.
- public Menu()
- Standard constructor. This constructor must intialize Items list.
To test Gtk+ capabilities I create this Gtk+ code
To validate design I create this Gtk# implementation.
Here is screenshot of Gtk# implementation. Please note icons next to text menu items.