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"
19 #include "BufferView.h"
20 #include "DispatchResult.h"
21 #include "FuncRequest.h"
22 #include "FuncStatus.h"
24 #include "support/gettext.h"
25 #include "LaTeXFeatures.h"
28 #include "MetricsInfo.h"
29 #include "Paragraph.h"
30 #include "paragraph_funcs.h"
33 #include "support/convert.h"
42 InsetFlex::InsetFlex(BufferParams const & bp,
43 TextClassPtr tc, string const & layoutName)
44 : InsetCollapsable(bp, Collapsed, tc),
47 setLayout(tc); // again, because now the name is initialized
48 packages_ = getLayout().requires;
49 preamble_ = getLayout().preamble;
53 InsetFlex::InsetFlex(InsetFlex const & in)
54 : InsetCollapsable(in), name_(in.name_)
58 Inset * InsetFlex::clone() const
60 return new InsetFlex(*this);
64 bool InsetFlex::undefined() const
66 return getLayout().labelstring == from_utf8("UNDEFINED");
70 docstring const InsetFlex::editMessage() const
72 return _("Opened Flex Inset");
76 void InsetFlex::write(Buffer const & buf, ostream & os) const
79 (name_.empty() ? "undefined" : name_) << "\n";
80 InsetCollapsable::write(buf, os);
84 void InsetFlex::read(Buffer const & buf, Lexer & lex)
88 string token = lex.getString();
90 if (token == "Flex") {
92 name_ = lex.getString();
95 // This is handled in Collapsable
96 else if (token == "status") {
101 InsetCollapsable::read(buf, lex);
105 int InsetFlex::plaintext(Buffer const & buf, odocstream & os,
106 OutputParams const & runparams) const
108 return InsetText::plaintext(buf, os, runparams);
112 int InsetFlex::docbook(Buffer const & buf, odocstream & os,
113 OutputParams const & runparams) const
115 ParagraphList::const_iterator beg = paragraphs().begin();
116 ParagraphList::const_iterator par = paragraphs().begin();
117 ParagraphList::const_iterator end = paragraphs().end();
120 sgml::openTag(os, getLayout().latexname,
121 par->getID(buf, runparams) + getLayout().latexparam);
123 for (; par != end; ++par) {
124 par->simpleDocBookOnePar(buf, os, runparams,
125 outerFont(distance(beg, par),
130 sgml::closeTag(os, getLayout().latexname);
136 void InsetFlex::textString(Buffer const & buf, odocstream & os) const
138 os << paragraphs().begin()->asString(buf, true);
142 void InsetFlex::validate(LaTeXFeatures & features) const
144 if (!preamble_.empty())
145 features.addPreambleSnippet(preamble_);
146 features.require(packages_);