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