+#define TurnOnFlag(x) flags |= ToolbarBackend::x
+#define TurnOffFlag(x) flags &= ~ToolbarBackend::x
+
+void Toolbars::initFlags(ToolbarBackend::Toolbar & tbb)
+{
+ ToolbarSection::ToolbarInfo & info = LyX::ref().session().toolbars().load(tbb.name);
+
+ unsigned int flags = static_cast<unsigned int>(tbb.flags);
+ // remove position
+ TurnOffFlag(TOP);
+ TurnOffFlag(BOTTOM);
+ TurnOffFlag(RIGHT);
+ TurnOffFlag(LEFT);
+
+ bool valid_location = true;
+ // init tbb.flags with saved location
+ if (info.location == ToolbarSection::ToolbarInfo::TOP)
+ TurnOnFlag(TOP);
+ else if (info.location == ToolbarSection::ToolbarInfo::BOTTOM)
+ TurnOnFlag(BOTTOM);
+ else if (info.location == ToolbarSection::ToolbarInfo::RIGHT)
+ TurnOnFlag(RIGHT);
+ else if (info.location == ToolbarSection::ToolbarInfo::LEFT)
+ TurnOnFlag(LEFT);
+ else {
+ TurnOnFlag(TOP);
+ valid_location = false;
+ }
+
+ // invalid location is for a new toolbar that has no saved information,
+ // so info.visible is not used for this case.
+ if (valid_location) {
+ // init tbb.flags with saved visibility,
+ TurnOffFlag(ON);
+ TurnOffFlag(OFF);
+ TurnOffFlag(AUTO);
+ if (info.state == ToolbarSection::ToolbarInfo::ON)
+ TurnOnFlag(ON);
+ else if (info.state == ToolbarSection::ToolbarInfo::OFF)
+ TurnOnFlag(OFF);
+ else
+ TurnOnFlag(AUTO);
+ }
+ /*
+ std::cout << "State " << info.state << " FLAGS: " << flags
+ << " ON:" << (flags & ToolbarBackend::ON)
+ << " OFF:" << (flags & ToolbarBackend::OFF)
+ << " L:" << (flags & ToolbarBackend::LEFT)
+ << " R:" << (flags & ToolbarBackend::RIGHT)
+ << " T:" << (flags & ToolbarBackend::TOP)
+ << " B:" << (flags & ToolbarBackend::BOTTOM)
+ << " MA:" << (flags & ToolbarBackend::MATH)
+ << " RE:" << (flags & ToolbarBackend::REVIEW)
+ << " TB:" << (flags & ToolbarBackend::TABLE)
+ << " AU:" << (flags & ToolbarBackend::AUTO)
+ << std::endl;
+ */
+ // now set the flags
+ tbb.flags = static_cast<lyx::ToolbarBackend::Flags>(flags);
+}
+