]> git.lyx.org Git - lyx.git/blob - src/MenuBackend.h
Dekel's patch -- I didn't fix the xforms-0.88 keysyms stuff so it still doesn't finis...
[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
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, 
47                  string const & label = string(), 
48                  string const & command = string(), 
49                  bool optional = false);
50         /// The label of a given menuitem
51         string label() const { return token(label_, '|', 0); }
52         ///
53         string shortcut() const { return token(label_, '|', 1); }
54         /// The kind of entry
55         Kind kind() const { return kind_; } 
56         /// the action (if relevant)
57         int action() const { return action_; }
58         /// the description of the  submenu (if relevant)
59         string const & submenu() const { return submenu_; }
60         /// returns true if the entry should be ommited when disabled
61         bool optional() const { return optional_; }
62 private:
63         ///
64         Kind kind_;
65         ///
66         string label_;
67         ///
68         int action_;
69         ///
70         string submenu_;
71         ///
72         bool optional_;
73 };
74
75
76 ///
77 class Menu {
78 public:
79         ///
80         typedef std::vector<MenuItem> ItemList;
81         ///
82         typedef ItemList::const_iterator const_iterator;
83         ///
84         explicit Menu(string const & name, bool mb = false) 
85                 : menubar_(mb), name_(name) {}
86         ///
87         Menu & add(MenuItem const &);
88         ///
89         Menu & read(LyXLex &);
90         /// 
91         bool menubar() const { return menubar_; }
92         /// 
93         string const & name() const { return name_; }
94         ///
95         bool empty() const { return items_.empty(); }
96         ///
97         const_iterator begin() const {
98                 return items_.begin();
99         }
100         ///
101         const_iterator end() const {
102                 return items_.end();
103         }
104 private:
105         ///
106         ItemList items_;
107         ///
108         bool menubar_;
109         ///
110         string name_;
111 };
112
113
114 ///
115 class MenuBackend {
116 public:
117         ///
118         typedef std::vector<Menu> MenuList;
119         ///
120         typedef MenuList::const_iterator const_iterator;
121         ///
122         void read(LyXLex &);
123         /// Set default values for menu structure.
124         void defaults();
125         ///
126         void add(Menu const &);
127         ///
128         bool hasMenu (string const &) const;
129         ///
130         Menu & getMenu (string const &);
131         ///
132         Menu const & getMenu (string const &) const;
133         //
134         bool empty() const { return menulist_.empty(); }
135         ///
136         const_iterator begin() const {
137                 return menulist_.begin();
138         }
139         ///
140         const_iterator end() const {
141                 return menulist_.end();
142         }
143 private:
144         ///
145         MenuList menulist_;
146 };
147
148 ///
149 extern MenuBackend menubackend;
150
151 #endif /* MENUBACKEND_H */