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
9 * Full author contact details are available in file CREDITS.
14 #include "frontends/Toolbars.h"
17 #include "BufferParams.h"
19 #include "FuncRequest.h"
20 #include "FuncStatus.h"
25 #include "TextClass.h"
37 #define TurnOnFlag(x) flags |= ToolbarInfo::x
38 #define TurnOffFlag(x) flags &= ~ToolbarInfo::x
40 void Toolbars::initFlags(ToolbarInfo & tbinfo)
42 ToolbarSection::ToolbarInfo & info = LyX::ref().session().toolbars().load(tbinfo.name);
44 unsigned int flags = static_cast<unsigned int>(tbinfo.flags);
46 // Remove default.ui positions. Only when a valid postion is stored
47 // in the session file the default.ui value will be overwritten
48 unsigned int save = flags;
54 bool valid_location = true;
55 // init tbinfo.flags with saved location
56 if (info.location == ToolbarSection::ToolbarInfo::TOP)
58 else if (info.location == ToolbarSection::ToolbarInfo::BOTTOM)
60 else if (info.location == ToolbarSection::ToolbarInfo::RIGHT)
62 else if (info.location == ToolbarSection::ToolbarInfo::LEFT)
65 // use setting from default.ui
67 valid_location = false;
70 // invalid location is for a new toolbar that has no saved information,
71 // so info.visible is not used for this case.
73 // init tbinfo.flags with saved visibility,
77 if (info.state == ToolbarSection::ToolbarInfo::ON)
79 else if (info.state == ToolbarSection::ToolbarInfo::OFF)
85 std::cout << "State " << info.state << " FLAGS: " << flags
86 << " ON:" << (flags & ToolbarBackend::ON)
87 << " OFF:" << (flags & ToolbarBackend::OFF)
88 << " L:" << (flags & ToolbarBackend::LEFT)
89 << " R:" << (flags & ToolbarBackend::RIGHT)
90 << " T:" << (flags & ToolbarBackend::TOP)
91 << " B:" << (flags & ToolbarBackend::BOTTOM)
92 << " MA:" << (flags & ToolbarBackend::MATH)
93 << " RE:" << (flags & ToolbarBackend::REVIEW)
94 << " TB:" << (flags & ToolbarBackend::TABLE)
95 << " AU:" << (flags & ToolbarBackend::AUTO)
99 tbinfo.flags = static_cast<lyx::ToolbarInfo::Flags>(flags);
103 void Toolbars::init()
105 // extracts the toolbars from the backend
106 ToolbarBackend::Toolbars::iterator cit = toolbarbackend.begin();
107 ToolbarBackend::Toolbars::iterator end = toolbarbackend.end();
109 // init flags will also add these toolbars to session if they
110 // are not already there (e.g. first run of lyx).
111 for (; cit != end; ++cit)
114 // add toolbars according the order in session
115 ToolbarSection::ToolbarList::const_iterator tb = LyX::ref().session().toolbars().begin();
116 ToolbarSection::ToolbarList::const_iterator te = LyX::ref().session().toolbars().end();
117 ToolbarSection::ToolbarInfo::Location last_loc = ToolbarSection::ToolbarInfo::NOTSET;
120 for (; tb != te; ++tb) {
121 LYXERR(Debug::INIT) << "Adding " << tb->get<0>() << " at position " << tb->get<1>().posx << " " << tb->get<1>().posy << endl;
122 // add toolbar break if posx or posy changes
123 bool newline = tb->get<1>().location == last_loc && (
124 // if two toolbars at the same location, assume uninitialized and add toolbar break
125 (tb->get<1>().posx == last_posx && tb->get<1>().posy == last_posy) ||
126 (last_loc == ToolbarSection::ToolbarInfo::TOP && tb->get<1>().posy != last_posy) ||
127 (last_loc == ToolbarSection::ToolbarInfo::BOTTOM && tb->get<1>().posy != last_posy) ||
128 (last_loc == ToolbarSection::ToolbarInfo::LEFT && tb->get<1>().posx != last_posx) ||
129 (last_loc == ToolbarSection::ToolbarInfo::RIGHT && tb->get<1>().posx != last_posx) );
130 // find the backend item and add
131 for (cit = toolbarbackend.begin(); cit != end; ++cit)
132 if (cit->name == tb->get<0>()) {
134 last_loc = tb->get<1>().location;
135 last_posx = tb->get<1>().posx;
136 last_posy = tb->get<1>().posy;
143 void Toolbars::display(string const & name, bool show)
145 ToolbarBackend::Toolbars::iterator cit = toolbarbackend.begin();
146 ToolbarBackend::Toolbars::iterator end = toolbarbackend.end();
148 for (; cit != end; ++cit) {
149 if (cit->name == name) {
150 unsigned int flags = cit->flags;
158 cit->flags = static_cast<lyx::ToolbarInfo::Flags>(flags);
159 displayToolbar(*cit, show);
163 LYXERR(Debug::GUI) << "Toolbar::display: no toolbar named "
168 ToolbarInfo * Toolbars::getToolbarInfo(string const & name)
170 return toolbarbackend.getUsedToolbarInfo(name);
174 void Toolbars::toggleToolbarState(string const & name, bool allowauto)
176 ToolbarInfo * tbi = toolbarbackend.getUsedToolbarInfo(name);
179 LYXERR(Debug::GUI) << "Toolbar::display: no toolbar named "
184 int flags = tbi->flags;
186 if (flags & ToolbarInfo::OFF) {
190 } else if (flags & ToolbarInfo::AUTO) {
194 && ((flags & ToolbarInfo::MATH)
195 || (flags & ToolbarInfo::TABLE)
196 || (flags & ToolbarInfo::REVIEW))) {
197 // for math etc, toggle from on -> auto
201 // for others, toggle from on -> off
205 tbi->flags = static_cast<ToolbarInfo::Flags>(flags);
211 void Toolbars::update(bool in_math, bool in_table, bool review)
215 // extracts the toolbars from the backend
216 ToolbarBackend::Toolbars::const_iterator cit = toolbarbackend.begin();
217 ToolbarBackend::Toolbars::const_iterator end = toolbarbackend.end();
219 for (; cit != end; ++cit) {
220 if (cit->flags & ToolbarInfo::ON)
221 displayToolbar(*cit, true);
222 else if (cit->flags & ToolbarInfo::OFF)
223 displayToolbar(*cit, false);
224 else if ((cit->flags & ToolbarInfo::AUTO) && (cit->flags & ToolbarInfo::MATH))
225 displayToolbar(*cit, in_math);
226 else if ((cit->flags & ToolbarInfo::AUTO) && (cit->flags & ToolbarInfo::TABLE))
227 displayToolbar(*cit, in_table);
228 else if ((cit->flags & ToolbarInfo::AUTO) && (cit->flags & ToolbarInfo::REVIEW))
229 displayToolbar(*cit, review);
234 } // namespace frontend