MySQL Workbench  6.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
menu.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2009, 2013, 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_MENU_H_
21 #define _MFORMS_MENU_H_
22 
23 #include <map>
24 #include "boost/signals2.hpp"
25 
26 #include "base/trackable.h"
27 #include "mforms/base.h"
28 #include "base/ui_form.h"
29 
30 namespace mforms {
31  class Menu;
32 }
33 
34 #ifdef _WIN32
35  #pragma make_public(mforms::Menu) // To allow using Menu in interface functions in assemblies.
36 #endif
37 
38 namespace mforms {
39 
40 #ifndef DOXYGEN_SHOULD_SKIP_THIS
41 #ifndef SWIG
42  struct MFORMS_EXPORT MenuImplPtrs
43  {
44  bool (*create)(Menu *self);
45 
46  void (*remove_item)(Menu *self, int i);
47  int (*add_item)(Menu *self, const std::string &caption, const std::string &action);
48  int (*add_separator)(Menu *self);
49  int (*add_submenu)(Menu *self, const std::string &caption, Menu *submenu);
50  void (*clear)(Menu *self);
51 
52  void (*set_item_enabled)(Menu *self, int i, bool flag);
53 
54  void (*popup_at)(Menu *self, Object *control, int x, int y);
55  };
56 #endif
57 #endif
58 
59  class MFORMS_EXPORT Menu : public Object, public base::trackable
60  {
61  private:
62  MenuImplPtrs *_menu_impl;
63  boost::function<void (const std::string&)> _action_handler;
64  boost::signals2::signal<void ()> _on_will_show;
65  boost::signals2::signal<void (const std::string&)> _on_action;
66  std::map<const std::string, int> _item_map;
67  public:
68  Menu();
69 
70  bool empty() const;
71  void clear();
72  void remove_item(int i);
73  int add_item(const std::string &caption, const std::string &action);
74  int add_separator();
75  int add_submenu(const std::string &caption, Menu *submenu);
76  void add_items_from_list(const bec::MenuItemList& list);
77 
78  void set_item_enabled(int i, bool flag);
79  void set_item_enabled(const std::string &action, bool flag);
80 #ifndef SWIG
81  void set_handler(const boost::function<void (const std::string&)> &action_handler);
82 #endif
83  void popup_at(Object *control, int x, int y);
84  void popup();
85 
86  void handle_action(const std::string &action);
87 
88  int get_item_index(const std::string &action);
89 #ifndef SWIG
90  boost::signals2::signal<void ()>* signal_will_show() { return &_on_will_show; }
91  boost::signals2::signal<void (const std::string&)>* signal_on_action() { return &_on_action; }
92 #endif
93  };
94 };
95 
96 #endif
boost::function< void(const std::string &)> _action_handler
Definition: menu.h:63
boost::signals2::signal< void()> * signal_will_show()
Definition: menu.h:90
#define MFORMS_EXPORT
Definition: base.h:33
boost::signals2::signal< void()> _on_will_show
Definition: menu.h:64
MenuImplPtrs * _menu_impl
Definition: menu.h:62
boost::signals2::signal< void(const std::string &)> * signal_on_action()
Definition: menu.h:91
boost::signals2::signal< void(const std::string &)> _on_action
Definition: menu.h:65
std::map< const std::string, int > _item_map
Definition: menu.h:66
MySQL Workbench 6.1 documentation