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 "frontends/FontMetrics.h"
34 #include "frontends/Painter.h"
36 #include "support/convert.h"
45 InsetFlex::InsetFlex(BufferParams const & bp,
46 InsetLayout const & il)
47 : InsetCollapsable(bp, Collapsed, &il)
50 packages_ = il.requires;
51 preamble_ = il.preamble;
55 InsetFlex::InsetFlex(InsetFlex const & in)
56 : InsetCollapsable(in), name_(in.name_)
60 Inset * InsetFlex::clone() const
62 return new InsetFlex(*this);
66 bool InsetFlex::undefined() const
68 return layout_->labelstring == from_utf8("UNDEFINED");
72 docstring const InsetFlex::editMessage() const
74 return _("Opened Flex Inset");
78 void InsetFlex::write(Buffer const & buf, ostream & os) const
80 os << "Flex " << name_ << "\n";
81 InsetCollapsable::write(buf, os);
85 void InsetFlex::read(Buffer const & buf, Lexer & lex)
89 string token = lex.getString();
91 if (token == "Flex") {
93 name_ = lex.getString();
96 // This is handled in Collapsable
97 else if (token == "status") {
102 InsetCollapsable::read(buf, lex);
106 int InsetFlex::plaintext(Buffer const & buf, odocstream & os,
107 OutputParams const & runparams) const
109 return InsetText::plaintext(buf, os, runparams);
113 int InsetFlex::docbook(Buffer const & buf, odocstream & os,
114 OutputParams const & runparams) const
116 ParagraphList::const_iterator beg = paragraphs().begin();
117 ParagraphList::const_iterator par = paragraphs().begin();
118 ParagraphList::const_iterator end = paragraphs().end();
121 sgml::openTag(os, layout_->latexname,
122 par->getID(buf, runparams) + layout_->latexparam);
124 for (; par != end; ++par) {
125 par->simpleDocBookOnePar(buf, os, runparams,
126 outerFont(distance(beg, par),
131 sgml::closeTag(os, layout_->latexname);
137 void InsetFlex::textString(Buffer const & buf, odocstream & os) const
139 os << paragraphs().begin()->asString(buf, true);
143 void InsetFlex::validate(LaTeXFeatures & features) const
145 if (!preamble_.empty())
146 features.addPreambleSnippet(preamble_);
147 if (packages_.empty())
149 for (vector<string>::const_iterator it = packages_.begin();
150 it != packages_.end(); ++it) {
151 features.require(*it);