]> git.lyx.org Git - lyx.git/blob - src/insets/InsetFlex.cpp
Andre's s/getTextClass/textClass/ cleanup.
[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 const InsetFlex::editMessage() const
65 {
66         return _("Opened Flex Inset");
67 }
68
69
70 void InsetFlex::write(Buffer const & buf, ostream & os) const
71 {
72         os << "Flex " <<
73                 (name_.empty() ? "undefined" : name_) << "\n";
74         InsetCollapsable::write(buf, os);
75 }
76
77
78 void InsetFlex::read(Buffer const & buf, 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(buf, lex);
96 }
97
98
99 int InsetFlex::plaintext(Buffer const & buf, odocstream & os,
100                               OutputParams const & runparams) const
101 {
102         return InsetText::plaintext(buf, os, runparams);
103 }
104
105
106 int InsetFlex::docbook(Buffer const & buf, odocstream & os,
107                             OutputParams const & runparams) const
108 {
109         ParagraphList::const_iterator beg = paragraphs().begin();
110         ParagraphList::const_iterator par = paragraphs().begin();
111         ParagraphList::const_iterator end = paragraphs().end();
112
113         if (!undefined())
114                 sgml::openTag(os, getLayout().latexname(),
115                               par->getID(buf, runparams) + getLayout().latexparam());
116
117         for (; par != end; ++par) {
118                 par->simpleDocBookOnePar(buf, os, runparams,
119                                          outerFont(distance(beg, par),
120                                                    paragraphs()));
121         }
122
123         if (!undefined())
124                 sgml::closeTag(os, getLayout().latexname());
125
126         return 0;
127 }
128
129
130 void InsetFlex::textString(Buffer const & buf, odocstream & os) const
131 {
132         os << paragraphs().begin()->asString(buf, true);
133 }
134
135
136 void InsetFlex::validate(LaTeXFeatures & features) const
137 {
138         if (!preamble_.empty())
139                 features.addPreambleSnippet(preamble_);
140         features.require(packages_);
141 }
142
143 } // namespace lyx