]> git.lyx.org Git - lyx.git/blob - src/ToolbarBackend.h
6149a6f99b4fc789ff774b3333044bcb5129d976
[lyx.git] / src / ToolbarBackend.h
1 // -*- C++ -*-
2 /**
3  * \file ToolbarBackend.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Jean-Marc Lasgouttes
8  * \author John Levon
9  *
10  * Full author contact details are available in file CREDITS.
11  */
12
13 #ifndef TOOLBAR_BACKEND_H
14 #define TOOLBAR_BACKEND_H
15
16 #include "funcrequest.h"
17
18 #include <vector>
19
20
21 namespace lyx {
22
23
24 class LyXLex;
25
26 class ToolbarItem {
27 public:
28         enum Type {
29                 /// command/action
30                 COMMAND,
31                 /// the command buffer
32                 MINIBUFFER,
33                 /// adds space between buttons in the toolbar
34                 SEPARATOR,
35                 /// a special combox insead of a button
36                 LAYOUTS,
37                 /// a special widget to insert tabulars
38                 TABLEINSERT
39         };
40
41         ToolbarItem(Type type,
42                  FuncRequest const & func,
43                  docstring const & label = docstring());
44
45         ToolbarItem(Type type,
46                  std::string const & name = std::string(),
47                  docstring const & label = docstring());
48
49         ~ToolbarItem();
50
51         /// item type
52         Type type_;
53         /// action
54         FuncRequest func_;
55         /// label/tooltip
56         docstring label_;
57         /// name
58         std::string name_;
59 };
60
61
62 ///
63 class ToolbarInfo {
64 public:
65         /// toolbar flags
66         enum Flags {
67                 ON = 1, //< show
68                 OFF = 2, //< do not show
69                 MATH = 4, //< show when in math
70                 TABLE = 8, //< show when in table
71                 TOP = 16, //< show at top
72                 BOTTOM = 32, //< show at bottom
73                 LEFT = 64, //< show at left
74                 RIGHT = 128, //< show at right
75                 REVIEW = 256, //< show when change tracking is enabled
76                 AUTO = 512  //< only if AUTO is set, when MATH, TABLE and REVIEW is used
77         };
78         /// the toolbar items
79         typedef std::vector<ToolbarItem> Items;
80
81         typedef Items::const_iterator item_iterator;
82
83         explicit ToolbarInfo(std::string const & name = std::string())
84                 : name(name) {}
85
86         /// toolbar name
87         std::string name;
88         /// toolbar GUI name
89         std::string gui_name;
90         /// toolbar contents
91         Items items;
92         /// flags
93         Flags flags;
94
95         /// read a toolbar from the file
96         ToolbarInfo & read(LyXLex &);
97
98 private:
99         /// add toolbar item
100         void add(ToolbarItem const &);
101 };
102
103
104 ///
105 class ToolbarBackend {
106 public:
107         typedef std::vector<ToolbarInfo> Toolbars;
108
109         ToolbarBackend();
110
111         /// iterator for all toolbars
112         Toolbars::const_iterator begin() const { return usedtoolbars.begin(); }
113
114         Toolbars::const_iterator end() const { return usedtoolbars.end(); }
115
116         Toolbars::iterator begin() { return usedtoolbars.begin(); }
117
118         Toolbars::iterator end() { return usedtoolbars.end(); }
119
120         /// read toolbars from the file
121         void readToolbars(LyXLex &);
122
123         /// read ui toolbar settings
124         void readToolbarSettings(LyXLex &);
125         ///
126         ToolbarInfo const & getToolbar(std::string const & name) const;
127         ///
128         ToolbarInfo & getToolbar(std::string const & name);
129
130 private:
131         /// all the toolbars
132         Toolbars toolbars;
133
134         /// toolbars listed
135         Toolbars usedtoolbars;
136 };
137
138 /// The global instance
139 extern ToolbarBackend toolbarbackend;
140
141
142
143 } // namespace lyx
144
145 #endif // TOOLBAR_BACKEND_H