Show cursor on exit
[utui.git] / ctrl / menu.h
blob2ae154773f9e865379716da43605d6600aca61da
1 // Copyright (c) 2006 by Mike Sharov <msharov@users.sourceforge.net>
2 //
3 // menu.h
4 //
6 #ifndef MENU_H_5D85214F09E197BD553E7F2141F2AA44
7 #define MENU_H_5D85214F09E197BD553E7F2141F2AA44
9 #include "../dialog.h"
11 //----------------------------------------------------------------------
13 /// List of standard commands
14 enum {
15 cmd_Root,
16 cmd_Nop,
17 cmd_Separator = cmd_Nop,
18 cmd_ExitMenu,
19 cmd_NextMenu,
20 cmd_PrevMenu,
21 cmd_ActionBase = 0x10,
22 cmd_File,
23 cmd_File_Save,
24 cmd_File_Quit,
25 cmd_Help,
26 cmd_Help_Contents,
27 cmd_Help_About,
28 cmd_User = 0x100,
31 //----------------------------------------------------------------------
33 /// \class CMenu ctrl/menu.h utui.h
34 ///
35 /// Displays a vertical menu of items initialized from the given list,
36 /// updated via the OnUpdateCommandUI interface on the window tree.
37 ///
38 class CMenu : public CDialog {
39 public:
40 typedef CCmdTarget* ptarget_t;
41 typedef vector<SCmd> cmdvec_t;
42 typedef const cmdvec_t& rccmdvec_t;
43 typedef cmdvec_t::iterator iitem_t;
44 typedef cmdvec_t::const_iterator icitem_t;
45 typedef const Point2d& rcoffset_t;
46 static const Point2d s_NullOffset;
47 public:
48 static cmd_t Run (const SCmd* pCmds, size_t nCmds, cmd_t root = cmd_Root, rcoffset_t offset = s_NullOffset);
49 void Set (const SCmd* pCmds, size_t nCmds, cmd_t root = cmd_Root);
50 SCmd* ConvertCountToParent (SCmd* pCmd, const SCmd* pCmdEnd, cmd_t parentCmd) const;
51 cmd_t ExecuteCommand (cmd_t cmd);
52 protected:
53 CMenu (const SCmd* pCmds = NULL, size_t nCmds = 0, cmd_t root = cmd_Root, rcoffset_t offset = s_NullOffset);
54 virtual void OnKey (wchar_t key);
55 virtual void OnCommand (cmd_t cmd);
56 virtual void OnUpdateCommandUI (rcmd_t cmd) const;
57 virtual void SizeHints (rrect_t wr) const;
58 inline bool IsEmpty (void) const { return (!m_nCmds); }
59 inline bool IsTopBar (void) const { return (m_Root == cmd_Root); }
60 private:
61 inline Point2d SubmenuOffset (cmd_t cmd) const;
62 uoff_t FindItem (cmd_t cmd) const;
63 private:
64 const SCmd* m_Cmds; ///< List of all commands in this menu hierarchy.
65 size_t m_nCmds; ///< Number of commands in m_Cmds.
66 Point2d m_ScrOffset; ///< Screen offset to place the menu under a specific item.
67 cmd_t m_Root; ///< Parent command to select commands by. See #CWindow::SCmd.
70 //----------------------------------------------------------------------
72 /// \class CMenuBar ctrl/menu.h utui.h
73 /// Special case of the root menu, which is the standard menu bar on top of the screen.
74 class CMenuBar : public CMenu {
75 public:
76 static CMenuBar* Instance (void);
77 void Set (const SCmd* pCmds, size_t nCmds);
78 inline void ExecuteCommand (cmd_t cmd) { OnCommand (cmd); }
79 protected:
80 virtual void OnKey (wchar_t key);
81 virtual void SizeHints (rrect_t wr) const;
82 private:
83 CMenuBar (void);
84 inline wchar_t CheckCuritemStatus (void);
85 private:
86 vector<SCmd> m_Cmdv;
89 //----------------------------------------------------------------------
91 #define BEGIN_MENU(n, name) \
92 static const CTodoList::SCmd c_TodoMenu[] = { \
93 SUBMENU(n,"menuroot",cmd_Root),
94 #define END_MENU \
96 #define MENUITEM(text, cmd) \
97 CMD_FULL (text, cmd, 0, 0)
98 #define MENUITEM_SEPARATOR \
99 CMD_FULL ("", cmd_Separator, 0, 0)
100 #define MENUCHECK(text, cmd) \
101 CMD_FULL (text, cmd, CCmdTarget::SCmd::cf_Checkable, 0)
102 #define SUBMENU(n, text, cmd) \
103 CMD_FULL (text, cmd, CCmdTarget::SCmd::cf_Submenu, n)
105 //----------------------------------------------------------------------
107 #endif