4 * This file is part of LyX, the document processor.
5 * Licence details can be found in the file COPYING.
7 * \author Lars Gullik Bjønnes
10 * Full author contact details are available in file CREDITS.
16 #include "FuncStatus.h"
17 #include "FuncRequest.h"
22 #include <boost/shared_ptr.hpp>
43 /// The type of elements that can be in a menu
51 /** This is the list of last opened file,
52 typically for the File menu. */
54 /** This is the list of opened Documents,
55 typically for the Documents menu. */
57 /** This is the bookmarks */
61 /** This is a list of viewable formats
62 typically for the File->View menu. */
64 /** This is a list of updatable formats
65 typically for the File->Update menu. */
67 /** This is a list of exportable formats
68 typically for the File->Export menu. */
70 /** This is a list of importable formats
71 typically for the File->Export menu. */
73 /** This is the list of elements available
74 * for insertion into document. */
76 /** This is the list of user-configurable
77 insets to insert into document */
79 /** This is the list of XML elements to
80 insert into the document */
82 /** This is the list of floats that we can
85 /** This is the list of floats that we can
88 /** This is the list of selections that can
93 /** Available branches in document */
97 explicit MenuItem(Kind kind);
100 QString const & label,
101 QString const & submenu = QString(),
102 bool optional = false);
105 QString const & label,
106 FuncRequest const & func,
107 bool optional = false);
109 /// This one is just to please boost::shared_ptr<>
111 /// The label of a given menuitem
112 QString label() const;
113 /// The keyboard shortcut (usually underlined in the entry)
114 QString shortcut() const;
115 /// The complete label, with label and shortcut separated by a '|'
116 QString fulllabel() const { return label_;}
117 /// The kind of entry
118 Kind kind() const { return kind_; }
119 /// the action (if relevant)
120 FuncRequest const & func() const { return func_; }
121 /// returns true if the entry should be ommited when disabled
122 bool optional() const { return optional_; }
123 /// returns the status of the lfun associated with this entry
124 FuncStatus const & status() const { return status_; }
125 /// returns the status of the lfun associated with this entry
126 FuncStatus & status() { return status_; }
127 /// returns the status of the lfun associated with this entry
128 void status(FuncStatus const & status) { status_ = status; }
129 ///returns the binding associated to this action.
130 QString binding() const;
131 /// the description of the submenu (if relevant)
132 QString const & submenuname() const { return submenuname_; }
133 /// set the description of the submenu
134 void submenuname(QString const & name) { submenuname_ = name; }
136 Menu * submenu() const { return submenu_.get(); }
138 void submenu(Menu * menu);
148 QString submenuname_;
154 boost::shared_ptr<Menu> submenu_;
162 typedef std::vector<MenuItem> ItemList;
164 typedef ItemList::const_iterator const_iterator;
167 explicit Menu(QString const & name = QString()) : name_(name) {}
169 /// Add the menu item unconditionally
170 void add(MenuItem const & item) { items_.push_back(item); }
171 /// Checks the associated FuncRequest status before adding the
173 void addWithStatusCheck(MenuItem const &);
177 QString const & name() const { return name_; }
179 bool empty() const { return items_.empty(); }
180 /// Clear the menu content.
181 void clear() { items_.clear(); }
183 size_t size() const { return items_.size(); }
185 MenuItem const & operator[](size_t) const;
187 bool hasFunc(FuncRequest const &) const;
189 const_iterator begin() const { return items_.begin(); }
191 const_iterator end() const { return items_.end(); }
193 // Check whether the menu shortcuts are unique
194 void checkShortcuts() const;
196 // search for func in this menu iteratively, and put menu
198 bool searchMenu(FuncRequest const & func, std::vector<docstring> & names)
214 typedef std::vector<Menu> MenuList;
216 typedef MenuList::const_iterator const_iterator;
218 typedef MenuList::iterator iterator;
224 void fillMenuBar(GuiView * view);
226 /// \return a top-level submenu given its name.
227 QMenu * menu(QString const & name);
229 /// update the state of the menuitems - not needed
234 void add(Menu const &);
236 bool hasMenu(QString const &) const;
238 Menu & getMenu(QString const &);
240 Menu const & getMenu(QString const &) const;
242 Menu const & getMenubar() const;
244 bool empty() const { return menulist_.empty(); }
245 /** This defines a menu whose entries list the FuncRequests
246 that will be removed by expand() in other menus. This is
247 used by the Qt/Mac code
249 void setSpecialMenu(Menu const & menu) { specialmenu_ = menu; }
251 Menu const & specialMenu() { return specialmenu_; }
253 /// Expands some special entries of the menu
254 /** The entries with the following kind are expanded to a
255 sequence of Command MenuItems: Lastfiles, Documents,
256 ViewFormats, ExportFormats, UpdateFormats, Branches
258 void expand(Menu const & frommenu, Menu & tomenu,
259 Buffer const *) const;
261 const_iterator begin() const { return menulist_.begin(); }
263 iterator begin() { return menulist_.begin(); }
265 const_iterator end() const { return menulist_.end(); }
267 iterator end() { return menulist_.end(); }
278 /// Initialize specific MACOS X menubar
279 void macxMenuBarInit(GuiView * view);
281 typedef QHash<QString, GuiPopupMenu *> NameMap;
283 /// name to menu for \c menu() method.
287 } // namespace frontend