1 // Copyright (c) 2006 by Mike Sharov <msharov@users.sourceforge.net>
6 #ifndef MENU_H_5D85214F09E197BD553E7F2141F2AA44
7 #define MENU_H_5D85214F09E197BD553E7F2141F2AA44
11 //----------------------------------------------------------------------
13 /// List of standard commands
17 cmd_Separator
= cmd_Nop
,
21 cmd_ActionBase
= 0x10,
31 //----------------------------------------------------------------------
33 /// \class CMenu ctrl/menu.h utui.h
35 /// Displays a vertical menu of items initialized from the given list,
36 /// updated via the OnUpdateCommandUI interface on the window tree.
38 class CMenu
: public CDialog
{
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
;
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
);
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
); }
61 inline Point2d
SubmenuOffset (cmd_t cmd
) const;
62 uoff_t
FindItem (cmd_t cmd
) const;
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
{
76 static CMenuBar
* Instance (void);
77 void Set (const SCmd
* pCmds
, size_t nCmds
);
78 inline void ExecuteCommand (cmd_t cmd
) { OnCommand (cmd
); }
80 virtual void OnKey (wchar_t key
);
81 virtual void SizeHints (rrect_t wr
) const;
84 inline wchar_t CheckCuritemStatus (void);
89 //----------------------------------------------------------------------
91 #define BEGIN_MENU(n, name) \
92 static const CTodoList::SCmd c_TodoMenu[] = { \
93 SUBMENU(n,"menuroot",cmd_Root),
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 //----------------------------------------------------------------------