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