MySQL Workbench  6.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
toolbar.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_TOOLBAR_H_
21 #define _MFORMS_TOOLBAR_H_
22 
23 #include <mforms/box.h>
24 #include <mforms/app.h>
25 #include <vector>
26 #include <boost/shared_ptr.hpp>
27 
28 namespace mforms {
29  class ToolBarItem;
30  class ToolBar;
31 
33  {
36  ToolPickerToolBar, // only toggle and separator items are required to work
39  };
40 
42  {
54 #ifdef __APPLE__
55  TitleItem
56 #else
57  TitleItem = LabelItem // TODO implement specific TitleItem (bold with #333333 color) for Windows, Linux
58 #endif
59  };
60 #ifndef SWIG
62  {
63  bool (*create_tool_bar)(ToolBar *item, ToolBarType type);
64  void (*insert_item)(ToolBar *toolbar, int index, ToolBarItem *item);
65  void (*remove_item)(ToolBar *toolbar, ToolBarItem *item);
66 
67  bool (*create_tool_item)(ToolBarItem *item, ToolBarItemType type);
68  void (*set_item_icon)(ToolBarItem *item, const std::string&);
69  void (*set_item_alt_icon)(ToolBarItem *item, const std::string&);
70  void (*set_item_text)(ToolBarItem *item, const std::string&);
71  std::string (*get_item_text)(ToolBarItem *item);
72  void (*set_item_enabled)(ToolBarItem *item, bool);
73  bool (*get_item_enabled)(ToolBarItem *item);
74  void (*set_item_checked)(ToolBarItem *item, bool);
75  bool (*get_item_checked)(ToolBarItem *item);
76  void (*set_item_tooltip)(ToolBarItem *item, const std::string&);
77 
78  // For selector items only.
79  void (*set_selector_items)(ToolBarItem* item, const std::vector<std::string>& values);
80  };
81 #endif
82 
83  // base abstract class for menuitem and menubase
85  {
86  protected:
88  std::vector<ToolBarItem*> _items;
90 
91  public:
92  typedef boost::shared_ptr<ToolBar> Ptr;
94  virtual ~ToolBar();
95 
96  ToolBarType get_type() { return _type; }
97 
98  std::vector<ToolBarItem*> &get_items() { return _items; }
99 
100  ToolBarItem *find_item(const std::string &name);
101 
102  void set_item_enabled(const std::string &name, bool flag);
103  void set_item_checked(const std::string &name, bool flag);
104  bool get_item_checked(const std::string &name);
105 
106  void add_item(ToolBarItem *item);
107  void insert_item(int index, ToolBarItem *item);
108  void remove_all();
109  void remove_item(ToolBarItem *item);
110 
111  ToolBarItem *add_separator_item(const std::string &name="");
112 
113  void validate();
114  };
115 
116  class MFORMS_EXPORT ToolBarItem : public Object
117  {
118  friend class ToolBar;
119  public:
120  ToolBarItem(ToolBarItemType type = ActionItem, const bool expandable = false);
121  ToolBarItemType get_type() { return _type; }
122 
123  bool get_expandable() const { return _expandable; }
124 
125  // Caption for labels, selected entry in drop down items, search text in search fields.
126  void set_text(const std::string &text);
127  std::string get_text();
128 
129  void set_tooltip(const std::string &text);
130 
131  void set_icon(const std::string &path);
132  std::string get_icon() { return _icon; };
133  void set_alt_icon(const std::string &path);
134  std::string get_alt_icon() { return _alt_icon; };
135 
136  void set_enabled(bool flag);
137  bool get_enabled();
138 
139  void set_checked(bool flag);
140  bool get_checked();
141 
142  boost::signals2::signal<void (ToolBarItem*)>* signal_activated() { return &_clicked_signal; }
143 
144  void set_name(const std::string &name);
145  std::string get_name() { return _name; }
146 
147  void set_selector_items(const std::vector<std::string>& values);
148 
149  void set_validator(const boost::function<bool ()> &slot);
150  void set_search_handler(const boost::function<void (const std::string&)> &slot);
151 
152  public:
153  void callback();
154  void validate();
155  void search(const std::string&);
156  private:
158  std::string _name;
159  std::string _icon;
160  std::string _alt_icon;
162  const bool _expandable;
163  boost::signals2::signal<void (ToolBarItem*)> _clicked_signal;
164  boost::function<bool ()> _validate;
165  boost::function<void (const std::string&)> _search;
166  };
167 };
168 
169 #endif
ToolBarImplPtrs * _impl
Definition: toolbar.h:157
ToolBarType _type
Definition: toolbar.h:89
std::vector< ToolBarItem * > _items
Definition: toolbar.h:88
boost::signals2::signal< void(ToolBarItem *)> * signal_activated()
Definition: toolbar.h:142
boost::function< bool()> _validate
Definition: toolbar.h:164
bool get_expandable() const
Definition: toolbar.h:123
std::string get_icon()
Definition: toolbar.h:132
std::string get_alt_icon()
Definition: toolbar.h:134
std::vector< ToolBarItem * > & get_items()
Definition: toolbar.h:98
#define MFORMS_EXPORT
Definition: base.h:33
const bool _expandable
Definition: toolbar.h:162
std::string _name
Definition: toolbar.h:158
std::string _alt_icon
Definition: toolbar.h:160
std::string get_name()
Definition: toolbar.h:145
boost::function< void(const std::string &)> _search
Definition: toolbar.h:165
boost::signals2::signal< void(ToolBarItem *)> _clicked_signal
Definition: toolbar.h:163
boost::shared_ptr< ToolBar > Ptr
Definition: toolbar.h:92
ToolBarImplPtrs * _impl
Definition: toolbar.h:87
ToolBarItemType _type
Definition: toolbar.h:161
ToolBarItemType get_type()
Definition: toolbar.h:121
ToolBarType get_type()
Definition: toolbar.h:96
ToolBarItemType
Definition: toolbar.h:41
Intermediate class used to collectively check for containers and later maybe implement special contai...
Definition: container.h:31
std::string _icon
Definition: toolbar.h:159
ToolBarType
Definition: toolbar.h:32
MySQL Workbench 6.1 documentation