libt3widget
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups
menuitem.h
1 /* Copyright (C) 2011-2013 G.P. Halkes
2  This program is free software: you can redistribute it and/or modify
3  it under the terms of the GNU General Public License version 3, as
4  published by the Free Software Foundation.
5 
6  This program is distributed in the hope that it will be useful,
7  but WITHOUT ANY WARRANTY; without even the implied warranty of
8  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9  GNU General Public License for more details.
10 
11  You should have received a copy of the GNU General Public License
12  along with this program. If not, see <http://www.gnu.org/licenses/>.
13 */
14 #ifndef T3_WIDGET_MENUITEM_H
15 #define T3_WIDGET_MENUITEM_H
16 
17 #include <t3widget/widgets/widget.h>
18 #include <t3widget/dialogs/menupanel.h>
19 
20 namespace t3_widget {
21 
22 class T3_WIDGET_API menu_item_base_t : public widget_t {
23  protected:
24  friend class menu_panel_t;
25  menu_panel_t *parent;
26 
27  /* Menu items get their events from the menu_t (via the menu_panel_t),
28  because that grabs the mouse as soon as it is activated. */
29  virtual void process_mouse_event_from_menu(mouse_event_t event);
30 
31  public:
32  menu_item_base_t(menu_panel_t *_parent) : widget_t(1, 4), parent(_parent) {}
33  virtual void set_position(optint top, optint left);
34  virtual bool set_size(optint height, optint width);
35 };
36 
37 class T3_WIDGET_API menu_item_t : public menu_item_base_t {
38  private:
39  cleanup_ptr<smart_label_text_t>::t label;
40  const char *hotkey;
41  int id;
42  bool has_focus;
43 
44  /* Menu items get their events from the menu_t (via the menu_panel_t),
45  because that grabs the mouse as soon as it is activated. */
46  virtual void process_mouse_event_from_menu(mouse_event_t event);
47 
48  public:
49  menu_item_t(menu_panel_t *_parent, const char *_label, const char *_hotkey, int _id);
50  virtual bool process_key(key_t key);
51  virtual void update_contents(void);
52  virtual void set_focus(focus_t focus);
53  virtual void show(void);
54  virtual void hide(void);
55  virtual bool is_hotkey(key_t key);
56  int get_label_width(void);
57  int get_hotkey_width(void);
58 };
59 
60 class T3_WIDGET_API menu_separator_t : public menu_item_base_t {
61  public:
63  virtual bool process_key(key_t key);
64  virtual void update_contents(void);
65  virtual void set_focus(focus_t focus);
66  virtual void show(void);
67  virtual void hide(void);
68  virtual bool accepts_focus(void);
69 };
70 
71 }; // namespace
72 #endif