]> git.lyx.org Git - lyx.git/blob - src/insets/InsetFlex.cpp
fix http://bugzilla.lyx.org/show_bug.cgi?id=4998
[lyx.git] / src / insets / InsetFlex.cpp
1 /**
2  * \file InsetFlex.cpp
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Angus Leeming
7  * \author Martin Vermeer
8  * \author Jürgen Spitzmüller
9  *
10  * Full author contact details are available in file CREDITS.
11  */
12
13 #include <config.h>
14
15 #include "InsetFlex.h"
16
17 #include "Buffer.h"
18 #include "BufferParams.h"
19 #include "LaTeXFeatures.h"
20 #include "Lexer.h"
21 #include "MetricsInfo.h"
22 #include "Paragraph.h"
23 #include "paragraph_funcs.h"
24 #include "sgml.h"
25 #include "Text.h"
26
27 #include "support/gettext.h"
28
29 #include <ostream>
30
31 using namespace std;
32
33 namespace lyx {
34
35
36 InsetFlex::InsetFlex(Buffer const & buf, string const & layoutName)
37         : InsetCollapsable(buf, Collapsed), name_(layoutName)
38 {
39         // again, because now the name is initialized
40         setLayout(buf.params().documentClassPtr());
41         packages_ = getLayout().requires();
42         preamble_ = getLayout().preamble();
43 }
44
45
46 InsetFlex::InsetFlex(InsetFlex const & in)
47         : InsetCollapsable(in), name_(in.name_)
48 {}
49
50
51 docstring InsetFlex::editMessage() const
52 {
53         return _("Opened Flex Inset");
54 }
55
56
57 void InsetFlex::write(ostream & os) const
58 {
59         os << "Flex " <<
60                 (name_.empty() ? "undefined" : name_) << "\n";
61         InsetCollapsable::write(os);
62 }
63
64
65 void InsetFlex::read(Lexer & lex)
66 {
67         string token;
68         while (lex.isOK()) {
69                 lex >> token;
70                 if (token == "Flex") {
71                         lex.next();
72                         name_ = lex.getString();
73                 } else if (token == "status") {
74                         // This is handled in Collapsable
75                         lex.pushToken(token);
76                         break;
77                 }
78         }
79         InsetCollapsable::read(lex);
80 }
81
82
83 int InsetFlex::plaintext(odocstream & os, OutputParams const & runparams) const
84 {
85         return InsetText::plaintext(os, runparams);
86 }
87
88
89 int InsetFlex::docbook(odocstream & os, OutputParams const & runparams) const
90 {
91         ParagraphList::const_iterator beg = paragraphs().begin();
92         ParagraphList::const_iterator par = paragraphs().begin();
93         ParagraphList::const_iterator end = paragraphs().end();
94
95         if (!undefined())
96                 sgml::openTag(os, getLayout().latexname(),
97                               par->getID(buffer(), runparams) + getLayout().latexparam());
98
99         for (; par != end; ++par) {
100                 par->simpleDocBookOnePar(buffer(), os, runparams,
101                                          outerFont(distance(beg, par),
102                                                    paragraphs()));
103         }
104
105         if (!undefined())
106                 sgml::closeTag(os, getLayout().latexname());
107
108         return 0;
109 }
110
111
112 void InsetFlex::textString(odocstream & os) const
113 {
114         os << paragraphs().begin()->asString(AS_STR_LABEL | AS_STR_INSETS);
115 }
116
117
118 void InsetFlex::validate(LaTeXFeatures & features) const
119 {
120         if (!preamble_.empty())
121                 features.addPreambleSnippet(preamble_);
122         features.require(packages_);
123 }
124
125 } // namespace lyx