]> git.lyx.org Git - lyx.git/blob - src/MenuBackend.h
GUI-indep toolbar and menus mostly work !
[lyx.git] / src / MenuBackend.h
1 /* This file is part of              -*- C++ -*-
2 * ======================================================
3
4 *           LyX, The Document Processor
5 *
6 *           Copyright (C) 1995 Matthias Ettrich
7 *           Copyright (C) 1995-1999 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 class MenuItem;
27
28 class MenuItem {
29 public:
30         // The type of elements that can be in a menu
31         enum Kind { 
32                 Command, 
33                 Submenu, 
34                 Separator, 
35                 Lastfiles, // This is the list of last opened file,
36                            // typically for the File menu. 
37                 Documents  // This is the list of opened Documents,
38                            // typically for the Documents menu.
39         };
40         // Create a copy of a given MenuItem
41         MenuItem(MenuItem const &);
42         // Create a Command type MenuItem
43         MenuItem(Kind kind_, string const & label_ = string(), 
44                  string const & command_ = string());
45         //
46         ~MenuItem() {}
47
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         
57 private:
58         Kind kind_;
59         string label_;
60         int action_;
61         string submenu_;
62         MenuItem() {}
63 };
64
65
66 class Menu {
67 public:
68         //
69         typedef std::vector<MenuItem> ItemList;
70         //
71         typedef ItemList::const_iterator const_iterator;
72         //
73         explicit Menu(string const & name, bool mb = false) 
74                 : menubar_(mb), name_(name) {}
75         //
76         void add(MenuItem const &);
77         //
78         void read(LyXLex &);
79         // 
80         bool menubar() const { return menubar_; }
81         // 
82         string const & name() const { return name_; }
83         //
84         bool empty() const { return items_.empty(); }
85         ///
86         const_iterator begin() const {
87                 return items_.begin();
88         }
89         ///
90         const_iterator end() const {
91                 return items_.end();
92         }
93     
94 private:
95         ///
96         ItemList items_;
97         ///
98         bool menubar_;
99         ///
100         string name_;
101         ///
102 };
103
104
105 class MenuBackend {
106 public:
107         ///
108         typedef std::vector<Menu> MenuList;
109         ///
110         typedef MenuList::const_iterator const_iterator;
111         ///
112         void read(LyXLex &);
113         /// Set default values for menu structure.
114         void defaults();
115         ///
116         void add(Menu const &);
117         ///
118         bool hasMenu (string const &) const;
119         ///
120         Menu const & getMenu (string const &) const;
121         //
122         bool empty() const { return menulist_.empty(); }
123         ///
124         const_iterator begin() const {
125                 return menulist_.begin();
126         }
127         ///
128         const_iterator end() const {
129                 return menulist_.end();
130         }
131 private:
132         ///
133         MenuList menulist_;
134 };
135
136 extern MenuBackend menubackend;
137
138 #endif /* MENUBACKEND_H */