]> git.lyx.org Git - lyx.git/blob - src/insets/InsetFlex.cpp
Change inset label from ": filename" to "Program Listing: filename" for listings...
[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 "support/gettext.h"
20 #include "LaTeXFeatures.h"
21 #include "Lexer.h"
22 #include "Text.h"
23 #include "MetricsInfo.h"
24 #include "Paragraph.h"
25 #include "paragraph_funcs.h"
26 #include "sgml.h"
27
28 #include <ostream>
29
30 using namespace std;
31
32 namespace lyx {
33
34
35 InsetFlex::InsetFlex(Buffer const & buf, string const & layoutName)
36         : InsetCollapsable(buf, Collapsed), name_(layoutName)
37 {
38         // again, because now the name is initialized
39         setLayout(buf.params().documentClassPtr());
40         packages_ = getLayout().requires();
41         preamble_ = getLayout().preamble();
42 }
43
44
45 InsetFlex::InsetFlex(InsetFlex const & in)
46         : InsetCollapsable(in), name_(in.name_)
47 {}
48
49
50 docstring InsetFlex::editMessage() const
51 {
52         return _("Opened Flex Inset");
53 }
54
55
56 void InsetFlex::write(ostream & os) const
57 {
58         os << "Flex " <<
59                 (name_.empty() ? "undefined" : name_) << "\n";
60         InsetCollapsable::write(os);
61 }
62
63
64 void InsetFlex::read(Lexer & lex)
65 {
66         string token;
67         while (lex.isOK()) {
68                 lex >> token;
69                 if (token == "Flex") {
70                         lex.next();
71                         name_ = lex.getString();
72                 } else if (token == "status") {
73                         // This is handled in Collapsable
74                         lex.pushToken(token);
75                         break;
76                 }
77         }
78         InsetCollapsable::read(lex);
79 }
80
81
82 int InsetFlex::plaintext(odocstream & os, OutputParams const & runparams) const
83 {
84         return InsetText::plaintext(os, runparams);
85 }
86
87
88 int InsetFlex::docbook(odocstream & os, OutputParams const & runparams) const
89 {
90         ParagraphList::const_iterator beg = paragraphs().begin();
91         ParagraphList::const_iterator par = paragraphs().begin();
92         ParagraphList::const_iterator end = paragraphs().end();
93
94         if (!undefined())
95                 sgml::openTag(os, getLayout().latexname(),
96                               par->getID(buffer(), runparams) + getLayout().latexparam());
97
98         for (; par != end; ++par) {
99                 par->simpleDocBookOnePar(buffer(), os, runparams,
100                                          outerFont(distance(beg, par),
101                                                    paragraphs()));
102         }
103
104         if (!undefined())
105                 sgml::closeTag(os, getLayout().latexname());
106
107         return 0;
108 }
109
110
111 void InsetFlex::textString(odocstream & os) const
112 {
113         os << paragraphs().begin()->asString(AS_STR_LABEL | AS_STR_INSETS);
114 }
115
116
117 void InsetFlex::validate(LaTeXFeatures & features) const
118 {
119         if (!preamble_.empty())
120                 features.addPreambleSnippet(preamble_);
121         features.require(packages_);
122 }
123
124 } // namespace lyx