3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Angus Leeming
7 * \author Martin Vermeer
8 * \author Jürgen Spitzmüller
10 * Full author contact details are available in file CREDITS.
15 #include "InsetFlex.h"
18 #include "BufferParams.h"
20 #include "FuncRequest.h"
21 #include "FuncStatus.h"
24 #include "support/gettext.h"
33 InsetFlex::InsetFlex(Buffer * buf, string const & layoutName)
34 : InsetCollapsable(buf), name_(layoutName)
40 InsetFlex::InsetFlex(InsetFlex const & in)
41 : InsetCollapsable(in), name_(in.name_)
45 InsetLayout const & InsetFlex::getLayout() const
47 DocumentClass const & dc = buffer().params().documentClass();
48 docstring const dname = from_utf8(name_);
49 if (dc.hasInsetLayout(dname))
50 return dc.insetLayout(dname);
51 return dc.insetLayout(from_utf8("Flex:" + name_));
55 InsetLayout::InsetDecoration InsetFlex::decoration() const
57 InsetLayout::InsetDecoration const dec = getLayout().decoration();
58 return dec == InsetLayout::DEFAULT ? InsetLayout::CONGLOMERATE : dec;
62 void InsetFlex::write(ostream & os) const
65 (name_.empty() ? "undefined" : name_) << "\n";
66 InsetCollapsable::write(os);
70 bool InsetFlex::getStatus(Cursor & cur, FuncRequest const & cmd,
71 FuncStatus & flag) const
73 switch (cmd.action()) {
74 case LFUN_INSET_DISSOLVE:
75 if (!cmd.argument().empty()) {
76 InsetLayout const & il = getLayout();
77 InsetLayout::InsetLyXType const type =
78 translateLyXType(to_utf8(cmd.argument()));
79 if (il.lyxtype() == type) {
80 FuncRequest temp_cmd(LFUN_INSET_DISSOLVE);
81 return InsetCollapsable::getStatus(cur, temp_cmd, flag);
87 return InsetCollapsable::getStatus(cur, cmd, flag);
92 void InsetFlex::doDispatch(Cursor & cur, FuncRequest & cmd)
94 switch (cmd.action()) {
95 case LFUN_INSET_DISSOLVE:
96 if (!cmd.argument().empty()) {
97 InsetLayout const & il = getLayout();
98 InsetLayout::InsetLyXType const type =
99 translateLyXType(to_utf8(cmd.argument()));
101 if (il.lyxtype() == type) {
102 FuncRequest temp_cmd(LFUN_INSET_DISSOLVE);
103 InsetCollapsable::doDispatch(cur, temp_cmd);
110 InsetCollapsable::doDispatch(cur, cmd);