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"
19 #include "support/strfwd.h"
24 #include <boost/shared_ptr.hpp>
46 /// The type of elements that can be in a menu
54 /** This is the list of last opened file,
55 typically for the File menu. */
57 /** This is the list of opened Documents,
58 typically for the Documents menu. */
60 /** This is the bookmarks */
64 /** This is a list of viewable formats
65 typically for the File->View menu. */
67 /** This is a list of updatable formats
68 typically for the File->Update menu. */
70 /** This is a list of exportable formats
71 typically for the File->Export menu. */
73 /** This is a list of importable formats
74 typically for the File->Export menu. */
76 /** This is the list of elements available
77 * for insertion into document. */
79 /** This is the list of user-configurable
80 insets to insert into document */
82 /** This is the list of XML elements to
83 insert into the document */
85 /** This is the list of floats that we can
88 /** This is the list of floats that we can
91 /** This is the list of selections that can
96 /** Available branches in document */
100 explicit MenuItem(Kind kind);
103 QString const & label,
104 QString const & submenu = QString(),
105 bool optional = false);
108 QString const & label,
109 FuncRequest const & func,
110 bool optional = false);
112 /// This one is just to please boost::shared_ptr<>
114 /// The label of a given menuitem
115 QString label() const;
116 /// The keyboard shortcut (usually underlined in the entry)
117 QString shortcut() const;
118 /// The complete label, with label and shortcut separated by a '|'
119 QString fulllabel() const { return label_;}
120 /// The kind of entry
121 Kind kind() const { return kind_; }
122 /// the action (if relevant)
123 FuncRequest const & func() const { return func_; }
124 /// returns true if the entry should be ommited when disabled
125 bool optional() const { return optional_; }
126 /// returns the status of the lfun associated with this entry
127 FuncStatus const & status() const { return status_; }
128 /// returns the status of the lfun associated with this entry
129 FuncStatus & status() { return status_; }
130 /// returns the status of the lfun associated with this entry
131 void status(FuncStatus const & status) { status_ = status; }
132 ///returns the binding associated to this action.
133 QString binding() const;
134 /// the description of the submenu (if relevant)
135 QString const & submenuname() const { return submenuname_; }
136 /// set the description of the submenu
137 void submenuname(QString const & name) { submenuname_ = name; }
139 Menu * submenu() const { return submenu_.get(); }
141 void setSubmenu(Menu * menu);
151 QString submenuname_;
157 boost::shared_ptr<Menu> submenu_;
165 typedef std::vector<MenuItem> ItemList;
167 typedef ItemList::const_iterator const_iterator;
170 explicit Menu(QString const & name = QString()) : name_(name) {}
175 QString const & name() const { return name_; }
177 bool empty() const { return items_.empty(); }
178 /// Clear the menu content.
179 void clear() { items_.clear(); }
181 size_t size() const { return items_.size(); }
183 MenuItem const & operator[](size_t) const;
185 const_iterator begin() const { return items_.begin(); }
187 const_iterator end() const { return items_.end(); }
189 // search for func in this menu iteratively, and put menu
191 bool searchMenu(FuncRequest const & func, std::vector<docstring> & names)
197 bool hasFunc(FuncRequest const &) const;
198 /// Add the menu item unconditionally
199 void add(MenuItem const & item) { items_.push_back(item); }
200 /// Checks the associated FuncRequest status before adding the
202 void addWithStatusCheck(MenuItem const &);
203 // Check whether the menu shortcuts are unique
204 void checkShortcuts() const;
206 void expandLastfiles();
207 void expandDocuments();
208 void expandBookmarks();
209 void expandFormats(MenuItem::Kind kind, Buffer const * buf);
210 void expandFloatListInsert(Buffer const * buf);
211 void expandFloatInsert(Buffer const * buf);
212 void expandFlexInsert(Buffer const * buf, std::string s);
213 void expandToc2(Toc const & toc_list, size_t from, size_t to, int depth);
214 void expandToc(Buffer const * buf);
215 void expandPasteRecent();
216 void expandToolbars();
217 void expandBranches(Buffer const * buf);
229 typedef std::vector<Menu> MenuList;
231 typedef MenuList::const_iterator const_iterator;
233 typedef MenuList::iterator iterator;
239 void fillMenuBar(GuiView * view);
241 /// \return a top-level submenu given its name.
242 QMenu * menu(QString const & name);
244 /// update the state of the menuitems - not needed
249 void add(Menu const &);
251 bool hasMenu(QString const &) const;
253 Menu & getMenu(QString const &);
255 Menu const & getMenu(QString const &) const;
257 Menu const & getMenubar() const;
259 bool empty() const { return menulist_.empty(); }
260 /** This defines a menu whose entries list the FuncRequests
261 that will be removed by expand() in other menus. This is
262 used by the Qt/Mac code
264 void setSpecialMenu(Menu const & menu) { specialmenu_ = menu; }
266 Menu const & specialMenu() { return specialmenu_; }
268 /// Expands some special entries of the menu
269 /** The entries with the following kind are expanded to a
270 sequence of Command MenuItems: Lastfiles, Documents,
271 ViewFormats, ExportFormats, UpdateFormats, Branches
273 void expand(Menu const & frommenu, Menu & tomenu,
274 Buffer const *) const;
276 const_iterator begin() const { return menulist_.begin(); }
278 iterator begin() { return menulist_.begin(); }
280 const_iterator end() const { return menulist_.end(); }
282 iterator end() { return menulist_.end(); }
293 /// Initialize specific MACOS X menubar
294 void macxMenuBarInit(GuiView * view);
296 typedef QHash<QString, GuiPopupMenu *> NameMap;
298 /// name to menu for \c menu() method.
302 } // namespace frontend