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