1 // Copyright (C) 2002-2012 Nikolaus Gebhardt
\r
2 // This file is part of the "Irrlicht Engine".
\r
3 // For conditions of distribution and use, see copyright notice in irrlicht.h
\r
5 #ifndef __I_GUI_CONTEXT_MENU_H_INCLUDED__
\r
6 #define __I_GUI_CONTEXT_MENU_H_INCLUDED__
\r
8 #include "IGUIElement.h"
\r
15 //! Default is ECMC_REMOVE
\r
16 enum ECONTEXT_MENU_CLOSE
\r
18 //! do nothing - menu stays open
\r
21 //! remove the gui element
\r
24 //! call setVisible(false)
\r
27 // note to implementers - this is planned as bitset, so continue with 4 if you need to add further flags.
\r
30 //! GUI Context menu interface.
\r
31 /** \par This element can create the following events of type EGUI_EVENT_TYPE:
\r
32 \li EGET_ELEMENT_CLOSED
\r
33 \li EGET_MENU_ITEM_SELECTED
\r
35 class IGUIContextMenu : public IGUIElement
\r
40 IGUIContextMenu(IGUIEnvironment* environment, IGUIElement* parent, s32 id, core::rect<s32> rectangle)
\r
41 : IGUIElement(EGUIET_CONTEXT_MENU, environment, parent, id, rectangle) {}
\r
43 //! set behavior when menus are closed
\r
44 virtual void setCloseHandling(ECONTEXT_MENU_CLOSE onClose) = 0;
\r
46 //! get current behavior when the menu will be closed
\r
47 virtual ECONTEXT_MENU_CLOSE getCloseHandling() const = 0;
\r
49 //! Get amount of menu items
\r
50 virtual u32 getItemCount() const = 0;
\r
52 //! Adds a menu item.
\r
53 /** \param text: Text of menu item. Set this to 0 to create
\r
54 an separator instead of a real item, which is the same like
\r
55 calling addSeparator();
\r
56 \param commandId: Command id of menu item, a simple id you may
\r
57 set to whatever you want.
\r
58 \param enabled: Specifies if the menu item should be enabled.
\r
59 \param hasSubMenu: Set this to true if there should be a submenu
\r
60 at this item. You can access this submenu via getSubMenu().
\r
61 \param checked: Specifies if the menu item should be initially checked.
\r
62 \param autoChecking: Specifies if the item should be checked by clicking
\r
63 \return Returns the index of the new item */
\r
64 virtual u32 addItem(const wchar_t* text, s32 commandId=-1, bool enabled=true,
\r
65 bool hasSubMenu=false, bool checked=false, bool autoChecking=false) = 0;
\r
67 //! Insert a menu item at specified position.
\r
68 /** \param idx: Position to insert the new element,
\r
69 should be smaller than itemcount otherwise the item is added to the end.
\r
70 \param text: Text of menu item. Set this to 0 to create
\r
71 an separator instead of a real item, which is the same like
\r
72 calling addSeparator();
\r
73 \param commandId: Command id of menu item, a simple id you may
\r
74 set to whatever you want.
\r
75 \param enabled: Specifies if the menu item should be enabled.
\r
76 \param hasSubMenu: Set this to true if there should be a submenu
\r
77 at this item. You can access this submenu via getSubMenu().
\r
78 \param checked: Specifies if the menu item should be initially checked.
\r
79 \param autoChecking: Specifies if the item should be checked by clicking
\r
80 \return Returns the index of the new item */
\r
81 virtual u32 insertItem(u32 idx, const wchar_t* text, s32 commandId=-1, bool enabled=true,
\r
82 bool hasSubMenu=false, bool checked=false, bool autoChecking=false) = 0;
\r
84 //! Find an item by its CommandID
\r
86 \param commandId: We are looking for the first item which has this commandID
\r
87 \param idxStartSearch: Start searching from this index.
\r
88 \return Returns the index of the item when found or otherwise -1. */
\r
89 virtual s32 findItemWithCommandId(s32 commandId, u32 idxStartSearch=0) const = 0;
\r
91 //! Adds a separator item to the menu
\r
92 virtual void addSeparator() = 0;
\r
94 //! Get text of the menu item.
\r
95 /** \param idx: Zero based index of the menu item */
\r
96 virtual const wchar_t* getItemText(u32 idx) const = 0;
\r
98 //! Sets text of the menu item.
\r
99 /** \param idx: Zero based index of the menu item
\r
100 \param text: New text of the item. */
\r
101 virtual void setItemText(u32 idx, const wchar_t* text) = 0;
\r
103 //! Check if a menu item is enabled
\r
104 /** \param idx: Zero based index of the menu item */
\r
105 virtual bool isItemEnabled(u32 idx) const = 0;
\r
107 //! Sets if the menu item should be enabled.
\r
108 /** \param idx: Zero based index of the menu item
\r
109 \param enabled: True if it is enabled, otherwise false. */
\r
110 virtual void setItemEnabled(u32 idx, bool enabled) = 0;
\r
112 //! Sets if the menu item should be checked.
\r
113 /** \param idx: Zero based index of the menu item
\r
114 \param enabled: True if it is enabled, otherwise false. */
\r
115 virtual void setItemChecked(u32 idx, bool enabled) = 0;
\r
117 //! Check if a menu item is checked
\r
118 /** \param idx: Zero based index of the menu item */
\r
119 virtual bool isItemChecked(u32 idx) const = 0;
\r
121 //! Removes a menu item
\r
122 /** \param idx: Zero based index of the menu item */
\r
123 virtual void removeItem(u32 idx) = 0;
\r
125 //! Removes all menu items
\r
126 virtual void removeAllItems() = 0;
\r
128 //! Get the selected item in the menu
\r
129 /** \return Index of the selected item, -1 if none selected. */
\r
130 virtual s32 getSelectedItem() const = 0;
\r
132 //! Get the command id of a menu item
\r
133 /** \param idx: Zero based index of the menu item */
\r
134 virtual s32 getItemCommandId(u32 idx) const = 0;
\r
136 //! Sets the command id of a menu item
\r
137 /** \param idx: Zero based index of the menu item
\r
138 \param id: Command id of menu item, a simple id you may
\r
139 set to whatever you want. */
\r
140 virtual void setItemCommandId(u32 idx, s32 id) = 0;
\r
142 //! Get a pointer to the submenu of an item.
\r
143 /** 0 is returned if there is no submenu
\r
144 \param idx: Zero based index of the menu item
\r
145 \return Returns a pointer to the submenu of an item. */
\r
146 virtual IGUIContextMenu* getSubMenu(u32 idx) const = 0;
\r
148 //! should the element change the checked status on clicking
\r
149 virtual void setItemAutoChecking(u32 idx, bool autoChecking) = 0;
\r
151 //! does the element change the checked status on clicking
\r
152 virtual bool getItemAutoChecking(u32 idx) const = 0;
\r
154 //! When an eventparent is set it receives events instead of the usual parent element
\r
155 virtual void setEventParent(IGUIElement *parent) = 0;
\r
158 } // end namespace gui
\r
159 } // end namespace irr
\r