3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Angus Leeming
7 * \author Martin Vermeer
8 * \author Jürgen Spitzmüller
10 * Full author contact details are available in file CREDITS.
15 #include "InsetFlex.h"
18 #include "BufferParams.h"
19 #include "BufferView.h"
20 #include "DispatchResult.h"
21 #include "FuncRequest.h"
22 #include "FuncStatus.h"
28 #include "MetricsInfo.h"
29 #include "Paragraph.h"
30 #include "paragraph_funcs.h"
33 #include "frontends/FontMetrics.h"
34 #include "frontends/Painter.h"
36 #include "support/convert.h"
47 InsetFlex::InsetFlex(BufferParams const & bp,
49 : InsetCollapsable(bp, Collapsed)
51 params_.name = il.name;
56 InsetFlex::InsetFlex(InsetFlex const & in)
57 : InsetCollapsable(in), params_(in.params_)
61 Inset * InsetFlex::clone() const
63 return new InsetFlex(*this);
67 bool InsetFlex::undefined() const
69 return layout_.labelstring == from_utf8("UNDEFINED");
73 void InsetFlex::setLayout(InsetLayout il)
79 docstring const InsetFlex::editMessage() const
81 return _("Opened CharStyle Inset");
85 void InsetFlex::write(Buffer const & buf, ostream & os) const
88 InsetCollapsable::write(buf, os);
92 void InsetFlex::read(Buffer const & buf, Lexer & lex)
95 InsetCollapsable::read(buf, lex);
99 bool InsetFlex::metrics(MetricsInfo & mi, Dimension & dim) const
101 Font tmpfont = mi.base.font;
102 getDrawFont(mi.base.font);
103 mi.base.font.reduce(Font(Font::ALL_SANE));
104 mi.base.font.realize(tmpfont);
105 bool changed = InsetCollapsable::metrics(mi, dim);
106 mi.base.font = tmpfont;
111 void InsetFlex::draw(PainterInfo & pi, int x, int y) const
113 setPosCache(pi, x, y);
115 Font tmpfont = pi.base.font;
116 getDrawFont(pi.base.font);
117 // I don't understand why the above .reduce and .realize aren't
118 //needed, or even wanted, here. It just works. -- MV 10.04.2005
119 InsetCollapsable::draw(pi, x, y);
120 pi.base.font = tmpfont;
124 void InsetFlex::getDrawFont(Font & font) const
130 void InsetFlex::doDispatch(Cursor & cur, FuncRequest & cmd)
132 InsetCollapsable::doDispatch(cur, cmd);
136 bool InsetFlex::getStatus(Cursor & cur, FuncRequest const & cmd,
137 FuncStatus & status) const
139 switch (cmd.action) {
140 // paragraph breaks not allowed in charstyle insets
141 case LFUN_BREAK_PARAGRAPH:
142 case LFUN_BREAK_PARAGRAPH_KEEP_LAYOUT:
143 case LFUN_BREAK_PARAGRAPH_SKIP:
144 status.enabled(false);
148 return InsetCollapsable::getStatus(cur, cmd, status);
153 int InsetFlex::plaintext(Buffer const & buf, odocstream & os,
154 OutputParams const & runparams) const
156 return InsetText::plaintext(buf, os, runparams);
160 int InsetFlex::docbook(Buffer const & buf, odocstream & os,
161 OutputParams const & runparams) const
163 ParagraphList::const_iterator beg = paragraphs().begin();
164 ParagraphList::const_iterator par = paragraphs().begin();
165 ParagraphList::const_iterator end = paragraphs().end();
169 sgml::openTag(os, layout_.latexname,
170 par->getID(buf, runparams) + layout_.latexparam);
172 for (; par != end; ++par) {
173 par->simpleDocBookOnePar(buf, os, runparams,
174 outerFont(std::distance(beg, par),
179 sgml::closeTag(os, layout_.latexname);
185 void InsetFlex::textString(Buffer const & buf, odocstream & os) const
187 os << paragraphs().begin()->asString(buf, true);
191 void InsetFlexParams::write(ostream & os) const
193 os << "CharStyle " << name << "\n";
197 void InsetFlexParams::read(Lexer & lex)
201 string token = lex.getString();
203 if (token == "CharStyle") {
205 name = lex.getString();
208 // This is handled in Collapsable
209 else if (token == "status") {
210 lex.pushToken(token);