]> git.lyx.org Git - lyx.git/blob - src/frontends/Toolbars.h
* src/frontends/Toolbars.h:
[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
30
31 namespace lyx {
32
33 class LyXView;
34
35 class LayoutBox {
36 public:
37         virtual ~LayoutBox() {}
38         /// Select the correct layout in the combox.
39         virtual void set(std::string const & layout) = 0;
40         /// Populate the layout combox.
41         virtual void update() = 0;
42         /// Erase the layout list.
43         virtual void clear() = 0;
44         /// Display the layout list.
45         virtual void open() = 0;
46         /// Set the activation status of the combox.
47         virtual void setEnabled(bool) = 0;
48 };
49
50
51 class Toolbar {
52 public:
53         virtual ~Toolbar() {}
54         /// Add a button to the bar.
55         virtual void add(FuncRequest const & func, docstring const & tooltip) = 0;
56
57         /** Hide the bar.
58          *  \param update_metrics is a hint to the layout engine that the
59          *  metrics should be updated.
60          */
61         virtual void hide(bool update_metrics) = 0;
62         /** Show the bar.
63          *  \param update_metrics is a hint to the layout engine that the
64          *  metrics should be updated.
65          */
66         virtual void show(bool update_metrics) = 0;
67
68         /// Refresh the contents of the bar.
69         virtual void update() = 0;
70         /// Accessor to the layout combox, if any.
71         virtual LayoutBox * layout() const = 0;
72 };
73
74
75 class Toolbars {
76 public:
77         ///
78         Toolbars(LyXView & owner);
79
80         /// Initialize the toolbars using the backend database.
81         void init();
82
83         /// Show/hide the named toolbar.
84         void display(std::string const & name, bool show);
85
86         /// Update the state of the toolbars.
87         void update(bool in_math, bool in_table, bool review);
88
89         /// Select the right layout in the combox.
90         void setLayout(std::string const & layout);
91
92         /** Populate the layout combox - returns whether we did a full
93          *  update or not
94          */
95         bool updateLayoutList(int textclass);
96
97         /// Drop down the layout list.
98         void openLayoutList();
99         /// Erase the layout list.
100         void clearLayoutList();
101
102         ///
103         typedef boost::shared_ptr<Toolbar> ToolbarPtr;
104
105 private:
106         /// Add a new toolbar.
107         void add(ToolbarBackend::Toolbar const & tb);
108         /// Show or hide a toolbar.
109         void displayToolbar(ToolbarBackend::Toolbar const & tb, bool show);
110         /// Update the state of the icons
111         void update();
112
113         /// The parent window.
114         LyXView & owner_;
115
116         /** The layout box is actually owned by whichever toolbar
117          *  contains it. All the Toolbars class needs is a means of
118          *  accessing it.
119          *
120          *  We don't need to use boost::weak_ptr here because the toolbars
121          *  are also stored here. There are, therefore, no lifetime issues.
122          */
123         LayoutBox * layout_;
124
125         /// Toolbar store providing access to individual toolbars by name.
126         typedef std::map<std::string, ToolbarPtr> ToolbarsMap;
127         ToolbarsMap toolbars_;
128
129         /// The last textclass layout list in the layout choice selector
130         int last_textclass_;
131 };
132
133 /// Set the layout in the kernel when an entry has been selected
134 void layoutSelected(LyXView & lv, std::string const & name);
135
136
137 } // namespace lyx
138
139 #endif // NOT TOOLBARS_H