]> git.lyx.org Git - lyx.git/blob - src/MenuBackend.h
minipage width compatibility 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 #ifdef __GNUG__
18 #pragma interface
19 #endif
20
21 #include "LString.h"
22 #include <vector>
23
24 class LyXLex;
25 class Buffer;
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                 : kind_(kind), label_(label),
75                   action_(action), submenu_(), optional_(optional) {}
76
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         /// the description of the  submenu (if relevant)
88         string const & submenu() const { return submenu_; }
89         /// returns true if the entry should be ommited when disabled
90         bool optional() const { return optional_; }
91 private:
92         ///
93         Kind kind_;
94         ///
95         string label_;
96         ///
97         int action_;
98         ///
99         string submenu_;
100         ///
101         bool optional_;
102 };
103
104
105 ///
106 class Menu {
107 public:
108         ///
109         typedef std::vector<MenuItem> ItemList;
110         ///
111         typedef ItemList::const_iterator const_iterator;
112         ///
113         explicit Menu(string const & name = string(), bool mb = false)
114                 : menubar_(mb), name_(name) {}
115         ///
116         Menu & add(MenuItem const &);
117         ///
118         Menu & read(LyXLex &);
119         /// Expands some special entries of the menu
120         /** The entries with the following kind are expanded to a
121             sequence of Command MenuItems: Lastfiles, Documents,
122             ViewFormats, ExportFormats, UpdateFormats
123         */
124         void expand(Menu & tomenu, Buffer *) const;
125         ///
126         bool menubar() const { return menubar_; }
127         ///
128         string const & name() const { return name_; }
129         ///
130         bool empty() const { return items_.empty(); }
131         ///
132         ItemList::size_type size() const { return items_.size(); }
133         ///
134         bool hasSubmenu(string const &) const;
135         ///
136         const_iterator begin() const {
137                 return items_.begin();
138         }
139         ///
140         const_iterator end() const {
141                 return items_.end();
142         }
143
144         // Check whether the menu shortcuts are unique
145         void checkShortcuts() const;
146
147 private:
148         ///
149         ItemList items_;
150         ///
151         bool menubar_;
152         ///
153         string name_;
154 };
155
156
157 ///
158 class MenuBackend {
159 public:
160         ///
161         typedef std::vector<Menu> MenuList;
162         ///
163         typedef MenuList::const_iterator const_iterator;
164         ///
165         void read(LyXLex &);
166         /// Set default values for menu structure.
167         void defaults();
168         ///
169         void add(Menu const &);
170         ///
171         bool hasMenu(string const &) const;
172         ///
173         Menu & getMenu (string const &);
174         ///
175         Menu const & getMenu (string const &) const;
176         //
177         bool empty() const { return menulist_.empty(); }
178         ///
179         const_iterator begin() const {
180                 return menulist_.begin();
181         }
182         ///
183         const_iterator end() const {
184                 return menulist_.end();
185         }
186 private:
187         ///
188         MenuList menulist_;
189 };
190
191 ///
192 extern MenuBackend menubackend;
193
194 #endif /* MENUBACKEND_H */