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