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