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