]> git.lyx.org Git - lyx.git/blob - src/insets/InsetFlex.cpp
bb59337a16da0e2fde4247b6ee783dc5ecccad38
[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 "frontends/FontMetrics.h"
34 #include "frontends/Painter.h"
35
36 #include "support/convert.h"
37
38 #include <sstream>
39
40 using namespace std;
41
42 namespace lyx {
43
44
45 InsetFlex::InsetFlex(BufferParams const & bp,
46         TextClassPtr tc, string const & layoutName)
47         : InsetCollapsable(bp, Collapsed, tc),
48         name_(layoutName)
49 {
50         setLayout(tc); // again, because now the name is initialized
51         packages_ = getLayout().requires;
52         preamble_ = getLayout().preamble;
53 }
54
55
56 InsetFlex::InsetFlex(InsetFlex const & in)
57         : InsetCollapsable(in), name_(in.name_)
58 {}
59
60
61 Inset * InsetFlex::clone() const
62 {
63         return new InsetFlex(*this);
64 }
65
66
67 bool InsetFlex::undefined() const
68 {
69         return getLayout().labelstring == from_utf8("UNDEFINED");
70 }
71
72
73 docstring const InsetFlex::editMessage() const
74 {
75         return _("Opened Flex Inset");
76 }
77
78
79 void InsetFlex::write(Buffer const & buf, ostream & os) const
80 {
81         os << "Flex " <<
82                 (name_.empty() ? "undefined" : name_) << "\n";
83         InsetCollapsable::write(buf, os);
84 }
85
86
87 void InsetFlex::read(Buffer const & buf, Lexer & lex)
88 {
89         while (lex.isOK()) {
90                 lex.next();
91                 string token = lex.getString();
92
93                 if (token == "Flex") {
94                         lex.next();
95                         name_ = lex.getString();
96                 }
97
98                 // This is handled in Collapsable
99                 else if (token == "status") {
100                         lex.pushToken(token);
101                         break;
102                 }
103         }
104         InsetCollapsable::read(buf, lex);
105 }
106
107
108 int InsetFlex::plaintext(Buffer const & buf, odocstream & os,
109                               OutputParams const & runparams) const
110 {
111         return InsetText::plaintext(buf, os, runparams);
112 }
113
114
115 int InsetFlex::docbook(Buffer const & buf, odocstream & os,
116                             OutputParams const & runparams) const
117 {
118         ParagraphList::const_iterator beg = paragraphs().begin();
119         ParagraphList::const_iterator par = paragraphs().begin();
120         ParagraphList::const_iterator end = paragraphs().end();
121
122         if (!undefined())
123                 sgml::openTag(os, getLayout().latexname,
124                               par->getID(buf, runparams) + getLayout().latexparam);
125
126         for (; par != end; ++par) {
127                 par->simpleDocBookOnePar(buf, os, runparams,
128                                          outerFont(distance(beg, par),
129                                                    paragraphs()));
130         }
131
132         if (!undefined())
133                 sgml::closeTag(os, getLayout().latexname);
134
135         return 0;
136 }
137
138
139 void InsetFlex::textString(Buffer const & buf, odocstream & os) const
140 {
141         os << paragraphs().begin()->asString(buf, true);
142 }
143
144
145 void InsetFlex::validate(LaTeXFeatures & features) const
146 {
147         if (!preamble_.empty())
148                 features.addPreambleSnippet(preamble_);
149         features.require(packages_);
150 }
151
152 } // namespace lyx