cwidget 0.5.18
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 <list>
31#include <string>
32#include <vector>
33
34namespace cwidget
35{
36 namespace widgets
37 {
38 class menu;
39
40 typedef util::ref_ptr<menu> menu_ref;
41
42 class menubar:public container
43 {
44 struct item
45 {
46 std::wstring title;
47 util::ref_ptr<menu> child_menu;
48
49 item(std::wstring _title, util::ref_ptr<menu> _child_menu)
50 :title(_title), child_menu(_child_menu)
51 {
52 }
53 };
54
55 typedef std::vector<item> itemlist;
56 typedef std::list<widget_ref> activemenulist;
57
58 // A list of the items in the menubar itself
59 itemlist items;
60 // A list of active menus
61 activemenulist active_menus;
62
64 itemlist::size_type startloc;
65
66 // True if the menu-bar is visible and/or being used
67 bool active;
68
69 // True if the menu-bar should always be visible
70 bool always_visible;
71
73 itemlist::size_type curloc;
74
75 // the widget underneath this one.
76 widget_ref subwidget;
77
78 // Returns the starting X location of the given item in the menu
79 int get_menustart(itemlist::size_type idx) const;
80
84 void update_x_start();
85
86 // Show/hide menus
87 void show_menu(const menu_ref &w);
88 void show_menu_bare(menu &w);
89
90 void hide_menu(const menu_ref &w);
91 void hide_menu_bare(menu &w);
92
93 void appear();
94 void disappear();
95
96 // Similar to the passthrough widget's routine (there's not enough
97 // similarity, though, to justify making this a passthrough widget)
98 widget_ref get_focus();
99
100 void got_focus();
101 void lost_focus();
102 protected:
103 virtual bool handle_key(const config::key &k);
104
105 menubar(bool _always_visible);
106 public:
107 static util::ref_ptr<menubar> create(bool always_visible = true)
108 {
109 util::ref_ptr<menubar> rval(new menubar(always_visible));
110 rval->decref();
111 return rval;
112 }
113
114 ~menubar();
115
118
119 void destroy();
120
121 int width_request();
122 int height_request(int w);
123 void layout_me();
124
125 void set_subwidget(const widget_ref &w);
126
127 void append_item(const std::wstring &title, const menu_ref &menu);
128 void append_item(const std::wstring &title, menu &menu)
129 {
130 append_item(title, menu_ref(&menu));
131 }
132
133 void show_all();
134
136 void add_widget(const widget_ref &w);
138 void rem_widget(const widget_ref &w);
139
140 virtual void paint(const style &st);
141 virtual bool focus_me();
142 virtual void dispatch_mouse(short id, int x, int y, int z,
143 mmask_t bmask);
144
145 bool get_cursorvisible();
146 point get_cursorloc();
147
148 bool get_always_visible() {return always_visible;}
149 void set_always_visible(bool _always_visible);
150
151 static config::keybindings *bindings;
152 static void init_bindings();
153 };
154
156 }
157}
158
159#endif
Stores the keys bound to various functions.
Definition keybindings.h:88
A "style" is a setting to be applied to a display element (widget, text, etc).
Definition style.h:52
Definition ref_ptr.h:20
Definition container.h:33
Definition menu.h:121
Definition menubar.h:43
void rem_widget(const widget_ref &w)
Remove the subwidget OR a menu.
Definition menubar.cc:269
void show_all()
Display this widget and all its subwidgets.
Definition menubar.cc:252
widget_ref get_active_widget()
The 'active' widget of a menubar is always its subwidget.
Definition menubar.cc:58
int width_request()
Definition menubar.cc:304
virtual void paint(const style &st)
Display this widget.
Definition menubar.cc:649
virtual bool handle_key(const config::key &k)
Handles a keypress in this widget.
Definition menubar.cc:533
void destroy()
Destroys the visible representation of this widget and disconnects it from any children that it may h...
Definition menubar.cc:63
int height_request(int w)
Calculate the desired height of the widget, given its width.
Definition menubar.cc:349
void add_widget(const widget_ref &w)
Add a widget as the new subwidget, like a bin.
Definition menubar.cc:260
Support for defining and remapping keybindings.
The namespace containing everything defined by cwidget.
Definition columnify.cc:28
Represents a keystroke as seen by curses.
Definition keybindings.h:43
Definition widget.h:89