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