]> git.lyx.org Git - lyx.git/blob - src/frontends/Toolbars.C
fix bug: table toolbar icons in menubar, hiding will be handled by the next patch
[lyx.git] / src / frontends / Toolbars.C
1 /**
2  * \file Toolbars.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Lars Gullik Bjønnes
7  * \author Angus Leeming
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #include <config.h>
13
14 #include "Toolbars.h"
15
16 #include "buffer.h"
17 #include "bufferparams.h"
18 #include "debug.h"
19 #include "funcrequest.h"
20 #include "FuncStatus.h"
21 #include "gettext.h"
22 #include "lyxfunc.h"
23 #include "lyxtextclass.h"
24 #include "LyXView.h"
25
26
27 namespace lyx {
28
29 using std::endl;
30 using std::string;
31
32
33 Toolbars::Toolbars(LyXView & owner)
34         : owner_(owner),
35           layout_(0),
36           last_textclass_(-1)
37 {}
38
39
40 void Toolbars::init()
41 {
42         // extracts the toolbars from the backend
43         ToolbarBackend::Toolbars::const_iterator cit = toolbarbackend.begin();
44         ToolbarBackend::Toolbars::const_iterator end = toolbarbackend.end();
45
46         for (; cit != end; ++cit)
47                 add(*cit);
48 }
49
50
51 void Toolbars::display(string const & name, bool show)
52 {
53         ToolbarBackend::Toolbars::const_iterator cit = toolbarbackend.begin();
54         ToolbarBackend::Toolbars::const_iterator end = toolbarbackend.end();
55
56         for (; cit != end; ++cit) {
57                 if (cit->name == name) {
58                         displayToolbar(*cit, show);
59                         return;
60                 }
61         }
62
63         lyxerr[Debug::GUI] << "Toolbar::display: no toolbar named "
64                 << name << endl;
65 }
66
67
68 void Toolbars::update(bool in_math, bool in_table)
69 {
70         update();
71
72         // extracts the toolbars from the backend
73         ToolbarBackend::Toolbars::const_iterator cit = toolbarbackend.begin();
74         ToolbarBackend::Toolbars::const_iterator end = toolbarbackend.end();
75
76         for (; cit != end; ++cit) {
77                 if (cit->flags & ToolbarBackend::MATH)
78                         displayToolbar(*cit, in_math);
79                 else if (cit->flags & ToolbarBackend::TABLE)
80                         displayToolbar(*cit, in_table);
81         }
82 }
83
84
85 void Toolbars::setLayout(string const & layout)
86 {
87         if (layout_)
88                 layout_->set(layout);
89 }
90
91
92 bool Toolbars::updateLayoutList(int textclass)
93 {
94         // update the layout display
95         if (last_textclass_ != textclass) {
96                 if (layout_)
97                         layout_->update();
98                 last_textclass_ = textclass;
99                 return true;
100         } else
101                 return false;
102 }
103
104
105 void Toolbars::openLayoutList()
106 {
107         if (layout_)
108                 layout_->open();
109 }
110
111
112 void Toolbars::clearLayoutList()
113 {
114         last_textclass_ = -1;
115         if (layout_)
116                 layout_->clear();
117 }
118
119
120 void Toolbars::add(ToolbarBackend::Toolbar const & tbb)
121 {
122         ToolbarPtr tb_ptr = owner_.makeToolbar(tbb);
123         toolbars_[tbb.name] = tb_ptr;
124
125         if (tb_ptr->layout())
126                 layout_ = tb_ptr->layout();
127 }
128
129
130 void Toolbars::displayToolbar(ToolbarBackend::Toolbar const & tbb,
131                               bool show_it)
132 {
133         ToolbarsMap::iterator it = toolbars_.find(tbb.name);
134         BOOST_ASSERT(it != toolbars_.end());
135
136         if (show_it)
137                 it->second->show(true);
138         else
139                 it->second->hide(true);
140 }
141
142
143 void Toolbars::update()
144 {
145         ToolbarsMap::const_iterator it = toolbars_.begin();
146         ToolbarsMap::const_iterator const end = toolbars_.end();
147         for (; it != end; ++it)
148                 it->second->update();
149
150         bool const enable =
151                 lyx::getStatus(FuncRequest(LFUN_LAYOUT)).enabled();
152
153         if (layout_)
154                 layout_->setEnabled(enable);
155 }
156
157
158 void layoutSelected(LyXView & lv, string const & name)
159 {
160         LyXTextClass const & tc = lv.buffer()->params().getLyXTextClass();
161
162         LyXTextClass::const_iterator it  = tc.begin();
163         LyXTextClass::const_iterator const end = tc.end();
164         for (; it != end; ++it) {
165                 string const & itname = (*it)->name();
166                 // Yes, the lyx::to_utf8(_()) is correct
167                 if (lyx::to_utf8(_(itname)) == name) {
168                         FuncRequest const func(LFUN_LAYOUT, itname,
169                                                FuncRequest::UI);
170                         lv.dispatch(func);
171                         return;
172                 }
173         }
174         lyxerr << "ERROR (layoutSelected): layout not found!"
175                << endl;
176 }
177
178
179 } // namespace lyx