]> git.lyx.org Git - lyx.git/blob - src/insets/InsetFlex.cpp
fix #4717
[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 "BufferView.h"
20 #include "DispatchResult.h"
21 #include "FuncRequest.h"
22 #include "FuncStatus.h"
23 #include "Cursor.h"
24 #include "support/gettext.h"
25 #include "LaTeXFeatures.h"
26 #include "Lexer.h"
27 #include "Text.h"
28 #include "MetricsInfo.h"
29 #include "Paragraph.h"
30 #include "paragraph_funcs.h"
31 #include "sgml.h"
32
33 #include "support/convert.h"
34
35 #include <sstream>
36
37 using namespace std;
38
39 namespace lyx {
40
41
42 InsetFlex::InsetFlex(Buffer const & buf, string const & layoutName)
43         : InsetCollapsable(buf, Collapsed), name_(layoutName)
44 {
45         // again, because now the name is initialized
46         setLayout(buf.params().documentClassPtr());
47         packages_ = getLayout().requires();
48         preamble_ = getLayout().preamble();
49 }
50
51
52 InsetFlex::InsetFlex(InsetFlex const & in)
53         : InsetCollapsable(in), name_(in.name_)
54 {}
55
56
57 docstring InsetFlex::editMessage() const
58 {
59         return _("Opened Flex Inset");
60 }
61
62
63 void InsetFlex::write(ostream & os) const
64 {
65         os << "Flex " <<
66                 (name_.empty() ? "undefined" : name_) << "\n";
67         InsetCollapsable::write(os);
68 }
69
70
71 void InsetFlex::read(Lexer & lex)
72 {
73         string token;
74         while (lex.isOK()) {
75                 lex >> token;
76                 if (token == "Flex") {
77                         lex.next();
78                         name_ = lex.getString();
79                 } else if (token == "status") {
80                         // This is handled in Collapsable
81                         lex.pushToken(token);
82                         break;
83                 }
84         }
85         InsetCollapsable::read(lex);
86 }
87
88
89 int InsetFlex::plaintext(odocstream & os, OutputParams const & runparams) const
90 {
91         return InsetText::plaintext(os, runparams);
92 }
93
94
95 int InsetFlex::docbook(odocstream & os, OutputParams const & runparams) const
96 {
97         ParagraphList::const_iterator beg = paragraphs().begin();
98         ParagraphList::const_iterator par = paragraphs().begin();
99         ParagraphList::const_iterator end = paragraphs().end();
100
101         if (!undefined())
102                 sgml::openTag(os, getLayout().latexname(),
103                               par->getID(buffer(), runparams) + getLayout().latexparam());
104
105         for (; par != end; ++par) {
106                 par->simpleDocBookOnePar(buffer(), os, runparams,
107                                          outerFont(distance(beg, par),
108                                                    paragraphs()));
109         }
110
111         if (!undefined())
112                 sgml::closeTag(os, getLayout().latexname());
113
114         return 0;
115 }
116
117
118 void InsetFlex::textString(odocstream & os) const
119 {
120         os << paragraphs().begin()->asString(true);
121 }
122
123
124 void InsetFlex::validate(LaTeXFeatures & features) const
125 {
126         if (!preamble_.empty())
127                 features.addPreambleSnippet(preamble_);
128         features.require(packages_);
129 }
130
131 } // namespace lyx