2 * \file GuiToolbars.cpp
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Lars Gullik Bjønnes
7 * \author Angus Leeming
8 * \author Abdelrazak Younes
10 * Full author contact details are available in file CREDITS.
15 #include "GuiToolbars.h"
17 #include "GuiToolbar.h"
21 #include "BufferParams.h"
23 #include "FuncRequest.h"
24 #include "FuncStatus.h"
29 #include "TextClass.h"
38 GuiToolbars::GuiToolbars(GuiViewBase & owner)
41 last_textclass_(TextClassPtr())
45 bool GuiToolbars::visible(string const & name) const
47 std::map<string, GuiToolbar *>::const_iterator it =
49 if (it == toolbars_.end())
51 return it->second->isVisible();
55 void GuiToolbars::saveToolbarInfo()
57 ToolbarSection & tb = LyX::ref().session().toolbars();
59 for (ToolbarBackend::Toolbars::iterator cit = toolbarbackend.begin();
60 cit != toolbarbackend.end(); ++cit) {
61 ToolbarsMap::iterator it = toolbars_.find(cit->name);
62 BOOST_ASSERT(it != toolbars_.end());
63 // get toolbar info from session.
64 ToolbarSection::ToolbarInfo & info = tb.load(cit->name);
65 if (cit->flags & ToolbarInfo::ON)
66 info.state = ToolbarSection::ToolbarInfo::ON;
67 else if (cit->flags & ToolbarInfo::OFF)
68 info.state = ToolbarSection::ToolbarInfo::OFF;
69 else if (cit->flags & ToolbarInfo::AUTO)
70 info.state = ToolbarSection::ToolbarInfo::AUTO;
71 // save other information
72 // if auto, frontend should *not* set on/off
73 it->second->saveInfo(info);
74 // maybe it is useful to update flags with real status. I do not know
76 if (!(cit->flags & ToolbarInfo::AUTO)) {
77 unsigned int flags = static_cast<unsigned int>(cit->flags);
78 flags &= ~(info.state == ToolbarSection::ToolbarInfo::ON ? ToolbarInfo::OFF : ToolbarInfo::ON);
79 flags |= (info.state == ToolbarSection::ToolbarInfo::ON ? ToolbarInfo::ON : ToolbarInfo::OFF);
80 if (info.state == ToolbarSection::ToolbarInfo::ON)
81 cit->flags = static_cast<lyx::ToolbarInfo::Flags>(flags);
88 void GuiToolbars::setLayout(docstring const & layout)
95 bool GuiToolbars::updateLayoutList(TextClassPtr textclass)
97 // update the layout display
98 if (last_textclass_ != textclass) {
100 layout_->updateContents();
101 last_textclass_ = textclass;
108 void GuiToolbars::openLayoutList()
111 layout_->showPopup();
115 void GuiToolbars::clearLayoutList()
117 last_textclass_ = TextClassPtr();
123 void GuiToolbars::add(ToolbarInfo const & tbinfo, bool newline)
125 GuiToolbar * tb_ptr = owner_.makeToolbar(tbinfo, newline);
126 toolbars_[tbinfo.name] = tb_ptr;
128 if (tbinfo.flags & ToolbarInfo::ON)
133 if (tb_ptr->layout())
134 layout_ = tb_ptr->layout();
138 void GuiToolbars::displayToolbar(ToolbarInfo const & tbinfo,
141 ToolbarsMap::iterator it = toolbars_.find(tbinfo.name);
142 BOOST_ASSERT(it != toolbars_.end());
145 if (it->second->isVisible())
149 else if (it->second->isVisible())
154 void GuiToolbars::updateIcons()
156 ToolbarsMap::const_iterator it = toolbars_.begin();
157 ToolbarsMap::const_iterator const end = toolbars_.end();
158 for (; it != end; ++it)
159 it->second->updateContents();
162 lyx::getStatus(FuncRequest(LFUN_LAYOUT)).enabled();
165 layout_->setEnabled(enable);
168 } // namespace frontend