]> git.lyx.org Git - lyx.git/blob - src/MenuBackend.h
62d6a54f5391d333e4f0ea9833f1f1d37cf231a3
[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/LAssert.h"
23 #include <vector>
24
25 class LyXLex;
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         /// Create a Command type MenuItem
46         MenuItem(Kind kind_, string const & label_ = string(), 
47                  string const & command_ = string());
48         /// The label of a given menuitem
49         string const & label() const { return label_; }
50         /// The kind of entry
51         Kind kind() const { return kind_; } 
52         /// the action (if relevant)
53         int action() const { return action_; }
54         /// the description of the  submenu (if relevant)
55         string const & submenu() const { return submenu_; }
56 private:
57         ///
58         Kind kind_;
59         ///
60         string label_;
61         ///
62         int action_;
63         ///
64         string submenu_;
65 };
66
67
68 ///
69 class Menu {
70 public:
71         ///
72         typedef std::vector<MenuItem> ItemList;
73         ///
74         typedef ItemList::const_iterator const_iterator;
75         ///
76         explicit Menu(string const & name, bool mb = false) 
77                 : menubar_(mb), name_(name) {}
78         ///
79         Menu & add(MenuItem const &);
80         ///
81         void read(LyXLex &);
82         /// 
83         bool menubar() const { return menubar_; }
84         /// 
85         string const & name() const { return name_; }
86         ///
87         bool empty() const { return items_.empty(); }
88         ///
89         const_iterator begin() const {
90                 return items_.begin();
91         }
92         ///
93         const_iterator end() const {
94                 return items_.end();
95         }
96 private:
97         ///
98         ItemList items_;
99         ///
100         bool menubar_;
101         ///
102         string name_;
103         ///
104 };
105
106
107 ///
108 class MenuBackend {
109 public:
110         ///
111         typedef std::vector<Menu> MenuList;
112         ///
113         typedef MenuList::const_iterator const_iterator;
114         ///
115         void read(LyXLex &);
116         /// Set default values for menu structure.
117         void defaults();
118         ///
119         void add(Menu const &);
120         ///
121         bool hasMenu (string const &) const;
122         ///
123         Menu const & getMenu (string const &) const;
124         //
125         bool empty() const { return menulist_.empty(); }
126         ///
127         const_iterator begin() const {
128                 return menulist_.begin();
129         }
130         ///
131         const_iterator end() const {
132                 return menulist_.end();
133         }
134 private:
135         ///
136         MenuList menulist_;
137 };
138
139 ///
140 extern MenuBackend menubackend;
141
142 #endif /* MENUBACKEND_H */