]> git.lyx.org Git - lyx.git/blob - src/MenuBackend.h
More 'standard conformant blurb' nonsense.
[lyx.git] / src / MenuBackend.h
1 /* This file is part of              -*- C++ -*-
2 * ======================================================
3 *
4 *           LyX, The Document Processor
5 *
6 *           Copyright 1995 Matthias Ettrich
7 *           Copyright 1995-2001 The LyX Team.
8 *
9 *           This file is Copyright 1999
10 *           Jean-Marc Lasgouttes
11 *
12 *======================================================*/
13
14 #ifndef MENUBACKEND_H
15 #define MENUBACKEND_H
16
17 #include "LString.h"
18
19 #include <boost/shared_ptr.hpp>
20
21 #include <vector>
22
23 #include "FuncStatus.h"
24
25 class LyXLex;
26 class LyXView;
27 class Menu;
28
29 ///
30 class MenuItem {
31 public:
32         /// The type of elements that can be in a menu
33         enum Kind {
34                 ///
35                 Command,
36                 ///
37                 Submenu,
38                 ///
39                 Separator,
40                 /** This is the list of last opened file,
41                     typically for the File menu. */
42                 Lastfiles,
43                 /** This is the list of opened Documents,
44                     typically for the Documents menu. */
45                 Documents,
46                 ///
47                 Toc,
48                 /** This is a list of viewable formats
49                     typically for the File->View menu. */
50                 ViewFormats,
51                 /** This is a list of updatable formats
52                     typically for the File->Update menu. */
53                 UpdateFormats,
54                 /** This is a list of exportable formats
55                     typically for the File->Export menu. */
56                 ExportFormats,
57                 /** This is a list of importable formats
58                     typically for the File->Export menu. */
59                 ImportFormats,
60                 /** This is the list of floats that we can
61                     insert a list for. */
62                 FloatListInsert,
63                 /** This is the list of floats that we can
64                     insert. */
65                 FloatInsert,
66                 /** This is the list of selections that can
67                     be pasted. */
68                 PasteRecent,
69                 /** Available branches in document */
70                 Branches
71         };
72         /// Create a Command type MenuItem
73         MenuItem(Kind kind,
74                  string const & label = string(),
75                  string const & command = string(),
76                  bool optional = false);
77         MenuItem(Kind kind,
78                  string const & label,
79                  int action,
80                  bool optional = false);
81
82         /// This one is just to please boost::shared_ptr<>
83         ~MenuItem();
84         /// The label of a given menuitem
85         string const label() const;
86         /// The keyboard shortcut (usually underlined in the entry)
87         string const shortcut() const;
88         /// The complete label, with label and shortcut separated by a '|'
89         string const fulllabel() const { return label_;}
90         /// The kind of entry
91         Kind kind() const { return kind_; }
92         /// the action (if relevant)
93         int action() const { return action_; }
94         /// returns true if the entry should be ommited when disabled
95         bool optional() const { return optional_; }
96         /// returns the status of the lfun associated with this entry
97         FuncStatus const & status() const { return status_; }
98         /// returns the status of the lfun associated with this entry
99         FuncStatus & status() { return status_; }
100         /// returns the status of the lfun associated with this entry
101         void status(FuncStatus const & status) { status_ = status; }
102         /// returns the binding associated to this action
103         string const binding() const;
104         /// the description of the  submenu (if relevant)
105         string const & submenuname() const { return submenuname_; }
106         /// set the description of the  submenu
107         void submenuname(string const & name) { submenuname_ = name; }
108         ///
109         Menu * submenu() const { return submenu_.get(); }
110         ///
111         void submenu(Menu * menu);
112
113 private:
114         //friend class MenuBackend;
115         ///
116         Kind kind_;
117         ///
118         string label_;
119         ///
120         int action_;
121         ///
122         string submenuname_;
123         ///
124         bool optional_;
125         ///
126         FuncStatus status_;
127         ///
128         boost::shared_ptr<Menu> submenu_;
129 };
130
131
132 ///
133 class Menu {
134 public:
135         ///
136         typedef std::vector<MenuItem> ItemList;
137         ///
138         typedef ItemList::const_iterator const_iterator;
139         ///
140         typedef ItemList::size_type size_type;
141         ///
142         explicit Menu(string const & name = string())
143                 : name_(name) {}
144         ///
145         Menu & add(MenuItem const &, LyXView const * view = 0);
146         ///
147         Menu & read(LyXLex &);
148         ///
149         string const & name() const { return name_; }
150         ///
151         bool empty() const { return items_.empty(); }
152         ///
153         ItemList::size_type size() const { return items_.size(); }
154         ///
155         bool hasSubmenu(string const &) const;
156         ///
157         const_iterator begin() const {
158                 return items_.begin();
159         }
160         ///
161         const_iterator end() const {
162                 return items_.end();
163         }
164
165         // Check whether the menu shortcuts are unique
166         void checkShortcuts() const;
167
168 private:
169         friend class MenuBackend;
170         ///
171         ItemList items_;
172         ///
173         string name_;
174 };
175
176
177 ///
178 class MenuBackend {
179 public:
180         ///
181         typedef std::vector<Menu> MenuList;
182         ///
183         typedef MenuList::const_iterator const_iterator;
184         ///
185         void read(LyXLex &);
186         ///
187         void add(Menu const &);
188         ///
189         bool hasMenu(string const &) const;
190         ///
191         Menu & getMenu(string const &);
192         ///
193         Menu const & getMenu(string const &) const;
194         ///
195         Menu const & getMenubar() const;
196         ///
197         bool empty() const { return menulist_.empty(); }
198         /// Expands some special entries of the menu
199         /** The entries with the following kind are expanded to a
200             sequence of Command MenuItems: Lastfiles, Documents,
201             ViewFormats, ExportFormats, UpdateFormats, Branches
202         */
203         void expand(Menu const & frommenu, Menu & tomenu,
204                     LyXView const *) const;
205         ///
206         const_iterator begin() const {
207                 return menulist_.begin();
208         }
209         ///
210         const_iterator end() const {
211                 return menulist_.end();
212         }
213 private:
214         ///
215         MenuList menulist_;
216         ///
217         Menu menubar_;
218 };
219
220 ///
221 extern MenuBackend menubackend;
222
223 #endif /* MENUBACKEND_H */