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