]> git.lyx.org Git - lyx.git/blob - src/frontends/Toolbars.h
Fulfill promise to Andre: TextClass_ptr --> TextClassPtr.
[lyx.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 "TextClassPtr.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         /// Set the focus on the command buffer, if any.
84         virtual void focusCommandBuffer() = 0;
85 };
86
87
88 class Toolbars {
89 public:
90         ///
91         Toolbars(LyXView & owner);
92
93         /// Initialize the toolbars using the backend database.
94         void init();
95
96         /// Show/hide the named toolbar.
97         Toolbar * display(std::string const & name, bool show);
98
99         /// get toolbar info
100         ToolbarInfo * getToolbarInfo(std::string const & name);
101
102         /** toggle the state of toolbars (on/off/auto). Skip "auto"
103          * when allowauto is false.
104          */
105         void toggleToolbarState(std::string const & name, bool allowauto);
106
107         /// Update the state of the toolbars.
108         void update(bool in_math, bool in_table, bool review);
109
110         /// Is the Toolbar currently visible?
111         bool visible(std::string const & name) const;
112
113         /// save toolbar information
114         void saveToolbarInfo();
115
116         /// Select the right layout in the combox.
117         void setLayout(docstring const & layout);
118
119         /** Populate the layout combox - returns whether we did a full
120          *  update or not
121          */
122         bool updateLayoutList(TextClassPtr textclass);
123
124         /// Drop down the layout list.
125         void openLayoutList();
126         /// Erase the layout list.
127         void clearLayoutList();
128
129         ///
130         typedef boost::shared_ptr<Toolbar> ToolbarPtr;
131
132 private:
133         /// Add a new toolbar. if newline==true, start from a new line
134         void add(ToolbarInfo const & tbinfo, bool newline);
135         /// Show or hide a toolbar.
136         Toolbar * displayToolbar(ToolbarInfo const & tbinfo, bool show);
137         /// Update the state of the icons
138         void update();
139
140         /// The parent window.
141         LyXView & owner_;
142
143         /** The layout box is actually owned by whichever toolbar
144          *  contains it. All the Toolbars class needs is a means of
145          *  accessing it.
146          *
147          *  We don't need to use boost::weak_ptr here because the toolbars
148          *  are also stored here. There are, therefore, no lifetime issues.
149          */
150         LayoutBox * layout_;
151
152         /// Toolbar store providing access to individual toolbars by name.
153         typedef std::map<std::string, ToolbarPtr> ToolbarsMap;
154         ToolbarsMap toolbars_;
155
156         /// The last textclass layout list in the layout choice selector
157         TextClassPtr last_textclass_;
158
159         // load flags with saved values
160         void initFlags(ToolbarInfo & tbinfo);
161 };
162
163 /// Set the layout in the kernel when an entry has been selected
164 void layoutSelected(LyXView & lv, docstring const & name);
165
166
167 } // namespace frontend
168 } // namespace lyx
169
170 #endif // NOT TOOLBARS_H