]> git.lyx.org Git - lyx.git/blob - src/frontends/Toolbars.h
merge controllers/Makefile.am and controllers/tests/Makefile.am
[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 "ToolbarBackend.h"
27 #include <boost/shared_ptr.hpp>
28 #include <map>
29 #include "Session.h"
30
31
32 namespace lyx {
33
34 class LyXView;
35
36 class LayoutBox {
37 public:
38         virtual ~LayoutBox() {}
39         /// Select the correct layout in the combox.
40         virtual void set(docstring const & layout) = 0;
41         /// Populate the layout combox.
42         virtual void update() = 0;
43         /// Erase the layout list.
44         virtual void clear() = 0;
45         /// Display the layout list.
46         virtual void open() = 0;
47         /// Set the activation status of the combox.
48         virtual void setEnabled(bool) = 0;
49 };
50
51
52 class Toolbar {
53 public:
54         virtual ~Toolbar() {}
55         /// Add a button to the bar.
56         virtual void add(ToolbarItem const & item) = 0;
57
58         /** Hide the bar.
59          *  \param update_metrics is a hint to the layout engine that the
60          *  metrics should be updated.
61          */
62         virtual void hide(bool update_metrics) = 0;
63         /** Show the bar.
64          *  \param update_metrics is a hint to the layout engine that the
65          *  metrics should be updated.
66          */
67         virtual void show(bool update_metrics) = 0;
68         /** update toolbar information
69         * ToolbarInfo will then be saved by session
70         */
71         virtual void saveInfo(ToolbarSection::ToolbarInfo & tbinfo) = 0;
72
73         /// whether toolbar is visible
74         virtual bool isVisible() const = 0;
75         /// Refresh the contents of the bar.
76         virtual void update() = 0;
77         /// Accessor to the layout combox, if any.
78         virtual LayoutBox * layout() const = 0;
79 };
80
81
82 class Toolbars {
83 public:
84         ///
85         Toolbars(LyXView & owner);
86
87         /// Initialize the toolbars using the backend database.
88         void init();
89
90         /// Show/hide the named toolbar.
91         void display(std::string const & name, bool show);
92
93         /// get toolbar info
94         ToolbarInfo * getToolbarInfo(std::string const & name);
95
96         /** toggle the state of toolbars (on/off/auto). Skip "auto"
97          * when allowauto is false.
98          */
99         void toggleToolbarState(std::string const & name, bool allowauto);
100
101         /// Update the state of the toolbars.
102         void update(bool in_math, bool in_table, bool review);
103
104         /// Is the Toolbar currently visible?
105         bool visible(std::string const & name) const;
106
107         /// save toolbar information
108         void saveToolbarInfo();
109
110         /// Select the right layout in the combox.
111         void setLayout(docstring const & layout);
112
113         /** Populate the layout combox - returns whether we did a full
114          *  update or not
115          */
116         bool updateLayoutList(int textclass);
117
118         /// Drop down the layout list.
119         void openLayoutList();
120         /// Erase the layout list.
121         void clearLayoutList();
122
123         ///
124         typedef boost::shared_ptr<Toolbar> ToolbarPtr;
125
126 private:
127         /// Add a new toolbar. if newline==true, start from a new line
128         void add(ToolbarInfo const & tbinfo, bool newline);
129         /// Show or hide a toolbar.
130         void displayToolbar(ToolbarInfo const & tbinfo, bool show);
131         /// Update the state of the icons
132         void update();
133
134         /// The parent window.
135         LyXView & owner_;
136
137         /** The layout box is actually owned by whichever toolbar
138          *  contains it. All the Toolbars class needs is a means of
139          *  accessing it.
140          *
141          *  We don't need to use boost::weak_ptr here because the toolbars
142          *  are also stored here. There are, therefore, no lifetime issues.
143          */
144         LayoutBox * layout_;
145
146         /// Toolbar store providing access to individual toolbars by name.
147         typedef std::map<std::string, ToolbarPtr> ToolbarsMap;
148         ToolbarsMap toolbars_;
149
150         /// The last textclass layout list in the layout choice selector
151         int last_textclass_;
152
153         // load flags with saved values
154         void initFlags(ToolbarInfo & tbinfo);
155 };
156
157 /// Set the layout in the kernel when an entry has been selected
158 void layoutSelected(LyXView & lv, docstring const & name);
159
160
161 } // namespace lyx
162
163 #endif // NOT TOOLBARS_H