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