#ifndef __C_GUI_CONTEXT_MENU_H_INCLUDED__
#define __C_GUI_CONTEXT_MENU_H_INCLUDED__
#include "IrrCompileConfig.h"
#ifdef _IRR_COMPILE_WITH_GUI_
#include "IGUIContextMenu.h"
#include "irrString.h"
#include "irrArray.h"
#include "IGUIFont.h"
namespace irr
{
namespace gui
{
class CGUIContextMenu : public IGUIContextMenu
{
public:
CGUIContextMenu(IGUIEnvironment* environment,
IGUIElement* parent, s32 id, core::rect<s32> rectangle,
bool getFocus = true, bool allowFocus = true);
virtual ~CGUIContextMenu();
virtual void setCloseHandling(ECONTEXT_MENU_CLOSE onClose);
virtual ECONTEXT_MENU_CLOSE getCloseHandling() const;
virtual u32 getItemCount() const;
virtual u32 addItem(const wchar_t* text, s32 commandid,
bool enabled, bool hasSubMenu, bool checked, bool autoChecking);
virtual u32 insertItem(u32 idx, const wchar_t* text, s32 commandId, bool enabled,
bool hasSubMenu, bool checked, bool autoChecking);
virtual s32 findItemWithCommandId(s32 commandId, u32 idxStartSearch) const;
virtual void addSeparator();
virtual const wchar_t* getItemText(u32 idx) const;
virtual void setItemText(u32 idx, const wchar_t* text);
virtual bool isItemEnabled(u32 idx) const;
virtual void setItemEnabled(u32 idx, bool enabled);
virtual bool isItemChecked(u32 idx) const;
virtual void setItemChecked(u32 idx, bool enabled);
virtual void removeItem(u32 idx);
virtual void removeAllItems();
virtual bool OnEvent(const SEvent& event);
virtual void draw();
virtual s32 getSelectedItem() const;
virtual IGUIContextMenu* getSubMenu(u32 idx) const;
virtual void setVisible(bool visible);
virtual void setItemAutoChecking(u32 idx, bool autoChecking);
virtual bool getItemAutoChecking(u32 idx) const;
virtual s32 getItemCommandId(u32 idx) const;
virtual void setItemCommandId(u32 idx, s32 id);
virtual void setSubMenu(u32 index, CGUIContextMenu* menu);
virtual void setEventParent(IGUIElement *parent);
virtual void serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options) const;
virtual void deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options);
protected:
void closeAllSubMenus();
bool hasOpenSubMenu() const;
struct SItem
{
core::stringw Text;
bool IsSeparator;
bool Enabled;
bool Checked;
bool AutoChecking;
core::dimension2d<u32> Dim;
s32 PosY;
CGUIContextMenu* SubMenu;
s32 CommandId;
};
virtual void recalculateSize();
virtual bool highlight(const core::position2d<s32>& p, bool canOpenSubMenu);
virtual u32 sendClick(const core::position2d<s32>& p);
virtual core::rect<s32> getHRect(const SItem& i, const core::rect<s32>& absolute) const;
virtual core::rect<s32> getRect(const SItem& i, const core::rect<s32>& absolute) const;
core::array<SItem> Items;
core::position2d<s32> Pos;
IGUIElement* EventParent;
IGUIFont *LastFont;
ECONTEXT_MENU_CLOSE CloseHandling;
s32 HighLighted;
u32 ChangeTime;
bool AllowFocus;
};
}
}
#endif
#endif