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