]> git.lyx.org Git - lyx.git/blob - src/MenuBackend.h
242a418c54f0b18283fd080ebfa4e45e82c1f6a7
[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 class LyXLex;
24 class Buffer;
25 class Menu;
26
27 ///
28 class MenuItem {
29 public:
30         /// The type of elements that can be in a menu
31         enum Kind {
32                 ///
33                 Command,
34                 ///
35                 Submenu,
36                 ///
37                 Separator,
38                 /** This is the list of last opened file,
39                     typically for the File menu. */
40                 Lastfiles,
41                 /** This is the list of opened Documents,
42                     typically for the Documents menu. */
43                 Documents,
44                 ///
45                 Toc,
46                 /** This is a list of viewable formats
47                     typically for the File->View menu. */
48                 ViewFormats,
49                 /** This is a list of updatable formats
50                     typically for the File->Update menu. */
51                 UpdateFormats,
52                 /** This is a list of exportable formats
53                     typically for the File->Export menu. */
54                 ExportFormats,
55                 /** This is a list of importable formats
56                     typically for the File->Export menu. */
57                 ImportFormats,
58                 /** This is the list of floats that we can
59                     insert a list for. */
60                 FloatListInsert,
61                 /** This is the list of floats that we can
62                     insert. */
63                 FloatInsert
64         };
65         /// Create a Command type MenuItem
66         MenuItem(Kind kind,
67                  string const & label = string(),
68                  string const & command = string(),
69                  bool optional = false);
70         MenuItem(Kind kind,
71                  string const & label,
72                  int action,
73                  bool optional = false);
74
75         /// This one is just to please boost::shared_ptr<>
76         ~MenuItem();
77         /// The label of a given menuitem
78         string const label() const;
79         /// The keyboard shortcut (usually underlined in the entry)
80         string const shortcut() const;
81         /// The complete label, with label and shortcut separated by a '|'
82         string const fulllabel() const { return label_;}
83         /// The kind of entry
84         Kind kind() const { return kind_; }
85         /// the action (if relevant)
86         int action() const { return action_; }
87         /// returns true if the entry should be ommited when disabled
88         bool optional() const { return optional_; }
89         /// the description of the  submenu (if relevant)
90         string const & submenuname() const { return submenuname_; }
91         /// the description of the  submenu (if relevant)
92         void submenuname(string const & name) { submenuname_ = name; }
93         ///
94         Menu * submenu() const { return submenu_.get(); }
95         ///
96         void submenu(Menu * menu);
97
98 private:
99         //friend class MenuBackend;
100         ///
101         Kind kind_;
102         ///
103         string label_;
104         ///
105         int action_;
106         ///
107         string submenuname_;
108         ///
109         bool optional_;
110         ///
111         boost::shared_ptr<Menu> submenu_;
112 };
113
114
115 ///
116 class Menu {
117 public:
118         ///
119         typedef std::vector<MenuItem> ItemList;
120         ///
121         typedef ItemList::const_iterator const_iterator;
122         ///
123         typedef ItemList::size_type size_type;
124         ///
125         explicit Menu(string const & name = string())
126                 : name_(name) {}
127         ///
128         Menu & add(MenuItem const &);
129         ///
130         Menu & read(LyXLex &);
131         ///
132         string const & name() const { return name_; }
133         ///
134         bool empty() const { return items_.empty(); }
135         ///
136         ItemList::size_type size() const { return items_.size(); }
137         ///
138         bool hasSubmenu(string const &) const;
139         ///
140         const_iterator begin() const {
141                 return items_.begin();
142         }
143         ///
144         const_iterator end() const {
145                 return items_.end();
146         }
147
148         // Check whether the menu shortcuts are unique
149         void checkShortcuts() const;
150
151 private:
152         ///
153         ItemList items_;
154         ///
155         string name_;
156 };
157
158
159 ///
160 class MenuBackend {
161 public:
162         ///
163         typedef std::vector<Menu> MenuList;
164         ///
165         typedef MenuList::const_iterator const_iterator;
166         ///
167         void read(LyXLex &);
168         /// Set default values for menu structure.
169         void defaults();
170         ///
171         void add(Menu const &);
172         ///
173         bool hasMenu(string const &) const;
174         ///
175         Menu & getMenu (string const &);
176         ///
177         Menu const & getMenu (string const &) const;
178         ///
179         Menu const & getMenubar() const;
180         ///
181         bool empty() const { return menulist_.empty(); }
182         /// Expands some special entries of the menu
183         /** The entries with the following kind are expanded to a
184             sequence of Command MenuItems: Lastfiles, Documents,
185             ViewFormats, ExportFormats, UpdateFormats
186         */
187         void expand(Menu const & frommenu, Menu & tomenu,
188                     Buffer const *) const;
189         ///
190         const_iterator begin() const {
191                 return menulist_.begin();
192         }
193         ///
194         const_iterator end() const {
195                 return menulist_.end();
196         }
197 private:
198         ///
199         MenuList menulist_;
200         ///
201         Menu menubar_;
202 };
203
204 ///
205 extern MenuBackend menubackend;
206
207 #endif /* MENUBACKEND_H */