]> git.lyx.org Git - features.git/blob - src/frontends/Toolbars.h
This is one of a series of patches that will merge the layout modules development...
[features.git] / src / frontends / Toolbars.h
1 // -*- C++ -*-
2 /**
3  * \file Toolbars.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Lars Gullik Bjønnes
8  * \author Angus Leeming
9  *
10  * Full author contact details are available in file CREDITS.
11  *
12  * The Toolbars class is a container of toolbars.
13  * It provides accessors to each Toolbar and to the LayoutBox.
14  *
15  * Each GUI frontend should provide toolbar and layout boxes by derivation
16  * from the LayoutBox and Toolbar pure abstract classes.
17  *
18  * The Toolbars class has no knowledge at all of the details of each
19  * frontend's implementation, which requires that each frontend should
20  * provide a 'make_toolbar' function, signature below.
21  */
22
23 #ifndef TOOLBARS_H
24 #define TOOLBARS_H
25
26 #include "TextClass_ptr.h"
27 #include "ToolbarBackend.h"
28 #include "Session.h"
29
30 #include <boost/shared_ptr.hpp>
31
32 #include <map>
33
34 namespace lyx {
35 namespace frontend {
36
37 class LyXView;
38
39 class LayoutBox {
40 public:
41         virtual ~LayoutBox() {}
42         /// Select the correct layout in the combox.
43         virtual void set(docstring const & layout) = 0;
44         /// Populate the layout combox.
45         virtual void update() = 0;
46         /// Erase the layout list.
47         virtual void clear() = 0;
48         /// Display the layout list.
49         virtual void open() = 0;
50         /// Set the activation status of the combox.
51         virtual void setEnabled(bool) = 0;
52 };
53
54
55 class Toolbar {
56 public:
57         virtual ~Toolbar() {}
58         /// Add a button to the bar.
59         virtual void add(ToolbarItem const & item) = 0;
60
61         /** Hide the bar.
62          *  \param update_metrics is a hint to the layout engine that the
63          *  metrics should be updated.
64          */
65         virtual void hide(bool update_metrics) = 0;
66         /** Show the bar.
67          *  \param update_metrics is a hint to the layout engine that the
68          *  metrics should be updated.
69          */
70         virtual void show(bool update_metrics) = 0;
71         /** update toolbar information
72         * ToolbarInfo will then be saved by session
73         */
74         virtual void saveInfo(ToolbarSection::ToolbarInfo & tbinfo) = 0;
75
76         /// whether toolbar is visible
77         virtual bool isVisible() const = 0;
78         /// Refresh the contents of the bar.
79         virtual void update() = 0;
80         /// Accessor to the layout combox, if any.
81         virtual LayoutBox * layout() const = 0;
82 };
83
84
85 class Toolbars {
86 public:
87         ///
88         Toolbars(LyXView & owner);
89
90         /// Initialize the toolbars using the backend database.
91         void init();
92
93         /// Show/hide the named toolbar.
94         void display(std::string const & name, bool show);
95
96         /// get toolbar info
97         ToolbarInfo * getToolbarInfo(std::string const & name);
98
99         /** toggle the state of toolbars (on/off/auto). Skip "auto"
100          * when allowauto is false.
101          */
102         void toggleToolbarState(std::string const & name, bool allowauto);
103
104         /// Update the state of the toolbars.
105         void update(bool in_math, bool in_table, bool review);
106
107         /// Is the Toolbar currently visible?
108         bool visible(std::string const & name) const;
109
110         /// save toolbar information
111         void saveToolbarInfo();
112
113         /// Select the right layout in the combox.
114         void setLayout(docstring const & layout);
115
116         /** Populate the layout combox - returns whether we did a full
117          *  update or not
118          */
119         bool updateLayoutList(TextClass_ptr textclass);
120
121         /// Drop down the layout list.
122         void openLayoutList();
123         /// Erase the layout list.
124         void clearLayoutList();
125
126         ///
127         typedef boost::shared_ptr<Toolbar> ToolbarPtr;
128
129 private:
130         /// Add a new toolbar. if newline==true, start from a new line
131         void add(ToolbarInfo const & tbinfo, bool newline);
132         /// Show or hide a toolbar.
133         void displayToolbar(ToolbarInfo const & tbinfo, bool show);
134         /// Update the state of the icons
135         void update();
136
137         /// The parent window.
138         LyXView & owner_;
139
140         /** The layout box is actually owned by whichever toolbar
141          *  contains it. All the Toolbars class needs is a means of
142          *  accessing it.
143          *
144          *  We don't need to use boost::weak_ptr here because the toolbars
145          *  are also stored here. There are, therefore, no lifetime issues.
146          */
147         LayoutBox * layout_;
148
149         /// Toolbar store providing access to individual toolbars by name.
150         typedef std::map<std::string, ToolbarPtr> ToolbarsMap;
151         ToolbarsMap toolbars_;
152
153         /// The last textclass layout list in the layout choice selector
154         TextClass_ptr last_textclass_;
155
156         // load flags with saved values
157         void initFlags(ToolbarInfo & tbinfo);
158 };
159
160 /// Set the layout in the kernel when an entry has been selected
161 void layoutSelected(LyXView & lv, docstring const & name);
162
163
164 } // namespace frontend
165 } // namespace lyx
166
167 #endif // NOT TOOLBARS_H