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 InsetLayout::InsetDecoration InsetFlex::decoration() const
62 InsetLayout::InsetDecoration const dec = getLayout().decoration();
63 return dec == InsetLayout::DEFAULT ? InsetLayout::CONGLOMERATE : dec;
67 void InsetFlex::write(ostream & os) const
70 (name_.empty() ? "undefined" : name_) << "\n";
71 InsetCollapsable::write(os);
75 bool InsetFlex::getStatus(Cursor & cur, FuncRequest const & cmd,
76 FuncStatus & flag) const
78 switch (cmd.action()) {
79 case LFUN_INSET_DISSOLVE:
80 if (!cmd.argument().empty()) {
81 InsetLayout const & il = getLayout();
82 InsetLayout::InsetLyXType const type =
83 translateLyXType(to_utf8(cmd.argument()));
84 if (il.lyxtype() == type) {
85 FuncRequest temp_cmd(LFUN_INSET_DISSOLVE);
86 return InsetCollapsable::getStatus(cur, temp_cmd, flag);
92 return InsetCollapsable::getStatus(cur, cmd, flag);
97 void InsetFlex::doDispatch(Cursor & cur, FuncRequest & cmd)
99 switch (cmd.action()) {
100 case LFUN_INSET_DISSOLVE:
101 if (!cmd.argument().empty()) {
102 InsetLayout const & il = getLayout();
103 InsetLayout::InsetLyXType const type =
104 translateLyXType(to_utf8(cmd.argument()));
106 if (il.lyxtype() == type) {
107 FuncRequest temp_cmd(LFUN_INSET_DISSOLVE);
108 InsetCollapsable::doDispatch(cur, temp_cmd);
115 InsetCollapsable::doDispatch(cur, cmd);
121 void InsetFlex::updateBuffer(ParIterator const & it, UpdateType utype)
123 BufferParams const & bp = buffer().masterBuffer()->params();
124 InsetLayout const & il = getLayout();
125 docstring custom_label = translateIfPossible(il.labelstring());
127 Counters & cnts = bp.documentClass().counters();
128 docstring const & count = il.counter();
129 bool const have_counter = cnts.hasCounter(count);
131 cnts.step(count, utype);
132 custom_label += ' ' +
133 cnts.theCounter(count, it.paragraph().getParLanguage(bp)->code());
135 setLabel(custom_label);
137 bool const save_counter = have_counter && utype == OutputUpdate;
139 // we assume the counter is local to this inset
140 // if this turns out to be wrong in some case, we will
141 // need a layout flag
142 cnts.saveLastCounter();
144 InsetCollapsable::updateBuffer(it, utype);
146 cnts.restoreLastCounter();