]> git.lyx.org Git - lyx.git/blob - src/MenuBackend.h
hopefully fix tex2lyx linking.
[lyx.git] / src / MenuBackend.h
1 // -*- C++ -*-
2 /**
3  * \file MenuBackend.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Lars Gullik Bjønnes
8  * \author Jean-Marc Lasgouttes
9  *
10  * Full author contact details are available in file CREDITS.
11  */
12
13 #ifndef MENUBACKEND_H
14 #define MENUBACKEND_H
15
16 #include "FuncStatus.h"
17 #include "funcrequest.h"
18
19 #include <boost/shared_ptr.hpp>
20
21 #include <vector>
22
23
24 namespace lyx {
25
26 class LyXLex;
27 class Buffer;
28 class Menu;
29
30 ///
31 class MenuItem {
32 public:
33         /// The type of elements that can be in a menu
34         enum Kind {
35                 ///
36                 Command,
37                 ///
38                 Submenu,
39                 ///
40                 Separator,
41                 /** This is the list of last opened file,
42                     typically for the File menu. */
43                 Lastfiles,
44                 /** This is the list of opened Documents,
45                     typically for the Documents menu. */
46                 Documents,
47                 /** This is the bookmarks */
48                 Bookmarks,
49                 ///
50                 Toc,
51                 /** This is a list of viewable formats
52                     typically for the File->View menu. */
53                 ViewFormats,
54                 /** This is a list of updatable formats
55                     typically for the File->Update menu. */
56                 UpdateFormats,
57                 /** This is a list of exportable formats
58                     typically for the File->Export menu. */
59                 ExportFormats,
60                 /** This is a list of importable formats
61                     typically for the File->Export menu. */
62                 ImportFormats,
63                 /** This is the list of elements available
64                  * for insertion into document. */
65                 CharStyles,
66                 /** This is the list of floats that we can
67                     insert a list for. */
68                 FloatListInsert,
69                 /** This is the list of floats that we can
70                     insert. */
71                 FloatInsert,
72                 /** This is the list of selections that can
73                     be pasted. */
74                 PasteRecent,
75                 /** toolbars */
76                 Toolbars,
77                 /** Available branches in document */
78                 Branches
79         };
80
81         explicit MenuItem(Kind kind);
82
83         MenuItem(Kind kind,
84                  docstring const & label,
85                  docstring const & submenu = docstring(),
86                  bool optional = false);
87
88         MenuItem(Kind kind,
89                  docstring const & label,
90                  FuncRequest const & func,
91                  bool optional = false);
92
93         /// This one is just to please boost::shared_ptr<>
94         ~MenuItem();
95         /// The label of a given menuitem
96         docstring const label() const;
97         /// The keyboard shortcut (usually underlined in the entry)
98         docstring const shortcut() const;
99         /// The complete label, with label and shortcut separated by a '|'
100         docstring const fulllabel() const { return label_;}
101         /// The kind of entry
102         Kind kind() const { return kind_; }
103         /// the action (if relevant)
104         FuncRequest const & func() const { return func_; }
105         /// returns true if the entry should be ommited when disabled
106         bool optional() const { return optional_; }
107         /// returns the status of the lfun associated with this entry
108         FuncStatus const & status() const { return status_; }
109         /// returns the status of the lfun associated with this entry
110         FuncStatus & status() { return status_; }
111         /// returns the status of the lfun associated with this entry
112         void status(FuncStatus const & status) { status_ = status; }
113         /// returns the binding associated to this action
114         docstring const binding() const;
115         /// the description of the  submenu (if relevant)
116         docstring const & submenuname() const { return submenuname_; }
117         /// set the description of the  submenu
118         void submenuname(docstring const & name) { submenuname_ = name; }
119         ///
120         Menu * submenu() const { return submenu_.get(); }
121         ///
122         void submenu(Menu * menu);
123
124 private:
125         //friend class MenuBackend;
126         ///
127         Kind kind_;
128         ///
129         docstring label_;
130         ///
131         FuncRequest func_;
132         ///
133         docstring submenuname_;
134         ///
135         bool optional_;
136         ///
137         FuncStatus status_;
138         ///
139         boost::shared_ptr<Menu> submenu_;
140 };
141
142
143 ///
144 class Menu {
145 public:
146         ///
147         typedef std::vector<MenuItem> ItemList;
148         ///
149         typedef ItemList::const_iterator const_iterator;
150         ///
151         typedef ItemList::size_type size_type;
152         ///
153         explicit Menu(docstring const & name = docstring())
154                 : name_(name) {}
155         /// Add the menu item unconditionally
156         Menu & add(MenuItem const &);
157         /// Checks the associated FuncRequest status before adding the
158         /// menu item.
159         Menu & addWithStatusCheck(MenuItem const &);
160         ///
161         Menu & read(LyXLex &);
162         ///
163         docstring const & name() const { return name_; }
164         ///
165         bool empty() const { return items_.empty(); }
166         /// Clear the menu content.
167         void clear() { items_.clear(); }
168         ///
169         ItemList::size_type size() const { return items_.size(); }
170         ///
171         MenuItem const & operator[](size_type) const;
172         ///
173         bool hasFunc(FuncRequest const &) const;
174         ///
175         const_iterator begin() const {
176                 return items_.begin();
177         }
178         ///
179         const_iterator end() const {
180                 return items_.end();
181         }
182
183         // Check whether the menu shortcuts are unique
184         void checkShortcuts() const;
185
186 private:
187         friend class MenuBackend;
188         ///
189         ItemList items_;
190         ///
191         docstring name_;
192 };
193
194
195 ///
196 class MenuBackend {
197 public:
198         ///
199         typedef std::vector<Menu> MenuList;
200         ///
201         typedef MenuList::const_iterator const_iterator;
202         ///
203         typedef MenuList::iterator iterator;
204         ///
205         MenuBackend() : specialmenu_(0) {}
206         ///
207         void read(LyXLex &);
208         ///
209         void add(Menu const &);
210         ///
211         bool hasMenu(docstring const &) const;
212         ///
213         Menu & getMenu(docstring const &);
214         ///
215         Menu const & getMenu(docstring const &) const;
216         ///
217         Menu const & getMenubar() const;
218         ///
219         bool empty() const { return menulist_.empty(); }
220         /** This defines a menu whose entries list the FuncRequests
221             will be removed by expand() in other menus. This is used by
222             the Qt/Mac code
223         */
224         void specialMenu(docstring const &);
225         /// Expands some special entries of the menu
226         /** The entries with the following kind are expanded to a
227             sequence of Command MenuItems: Lastfiles, Documents,
228             ViewFormats, ExportFormats, UpdateFormats, Branches
229         */
230         void expand(Menu const & frommenu, Menu & tomenu,
231                     Buffer const *) const;
232         ///
233         const_iterator begin() const {
234                 return menulist_.begin();
235         }
236         ///
237         iterator begin() {
238                 return menulist_.begin();
239         }
240         ///
241         const_iterator end() const {
242                 return menulist_.end();
243         }
244         ///
245         iterator end() {
246                 return menulist_.end();
247         }
248 private:
249         ///
250         MenuList menulist_;
251         ///
252         Menu menubar_;
253         ///
254         Menu * specialmenu_;
255 };
256
257 ///
258 extern MenuBackend menubackend;
259
260
261 } // namespace lyx
262
263 #endif /* MENUBACKEND_H */