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