menubar.h
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef MENUBAR_H
00024 #define MENUBAR_H
00025
00026 #include "widget.h"
00027 #include "container.h"
00028 #include <cwidget/config/keybindings.h>
00029
00030 #include <string>
00031 #include <vector>
00032
00033 namespace cwidget
00034 {
00035 namespace widgets
00036 {
00037 class menu;
00038
00039 typedef util::ref_ptr<menu> menu_ref;
00040
00041 class menubar:public container
00042 {
00043 struct item
00044 {
00045 std::wstring title;
00046 util::ref_ptr<menu> child_menu;
00047
00048 item(std::wstring _title, util::ref_ptr<menu> _child_menu)
00049 :title(_title), child_menu(_child_menu)
00050 {
00051 }
00052 };
00053
00054 typedef std::vector<item> itemlist;
00055 typedef std::list<widget_ref> activemenulist;
00056
00057
00058 itemlist items;
00059
00060 activemenulist active_menus;
00061
00063 itemlist::size_type startloc;
00064
00065
00066 bool active;
00067
00068
00069 bool always_visible;
00070
00072 itemlist::size_type curloc;
00073
00074
00075 widget_ref subwidget;
00076
00077
00078 int get_menustart(itemlist::size_type idx) const;
00079
00083 void update_x_start();
00084
00085
00086 void show_menu(const menu_ref &w);
00087 void show_menu_bare(menu &w);
00088
00089 void hide_menu(const menu_ref &w);
00090 void hide_menu_bare(menu &w);
00091
00092 void appear();
00093 void disappear();
00094
00095
00096
00097 widget_ref get_focus();
00098
00099 void got_focus();
00100 void lost_focus();
00101 protected:
00102 virtual bool handle_key(const config::key &k);
00103
00104 menubar(bool _always_visible);
00105 public:
00106 static util::ref_ptr<menubar> create(bool always_visible = true)
00107 {
00108 util::ref_ptr<menubar> rval(new menubar(always_visible));
00109 rval->decref();
00110 return rval;
00111 }
00112
00113 ~menubar();
00114
00116 widget_ref get_active_widget();
00117
00118 void destroy();
00119
00120 int width_request();
00121 int height_request(int w);
00122 void layout_me();
00123
00124 void set_subwidget(const widget_ref &w);
00125
00126 void append_item(const std::wstring &title, const menu_ref &menu);
00127 void append_item(const std::wstring &title, menu &menu)
00128 {
00129 append_item(title, menu_ref(&menu));
00130 }
00131
00132 void show_all();
00133
00135 void add_widget(const widget_ref &w);
00137 void rem_widget(const widget_ref &w);
00138
00139 virtual void paint(const style &st);
00140 virtual bool focus_me();
00141 virtual void dispatch_mouse(short id, int x, int y, int z,
00142 mmask_t bmask);
00143
00144 bool get_cursorvisible();
00145 point get_cursorloc();
00146
00147 bool get_always_visible() {return always_visible;}
00148 void set_always_visible(bool _always_visible);
00149
00150 static config::keybindings *bindings;
00151 static void init_bindings();
00152 };
00153
00154 typedef util::ref_ptr<menubar> menubar_ref;
00155 }
00156 }
00157
00158 #endif