cwidget 0.5.16
|
00001 // menubar.h -*-c++-*- 00002 // 00003 // Copyright (C) 2000-2005 Daniel Burrows 00004 // 00005 // This program is free software; you can redistribute it and/or 00006 // modify it under the terms of the GNU General Public License as 00007 // published by the Free Software Foundation; either version 2 of 00008 // the License, or (at your option) any later version. 00009 // 00010 // This program is distributed in the hope that it will be useful, 00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 // General Public License for more details. 00014 // 00015 // You should have received a copy of the GNU General Public License 00016 // along with this program; see the file COPYING. If not, write to 00017 // the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 00018 // Boston, MA 02111-1307, USA. 00019 // 00020 // Provides a horizontal menubar and a space for submenus. This widget and 00021 // its menus are superimposed on top of another widget. 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 // A list of the items in the menubar itself 00058 itemlist items; 00059 // A list of active menus 00060 activemenulist active_menus; 00061 00063 itemlist::size_type startloc; 00064 00065 // True if the menu-bar is visible and/or being used 00066 bool active; 00067 00068 // True if the menu-bar should always be visible 00069 bool always_visible; 00070 00072 itemlist::size_type curloc; 00073 00074 // the widget underneath this one. 00075 widget_ref subwidget; 00076 00077 // Returns the starting X location of the given item in the menu 00078 int get_menustart(itemlist::size_type idx) const; 00079 00083 void update_x_start(); 00084 00085 // Show/hide menus 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 // Similar to the passthrough widget's routine (there's not enough 00096 // similarity, though, to justify making this a passthrough widget) 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