]> git.lyx.org Git - lyx.git/blob - src/insets/InsetFlex.cpp
pimpl not needed here
[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 "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 il)
48         : InsetCollapsable(bp, Collapsed)
49 {
50         params_.name = il.name;
51         setLayout(il);
52 }
53
54
55 InsetFlex::InsetFlex(InsetFlex const & in)
56         : InsetCollapsable(in), params_(in.params_)
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 void InsetFlex::setLayout(InsetLayout il)
73 {
74         layout_ = il;
75 }
76
77
78 docstring const InsetFlex::editMessage() const
79 {
80         return _("Opened Flex Inset");
81 }
82
83
84 void InsetFlex::write(Buffer const & buf, ostream & os) const
85 {
86         params_.write(os);
87         InsetCollapsable::write(buf, os);
88 }
89
90
91 void InsetFlex::read(Buffer const & buf, Lexer & lex)
92 {
93         params_.read(lex);
94         InsetCollapsable::read(buf, lex);
95 }
96
97
98 int InsetFlex::plaintext(Buffer const & buf, odocstream & os,
99                               OutputParams const & runparams) const
100 {
101         return InsetText::plaintext(buf, os, runparams);
102 }
103
104
105 int InsetFlex::docbook(Buffer const & buf, odocstream & os,
106                             OutputParams const & runparams) const
107 {
108         ParagraphList::const_iterator beg = paragraphs().begin();
109         ParagraphList::const_iterator par = paragraphs().begin();
110         ParagraphList::const_iterator end = paragraphs().end();
111
112         if (!undefined())
113                 // FIXME UNICODE
114                 sgml::openTag(os, layout_.latexname,
115                               par->getID(buf, runparams) + layout_.latexparam);
116
117         for (; par != end; ++par) {
118                 par->simpleDocBookOnePar(buf, os, runparams,
119                                          outerFont(std::distance(beg, par),
120                                                    paragraphs()));
121         }
122
123         if (!undefined())
124                 sgml::closeTag(os, layout_.latexname);
125
126         return 0;
127 }
128
129
130 void InsetFlex::textString(Buffer const & buf, odocstream & os) const
131 {
132         os << paragraphs().begin()->asString(buf, true);
133 }
134
135
136 void InsetFlexParams::write(ostream & os) const
137 {
138         os << "Flex " << name << "\n";
139 }
140
141
142 void InsetFlexParams::read(Lexer & lex)
143 {
144         while (lex.isOK()) {
145                 lex.next();
146                 string token = lex.getString();
147
148                 if (token == "Flex") {
149                         lex.next();
150                         name = lex.getString();
151                 }
152
153                 // This is handled in Collapsable
154                 else if (token == "status") {
155                         lex.pushToken(token);
156                         break;
157                 }
158         }
159 }
160
161
162 } // namespace lyx