]> git.lyx.org Git - lyx.git/blob - src/insets/InsetFlex.cpp
605d93db1d69582d7683c31659bd8989359775ad
[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 "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 using namespace std;
40
41 namespace lyx {
42
43
44 InsetFlex::InsetFlex(BufferParams const & bp,
45                                 InsetLayout const & il)
46         : InsetCollapsable(bp, Collapsed, &il)
47 {
48         name_ = il.name;
49 }
50
51
52 InsetFlex::InsetFlex(InsetFlex const & in)
53         : InsetCollapsable(in), name_(in.name_)
54 {}
55
56
57 Inset * InsetFlex::clone() const
58 {
59         return new InsetFlex(*this);
60 }
61
62
63 bool InsetFlex::undefined() const
64 {
65         return layout_->labelstring == from_utf8("UNDEFINED");
66 }
67
68
69 docstring const InsetFlex::editMessage() const
70 {
71         return _("Opened Flex Inset");
72 }
73
74
75 void InsetFlex::write(Buffer const & buf, ostream & os) const
76 {
77         os << "Flex " << name_ << "\n";
78         InsetCollapsable::write(buf, os);
79 }
80
81
82 void InsetFlex::read(Buffer const & buf, Lexer & lex)
83 {
84         while (lex.isOK()) {
85                 lex.next();
86                 string token = lex.getString();
87
88                 if (token == "Flex") {
89                         lex.next();
90                         name_ = lex.getString();
91                 }
92
93                 // This is handled in Collapsable
94                 else if (token == "status") {
95                         lex.pushToken(token);
96                         break;
97                 }
98         }
99         InsetCollapsable::read(buf, lex);
100 }
101
102
103 int InsetFlex::plaintext(Buffer const & buf, odocstream & os,
104                               OutputParams const & runparams) const
105 {
106         return InsetText::plaintext(buf, os, runparams);
107 }
108
109
110 int InsetFlex::docbook(Buffer const & buf, odocstream & os,
111                             OutputParams const & runparams) const
112 {
113         ParagraphList::const_iterator beg = paragraphs().begin();
114         ParagraphList::const_iterator par = paragraphs().begin();
115         ParagraphList::const_iterator end = paragraphs().end();
116
117         if (!undefined())
118                 sgml::openTag(os, layout_->latexname,
119                               par->getID(buf, runparams) + layout_->latexparam);
120
121         for (; par != end; ++par) {
122                 par->simpleDocBookOnePar(buf, os, runparams,
123                                          outerFont(distance(beg, par),
124                                                    paragraphs()));
125         }
126
127         if (!undefined())
128                 sgml::closeTag(os, layout_->latexname);
129
130         return 0;
131 }
132
133
134 void InsetFlex::textString(Buffer const & buf, odocstream & os) const
135 {
136         os << paragraphs().begin()->asString(buf, true);
137 }
138
139 } // namespace lyx