]> git.lyx.org Git - lyx.git/blob - src/MenuBackend.h
cosmetic fix
[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         };
70         /// Create a Command type MenuItem
71         MenuItem(Kind kind,
72                  string const & label = string(),
73                  string const & command = string(),
74                  bool optional = false);
75         MenuItem(Kind kind,
76                  string const & label,
77                  int action,
78                  bool optional = false);
79
80         /// This one is just to please boost::shared_ptr<>
81         ~MenuItem();
82         /// The label of a given menuitem
83         string const label() const;
84         /// The keyboard shortcut (usually underlined in the entry)
85         string const shortcut() const;
86         /// The complete label, with label and shortcut separated by a '|'
87         string const fulllabel() const { return label_;}
88         /// The kind of entry
89         Kind kind() const { return kind_; }
90         /// the action (if relevant)
91         int action() const { return action_; }
92         /// returns true if the entry should be ommited when disabled
93         bool optional() const { return optional_; }
94         /// returns the status of the lfun associated with this entry
95         FuncStatus const & status() const { return status_; }
96         /// returns the status of the lfun associated with this entry
97         FuncStatus & status() { return status_; }
98         /// returns the status of the lfun associated with this entry
99         void status(FuncStatus const & status) { status_ = status; }
100         /// returns the binding associated to this action
101         string const binding() const;
102         /// the description of the  submenu (if relevant)
103         string const & submenuname() const { return submenuname_; }
104         /// set the description of the  submenu
105         void submenuname(string const & name) { submenuname_ = name; }
106         ///
107         Menu * submenu() const { return submenu_.get(); }
108         ///
109         void submenu(Menu * menu);
110
111 private:
112         //friend class MenuBackend;
113         ///
114         Kind kind_;
115         ///
116         string label_;
117         ///
118         int action_;
119         ///
120         string submenuname_;
121         ///
122         bool optional_;
123         ///
124         FuncStatus status_;
125         ///
126         boost::shared_ptr<Menu> submenu_;
127 };
128
129
130 ///
131 class Menu {
132 public:
133         ///
134         typedef std::vector<MenuItem> ItemList;
135         ///
136         typedef ItemList::const_iterator const_iterator;
137         ///
138         typedef ItemList::size_type size_type;
139         ///
140         explicit Menu(string const & name = string())
141                 : name_(name) {}
142         ///
143         Menu & add(MenuItem const &, LyXView const * view = 0);
144         ///
145         Menu & read(LyXLex &);
146         ///
147         string const & name() const { return name_; }
148         ///
149         bool empty() const { return items_.empty(); }
150         ///
151         ItemList::size_type size() const { return items_.size(); }
152         ///
153         bool hasSubmenu(string const &) const;
154         ///
155         const_iterator begin() const {
156                 return items_.begin();
157         }
158         ///
159         const_iterator end() const {
160                 return items_.end();
161         }
162
163         // Check whether the menu shortcuts are unique
164         void checkShortcuts() const;
165
166 private:
167         friend class MenuBackend;
168         ///
169         ItemList items_;
170         ///
171         string name_;
172 };
173
174
175 ///
176 class MenuBackend {
177 public:
178         ///
179         typedef std::vector<Menu> MenuList;
180         ///
181         typedef MenuList::const_iterator const_iterator;
182         ///
183         void read(LyXLex &);
184         ///
185         void add(Menu const &);
186         ///
187         bool hasMenu(string const &) const;
188         ///
189         Menu & getMenu(string const &);
190         ///
191         Menu const & getMenu(string const &) const;
192         ///
193         Menu const & getMenubar() const;
194         ///
195         bool empty() const { return menulist_.empty(); }
196         /// Expands some special entries of the menu
197         /** The entries with the following kind are expanded to a
198             sequence of Command MenuItems: Lastfiles, Documents,
199             ViewFormats, ExportFormats, UpdateFormats
200         */
201         void expand(Menu const & frommenu, Menu & tomenu,
202                     LyXView const *) const;
203         ///
204         const_iterator begin() const {
205                 return menulist_.begin();
206         }
207         ///
208         const_iterator end() const {
209                 return menulist_.end();
210         }
211 private:
212         ///
213         MenuList menulist_;
214         ///
215         Menu menubar_;
216 };
217
218 ///
219 extern MenuBackend menubackend;
220
221 #endif /* MENUBACKEND_H */