NCBI C++ ToolKit
menu_item.hpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 #ifndef GUI_UTILS___MENU_ITEM__HPP
2 #define GUI_UTILS___MENU_ITEM__HPP
3 
4 /* $Id: menu_item.hpp 21023 2010-03-10 01:12:14Z voronov $
5  * ===========================================================================
6  *
7  * PUBLIC DOMAIN NOTICE
8  * National Center for Biotechnology Information
9  *
10  * This software/database is a "United States Government Work" under the
11  * terms of the United States Copyright Act. It was written as part of
12  * the author's official duties as a United States Government employee and
13  * thus cannot be copyrighted. This software/database is freely available
14  * to the public for use. The National Library of Medicine and the U.S.
15  * Government have not placed any restriction on its use or reproduction.
16  *
17  * Although all reasonable efforts have been taken to ensure the accuracy
18  * and reliability of the software and data, the NLM and the U.S.
19  * Government do not and cannot warrant the performance or results that
20  * may be obtained by using this software or data. The NLM and the U.S.
21  * Government disclaim all warranties, express or implied, including
22  * warranties of performance, merchantability or fitness for any particular
23  * purpose.
24  *
25  * Please cite the author in any work or product based on this material.
26  *
27  * ===========================================================================
28  *
29  * Authors: Andrey Yazhuk
30  *
31  */
32 
33 /** @addtogroup GUI_UTILS
34 *
35 * @{
36 */
37 
38 /// @file menu_item.hpp
39 
40 #include <corelib/ncbistd.hpp>
41 #include <corelib/ncbi_tree.hpp>
42 #include <gui/gui.hpp>
43 #include <gui/utils/command.hpp>
44 
46 
47 struct SMenuItemRecRec;
48 
49 ////////////////////////////////////////////////////////////////////////////////
50 /// CMenuItem - represents a menu items in IMenu-style menus.
51 
53 {
54 public:
55  /// Type of menu item
56  enum EType {
57  eItem, // command item (includes "checkbox" and "radio" items)
59  eSeparator
60  };
61  /// State and subtype of menu item
62  enum EState {
63  eDefault = 0,
64  eDisabled = 0x1, /// item is disabled (visible but inactive)
65  eCheckItem = 0x2, /// "check-box" item
66  eRadioItem = 0x4, /// "radio" item
67  eSet = 0x8 /// indicates that chekbox is checked or radio item is selected
68  };
69 protected:
71 public:
72  /// creates a separator item
73  CMenuItem();
74 
75  /// creates a submenu item
76  CMenuItem(const string& label, const string& image_alias = "");
77 
78  /// creates a command item
79  CMenuItem(const string& label, TCmdID cmd, const string& image_alias = "",
80  const string& tooltip = "", int state = eDefault);
81 
82  /// generic constructor, can be used to create any type of menuitem
83  CMenuItem(EType type, const string& label = "", TCmdID cmd = eCmdNone,
84  const string& image_alias = "", const string& tooltip = "",
85  int state = eDefault);
86 
87  /// copy contsructor - copies attributes but not subitems
88  CMenuItem(const CMenuItem& item);
89 
90  virtual ~CMenuItem();
91 
92  void Init(EType type, const string& label = "", TCmdID cmd = eCmdNone,
93  const string& image_alias = "", const string& tooltip = "",
94  int state = eDefault);
95 
96  void InitPopup(const string& label, const string& image_alias = "",
97  const string& tooltip = "");
98  void InitItem(const string& label, TCmdID cmd, const string& image_alias = "",
99  const string& tooltip = "", int state = eDefault);
100  void InitSeparator();
101 
102  bool Equal(const CMenuItem& item) const;
103 
104  /// clones item and its subitems
105  CMenuItem* Clone() const;
106 
107  EType GetType() const;
108  void SetType(EType type);
109  bool IsItem() const;
110  bool IsSubmenu() const;
111  bool IsSeparator() const;
112 
113  const string& GetLabel() const;
114  void SetLabel(const string& label);
115 
116  const TCmdID& GetCommand() const;
117  void SetCommand(TCmdID cmd);
118 
119  bool HasImage() const;
120  const string& GetImageAlias() const;
121  void SetImageAlias(const string& image_alias);
122 
123  const string& GetTooltip() const;
124  void SetTooltip(const string& tooltip);
125 
126  int GetState() const;
127  void SetState(int state) ;
128 
129  bool IsEnabled() const;
130  void Enable(bool b_en);
131 
132  bool IsCheckType() const;
133  bool IsChecked() const;
134  void SetCheck(bool b_set);
135 
136  bool IsRadioType() const;
137  bool IsRadioSelected() const;
138  void SelectRadio(bool b_set);
139 
140  bool IsValid() const;
141 
142  bool IsEnabledItem() const { return IsEnabled() && IsItem(); }
143  bool IsEnabledSubmenu() const { return IsEnabled() && IsSubmenu(); }
144 
145  /// merges menu tree represented by "item" into menu tree represented by "this"
146  void Merge(const CMenuItem& item);
147 
148 public:
149  typedef TItemNode::TNodeList_I TChildItem_I;
151 
152  /// @name Operations with submenus
153  /// @{
154  CMenuItem* GetParent();
155  const CMenuItem* GetParent() const;
156 
157  CMenuItem* AddSubItem(CMenuItem* item);
158 
159  /// Adds Separator
160  CMenuItem* AddSeparator();
161  CMenuItem* AddSeparator(const string& label);
162  /// it is recommended that labels start with '-'
163 
164  /// Adds Submenu
165  CMenuItem* AddSubMenu(const string& Label, const string& image_alias = "");
166 
167  /// Adds command subitem
168  CMenuItem* AddSubItem(const string& label, TCmdID cmd, const string& image_alias = "",
169  const string& tooltip = "", int state = eDefault);
170 
171  CMenuItem* InsertSubItem(TChildItem_I it, CMenuItem* item);
172  void RemoveItem(TChildItem_I it);
173 
174  void DestroyAllSubNodes();
175 
176  bool IsSubmenuEmpty();
177 
178  TChildItem_I SubItemsBegin();
179  TChildItem_I SubItemsEnd();
180  TChildItem_CI SubItemsBegin() const;
181  TChildItem_CI SubItemsEnd() const;
182 
183  CMenuItem* FindEqualSubItem(const CMenuItem& item);
184  const CMenuItem* FindEqualSubItem(const CMenuItem& item) const;
185 
186  TChildItem_I FindSubItem(const CMenuItem& item);
187  TChildItem_CI FindSubItem(const CMenuItem& item) const;
188 
189  TChildItem_I FindSubItem(const string& label);
190  TChildItem_CI FindSubItem(const string& label) const;
191 
192  TChildItem_I FindSubItem(EType type, const string& label);
193  TChildItem_CI FindSubItem(EType type, const string& label) const;
194  /// @}
195 
196 protected:
197  void x_MergeItems(CMenuItem& target, const CMenuItem& new_item);
198  TChildItem_I x_FindSubItem(TChildItem_I it_begin, TChildItem_I it_end,
199  const string& label, bool skip_named_groups);
200  void x_InsertInUnnamedGroup(CMenuItem& item);
201 
202  inline void x_SetState(int mask, bool b_en)
203  {
204  if(b_en) {
205  m_State |= mask;
206  } else {
207  m_State &= ~mask;
208  }
209  }
210  inline void x_SetState(int mask, int values)
211  {
212  m_State &= ~mask;
213  m_State |= values;
214  }
215 private:
217  string m_Label;
219  string m_ImageAlias;
220  string m_Tooltip;
221  int m_State;
222 
224 };
225 
226 ////////////////////////////////////////////////////////////////////////////////
227 /// SMenuItemRec
229 {
230  int m_Type;
231  const char* m_Label;
233  const char* m_ImageAlias;
234  const char* m_Tooltip;
235  int m_State;
236 
237  bool IsSubMenu() const
238  {
239  return m_Type == CMenuItem::eSubmenu && m_CommandID == eCmdNone;
240  }
241  bool IsSubMenuEnd() const
242  {
243  return m_Type == CMenuItem::eSubmenu && m_CommandID == eCmdInvalid;
244  }
245  bool IsMenuEnd() const
246  {
247  return m_Type == CMenuItem::eSubmenu && m_CommandID == eCmdMenuEnd;
248  }
249 };
250 
251 /// creates CMenuItem hierarchy from an array of SMenuItemRecRec
253 
254 #define DEFINE_MENU(name) \
255  const SMenuItemRec name[] = \
256  { SUBMENU("Root")
257 
258 #define MENU_ITEM(cmd, label) \
259 { CMenuItem::eItem, label, cmd, "", "", CMenuItem::eDefault},
260 
261 #define MENU_ITEM_T(cmd, label, tooltip) \
262  { CMenuItem::eItem, label, cmd, "", tooltip, CMenuItem::eDefault},
263 
264 #define MENU_ITEM_IM(cmd, label, image) \
265  { CMenuItem::eItem, label, cmd, image, "", CMenuItem::eDefault},
266 
267 #define MENU_ITEM_IM_T(cmd, label, image, tooltip) \
268  { CMenuItem::eItem, label, cmd, image, tooltip, CMenuItem::eDefault},
269 
270 #define MENU_ITEM_RADIO(cmd, label) \
271  { CMenuItem::eItem, label, cmd, "", "", CMenuItem::eRadioItem},
272 
273 #define MENU_ITEM_CHECK(cmd, label) \
274  { CMenuItem::eItem, label, cmd, "", "", CMenuItem::eCheckItem},
275 
276 #define MENU_SEPARATOR() \
277  { CMenuItem::eSeparator, "", eCmdNone, "", "", CMenuItem::eDefault},
278 
279 #define MENU_SEPARATOR_L(label) \
280  { CMenuItem::eSeparator, label, eCmdNone, "", "", CMenuItem::eDefault},
281 
282 #define SUBMENU(label) \
283  { CMenuItem::eSubmenu, label, eCmdNone, "", "", CMenuItem::eDefault},
284 
285 #define SUBMENU_IM(label, image) \
286  { CMenuItem::eSubmenu, label, eCmdNone, image, "", CMenuItem::eDefault},
287 
288 #define END_SUBMENU() \
289  { CMenuItem::eSubmenu, "", eCmdInvalid, "", "", CMenuItem::eDefault},
290 
291 #define END_MENU() \
292  { CMenuItem::eSubmenu, "", eCmdMenuEnd, "", "", CMenuItem::eDefault}, \
293  };
294 
295 
297 
298 /* @} */
299 
300 #endif // GUI_UTILS___MENU_ITEM__HPP
ncbi::TMaskedQueryRegions mask
CMenuItem - represents a menu items in IMenu-style menus.
Definition: menu_item.hpp:53
GUI command routing and handling framework.
Include a standard set of the NCBI C++ Toolkit most basic headers.
static CS_COMMAND * cmd
Definition: ct_dynamic.c:26
static void Init(void)
Definition: cursor6.c:76
TItemNode m_ItemNode
Definition: menu_item.hpp:223
bool IsEnabledItem() const
Definition: menu_item.hpp:142
bool IsMenuEnd() const
Definition: menu_item.hpp:245
const CMenuItem * GetParent() const
bool IsEnabledSubmenu() const
Definition: menu_item.hpp:143
const char * m_Label
Definition: menu_item.hpp:231
EType m_Type
Definition: menu_item.hpp:216
const char * m_ImageAlias
Definition: menu_item.hpp:233
TItemNode::TNodeList_CI TChildItem_CI
Definition: menu_item.hpp:150
bool IsSubMenuEnd() const
Definition: menu_item.hpp:241
const char * m_Tooltip
Definition: menu_item.hpp:234
string m_Tooltip
Definition: menu_item.hpp:220
TItemNode::TNodeList_I TChildItem_I
Definition: menu_item.hpp:149
bool IsSubMenu() const
Definition: menu_item.hpp:237
CTreeNode< CMenuItem * > TItemNode
Definition: menu_item.hpp:70
string m_ImageAlias
Definition: menu_item.hpp:219
TCmdID m_CommandID
Definition: menu_item.hpp:218
CMenuItem * CreateMenuItems(const SMenuItemRec *items)
creates CMenuItem hierarchy from an array of SMenuItemRecRec
Definition: menu_item.cpp:614
string m_Label
Definition: menu_item.hpp:217
TCmdID m_CommandID
Definition: menu_item.hpp:232
void x_SetState(int mask, int values)
Definition: menu_item.hpp:210
EType
Type of menu item.
Definition: menu_item.hpp:56
void x_SetState(int mask, bool b_en)
Definition: menu_item.hpp:202
int TCmdID
@ eCmdMenuEnd
Definition: command.hpp:63
@ eCmdInvalid
marks menu end in array initializers
Definition: command.hpp:64
@ eCmdNone
not a valid command
Definition: command.hpp:65
string GetLabel(const CSeq_id &id)
bool IsValid(const CSeq_point &pt, CScope *scope)
Checks that point >= 0 and point < length of Bioseq.
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
TNodeList::const_iterator TNodeList_CI
Definition: ncbi_tree.hpp:110
#define NCBI_GUIUTILS_EXPORT
Definition: gui_export.h:518
static const char label[]
constexpr bool Equal(std::integral_constant< ncbi::NStr::ECase, case_sensitive > tag, const ct_basic_string< _CharType > &l, const ct_basic_string< _CharType > &r)
SMenuItemRec.
Definition: menu_item.hpp:229
Definition: type.c:6
void Merge(wxMenu &menu_1, const wxMenu &menu_2)
merges all items form menu_2 into menu_1, preserving the structure if possible
Definition: wx_utils.cpp:579
wxMenuItem * FindSubItem(wxMenu &menu, const wxString &text)
Find a subitem of the given menu by text.
Definition: wx_utils.cpp:426
Modified on Sun Mar 03 03:14:02 2024 by modify_doxy.py rev. 669887