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