MySQL Workbench  6.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
menubar.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved.
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License as
6  * published by the Free Software Foundation; version 2 of the
7  * License.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
17  * 02110-1301 USA
18  */
19 
20 #ifndef _MFORMS_MENUBAR_H_
21 #define _MFORMS_MENUBAR_H_
22 
23 #include "base/trackable.h"
24 #include <mforms/box.h>
25 #include <mforms/app.h>
26 #include <vector>
27 
28 namespace mforms {
29  class MenuBase;
30 }
31 
32 namespace mforms {
33  class MenuItem;
34  class MenuBar;
35  class View;
36  class ContextMenu;
37 
39  {
43  };
44 
45 #ifndef SWIG
46 #ifndef DOXYGEN_SHOULD_SKIP_THIS
47  // This merges functionality of menus and menu items.
48  struct MFORMS_EXPORT MenuItemImplPtrs
49  {
50  bool (*create_menu_bar)(MenuBar *item);
51  bool (*create_context_menu)(ContextMenu *item);
52 
53  bool (*create_menu_item)(MenuItem *item, const std::string &, const MenuItemType type);
54  void (*set_title)(MenuItem *item, const std::string&);
55  std::string (*get_title)(MenuItem *item);
56  void (*set_shortcut)(MenuItem *item, const std::string&);
57  void (*set_enabled)(MenuBase *item, bool);
58  bool (*get_enabled)(MenuBase *item);
59  void (*set_checked)(MenuItem *item, bool);
60  bool (*get_checked)(MenuItem *item);
61 
62  void (*insert_item)(MenuBase *menu, int index, MenuItem *item);
63  void (*remove_item)(MenuBase *menu, MenuItem *item); // NULL item to remove all
64 
65  void (*popup_menu)(ContextMenu *menu, int x, int y); // TODO: windows (not used, so this can go)
66  };
67 #endif
68 #endif
69 
70  // base abstract class for menuitem and menubase
71  class MFORMS_EXPORT MenuBase : public Object, public base::trackable
72  {
73  protected:
74  MenuBase();
75 
76  MenuItemImplPtrs *_impl;
78  std::vector<MenuItem*> _items;
79 
80  public:
81  virtual ~MenuBase();
82 
83 #ifndef SWIG
84  std::vector<MenuItem*> &get_subitems() { return _items; }
85 #endif
86 
87  MenuItem *find_item(const std::string &name);
88  MenuItem *get_item(int i);
89  int get_item_index(MenuItem *item);
90  int item_count();
91 
92 #ifndef SWIG
93  MenuItem *add_item_with_title(const std::string &title, boost::function<void ()> action, const std::string &name="");
94 #endif
95  MenuItem *add_separator();
96 
97  void add_item(MenuItem *item);
98  void add_submenu(MenuItem *item) { add_item(item); }
99 
100  void insert_item(int index, MenuItem *item);
101  void remove_all();
102  void remove_item(MenuItem *item);
103  void set_enabled(bool flag);
104  bool get_enabled();
105 
106  virtual void validate();
107 
108  MenuBase *get_parent() { return _parent; }
109  MenuBase *get_top_menu();
110  };
111 
116  {
117  public:
122  MenuItem(const std::string &title, const MenuItemType type = NormalMenuItem);
123 
124  void set_title(const std::string &title);
125  std::string get_title();
126 
127  void set_shortcut(const std::string &shortcut);
128 
129  void set_checked(bool flag);
130  bool get_checked();
131 
132 #ifndef SWIG
133  boost::signals2::signal<void ()>* signal_clicked() { return &_clicked_signal; }
134 #endif
135  void set_name(const std::string &name);
136  std::string get_name() { return _name; }
137 
138  MenuItemType get_type() { return _type; }
139 
140  void set_validator(const boost::function<bool ()> &slot);
141 
142  public:
143  void callback();
144  virtual void validate();
145 
146  private:
147  std::string _name;
148  boost::function<bool ()> _validate;
149  boost::signals2::signal<void ()> _clicked_signal;
151  };
152 
153 
154 
158  {
159  public:
160  MenuBar();
161 
162 #ifndef SWIG
163  boost::signals2::signal<void (MenuItem*)>* signal_will_show() { return &_signal_will_show; }
164 #endif
165  void set_item_enabled(const std::string &item_name, bool flag);
166  void set_item_checked(const std::string &item_name, bool flag);
167 
168  void will_show_submenu_from(MenuItem *item);
169 
170  private:
171  boost::signals2::signal<void (MenuItem*)> _signal_will_show;
172  };
173 
174 
178  {
179  public:
184  ContextMenu();
185 
186 #ifndef SWIG
187  boost::signals2::signal<void (MenuItem*)>* signal_will_show() { return &_signal_will_show; }
188 #endif
189  void set_item_enabled(const std::string &item_name, bool flag);
190  void set_item_checked(const std::string &item_name, bool flag);
191 
192  void will_show();
193  void will_show_submenu_from(MenuItem *item);
194 
195  void popup_at(int x, int y);
196 
197  private:
198  boost::signals2::signal<void (MenuItem*)> _signal_will_show;
199  };
200 };
201 
202 #endif
std::vector< MenuItem * > _items
Definition: menubar.h:78
boost::signals2::signal< void(MenuItem *)> * signal_will_show()
Definition: menubar.h:187
MenuBase * _parent
Definition: menubar.h:77
boost::signals2::signal< void()> _clicked_signal
Definition: menubar.h:149
#define MFORMS_EXPORT
Definition: base.h:33
MenuItemImplPtrs * _impl
Definition: menubar.h:76
std::string get_name()
Definition: menubar.h:136
MenuItemType _type
Definition: menubar.h:150
std::vector< MenuItem * > & get_subitems()
Definition: menubar.h:84
MenuBase * get_parent()
Definition: menubar.h:108
std::string _name
Definition: menubar.h:147
A menu item that can be added to the host application menus.
Definition: menubar.h:115
void add_submenu(MenuItem *item)
Definition: menubar.h:98
A menu that can be attached to other controls.
Definition: menubar.h:177
A menu that can be added to the host application.
Definition: menubar.h:157
boost::signals2::signal< void(MenuItem *)> _signal_will_show
Definition: menubar.h:171
boost::signals2::signal< void(MenuItem *)> * signal_will_show()
Definition: menubar.h:163
boost::signals2::signal< void(MenuItem *)> _signal_will_show
Definition: menubar.h:198
boost::signals2::signal< void()> * signal_clicked()
Definition: menubar.h:133
MenuItemType
Definition: menubar.h:38
boost::function< bool()> _validate
Definition: menubar.h:148
MenuItemType get_type()
Definition: menubar.h:138
MySQL Workbench 6.1 documentation