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 "ParIterator.h"
25 #include "TextClass.h"
27 #include "support/gettext.h"
36 InsetFlex::InsetFlex(Buffer * buf, string const & layoutName)
37 : InsetCollapsable(buf), name_(layoutName)
41 InsetFlex::InsetFlex(InsetFlex const & in)
42 : InsetCollapsable(in), name_(in.name_)
46 // special code for InsetFlex when there is not the explicit Flex:: prefix
47 InsetLayout const & InsetFlex::getLayout() const
50 return DocumentClass::plainInsetLayout();
52 DocumentClass const & dc = buffer().params().documentClass();
53 docstring const dname = from_utf8(name_);
54 if (dc.hasInsetLayout(dname))
55 return dc.insetLayout(dname);
56 return dc.insetLayout(from_utf8("Flex:" + name_));
60 bool InsetFlex::resetFontEdit() const
62 if (getLayout().resetsFont())
64 return InsetCollapsable::resetFontEdit();
68 InsetLayout::InsetDecoration InsetFlex::decoration() const
70 InsetLayout::InsetDecoration const dec = getLayout().decoration();
71 return dec == InsetLayout::DEFAULT ? InsetLayout::CONGLOMERATE : dec;
75 void InsetFlex::write(ostream & os) const
78 (name_.empty() ? "undefined" : name_) << "\n";
79 InsetCollapsable::write(os);
83 bool InsetFlex::getStatus(Cursor & cur, FuncRequest const & cmd,
84 FuncStatus & flag) const
86 switch (cmd.action()) {
87 case LFUN_INSET_DISSOLVE:
88 if (!cmd.argument().empty()) {
89 InsetLayout const & il = getLayout();
90 InsetLayout::InsetLyXType const type =
91 translateLyXType(to_utf8(cmd.argument()));
92 if (il.lyxtype() == type) {
93 FuncRequest temp_cmd(LFUN_INSET_DISSOLVE);
94 return InsetCollapsable::getStatus(cur, temp_cmd, flag);
100 return InsetCollapsable::getStatus(cur, cmd, flag);
105 void InsetFlex::doDispatch(Cursor & cur, FuncRequest & cmd)
107 switch (cmd.action()) {
108 case LFUN_INSET_DISSOLVE:
109 if (!cmd.argument().empty()) {
110 InsetLayout const & il = getLayout();
111 InsetLayout::InsetLyXType const type =
112 translateLyXType(to_utf8(cmd.argument()));
114 if (il.lyxtype() == type) {
115 FuncRequest temp_cmd(LFUN_INSET_DISSOLVE);
116 InsetCollapsable::doDispatch(cur, temp_cmd);
123 InsetCollapsable::doDispatch(cur, cmd);
129 void InsetFlex::updateBuffer(ParIterator const & it, UpdateType utype)
131 BufferParams const & bp = buffer().masterBuffer()->params();
132 InsetLayout const & il = getLayout();
133 docstring custom_label = translateIfPossible(il.labelstring());
135 Counters & cnts = bp.documentClass().counters();
136 docstring const & count = il.counter();
137 bool const have_counter = cnts.hasCounter(count);
139 cnts.step(count, utype);
140 custom_label += ' ' +
141 cnts.theCounter(count, it.paragraph().getParLanguage(bp)->code());
143 setLabel(custom_label);
145 bool const save_counter = have_counter && utype == OutputUpdate;
147 // we assume the counter is local to this inset
148 // if this turns out to be wrong in some case, we will
149 // need a layout flag
150 cnts.saveLastCounter();
152 InsetCollapsable::updateBuffer(it, utype);
154 cnts.restoreLastCounter();