cwidget  0.5.17
menubar.h
1 // menubar.h -*-c++-*-
2 //
3 // Copyright (C) 2000-2005 Daniel Burrows
4 //
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License as
7 // published by the Free Software Foundation; either version 2 of
8 // the License, or (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; see the file COPYING. If not, write to
17 // the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 // Boston, MA 02111-1307, USA.
19 //
20 // Provides a horizontal menubar and a space for submenus. This widget and
21 // its menus are superimposed on top of another widget.
22 
23 #ifndef MENUBAR_H
24 #define MENUBAR_H
25 
26 #include "widget.h"
27 #include "container.h"
29 
30 #include <string>
31 #include <vector>
32 
33 namespace cwidget
34 {
35  namespace widgets
36  {
37  class menu;
38 
39  typedef util::ref_ptr<menu> menu_ref;
40 
41  class menubar:public container
42  {
43  struct item
44  {
45  std::wstring title;
46  util::ref_ptr<menu> child_menu;
47 
48  item(std::wstring _title, util::ref_ptr<menu> _child_menu)
49  :title(_title), child_menu(_child_menu)
50  {
51  }
52  };
53 
54  typedef std::vector<item> itemlist;
55  typedef std::list<widget_ref> activemenulist;
56 
57  // A list of the items in the menubar itself
58  itemlist items;
59  // A list of active menus
60  activemenulist active_menus;
61 
63  itemlist::size_type startloc;
64 
65  // True if the menu-bar is visible and/or being used
66  bool active;
67 
68  // True if the menu-bar should always be visible
69  bool always_visible;
70 
72  itemlist::size_type curloc;
73 
74  // the widget underneath this one.
75  widget_ref subwidget;
76 
77  // Returns the starting X location of the given item in the menu
78  int get_menustart(itemlist::size_type idx) const;
79 
83  void update_x_start();
84 
85  // Show/hide menus
86  void show_menu(const menu_ref &w);
87  void show_menu_bare(menu &w);
88 
89  void hide_menu(const menu_ref &w);
90  void hide_menu_bare(menu &w);
91 
92  void appear();
93  void disappear();
94 
95  // Similar to the passthrough widget's routine (there's not enough
96  // similarity, though, to justify making this a passthrough widget)
97  widget_ref get_focus();
98 
99  void got_focus();
100  void lost_focus();
101  protected:
102  virtual bool handle_key(const config::key &k);
103 
104  menubar(bool _always_visible);
105  public:
106  static util::ref_ptr<menubar> create(bool always_visible = true)
107  {
108  util::ref_ptr<menubar> rval(new menubar(always_visible));
109  rval->decref();
110  return rval;
111  }
112 
113  ~menubar();
114 
117 
118  void destroy();
119 
120  int width_request();
121  int height_request(int w);
122  void layout_me();
123 
124  void set_subwidget(const widget_ref &w);
125 
126  void append_item(const std::wstring &title, const menu_ref &menu);
127  void append_item(const std::wstring &title, menu &menu)
128  {
129  append_item(title, menu_ref(&menu));
130  }
131 
132  void show_all();
133 
135  void add_widget(const widget_ref &w);
137  void rem_widget(const widget_ref &w);
138 
139  virtual void paint(const style &st);
140  virtual bool focus_me();
141  virtual void dispatch_mouse(short id, int x, int y, int z,
142  mmask_t bmask);
143 
144  bool get_cursorvisible();
145  point get_cursorloc();
146 
147  bool get_always_visible() {return always_visible;}
148  void set_always_visible(bool _always_visible);
149 
150  static config::keybindings *bindings;
151  static void init_bindings();
152  };
153 
155  }
156 }
157 
158 #endif
A "style" is a setting to be applied to a display element (widget, text, etc).
Definition: style.h:51
Stores the keys bound to various functions.
Definition: keybindings.h:87
void destroy()
Destroys the visible representation of this widget and disconnects it from any children that it may h...
Definition: menubar.cc:63
Definition: widget.h:89
Definition: ref_ptr.h:19
Definition: menu.h:120
The namespace containing everything defined by cwidget.
Definition: columnify.cc:26
int width_request()
Definition: menubar.cc:304
Definition: menubar.h:41
Definition: container.h:32
Represents a keystroke as seen by curses.
Definition: keybindings.h:42
widget_ref get_active_widget()
The &#39;active&#39; widget of a menubar is always its subwidget.
Definition: menubar.cc:58
int height_request(int w)
Calculate the desired height of the widget, given its width.
Definition: menubar.cc:349
virtual bool handle_key(const config::key &k)
Handles a keypress in this widget.
Definition: menubar.cc:533
Support for defining and remapping keybindings.
void rem_widget(const widget_ref &w)
Remove the subwidget OR a menu.
Definition: menubar.cc:269
virtual void paint(const style &st)
Display this widget.
Definition: menubar.cc:649
void show_all()
Display this widget and all its subwidgets.
Definition: menubar.cc:252
void add_widget(const widget_ref &w)
Add a widget as the new subwidget, like a bin.
Definition: menubar.cc:260