2 * \file insetcharstyle.C
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 "insetcharstyle.h"
17 #include "BufferView.h"
18 #include "dispatchresult.h"
19 #include "funcrequest.h"
21 #include "LaTeXFeatures.h"
25 #include "metricsinfo.h"
26 #include "paragraph.h"
28 #include "support/std_sstream.h"
33 using std::istringstream;
35 using std::ostringstream;
38 void InsetCharStyle::init()
40 setInsetName("CharStyle");
45 InsetCharStyle::InsetCharStyle(BufferParams const & bp,
46 CharStyles::iterator cs)
47 : InsetCollapsable(bp)
49 params_.type = cs->name;
50 params_.latextype = cs->latextype;
51 params_.latexname = cs->latexname;
52 params_.latexparam = cs->latexparam;
53 params_.font = cs->font;
54 params_.labelfont = cs->labelfont;
59 InsetCharStyle::InsetCharStyle(InsetCharStyle const & in)
60 : InsetCollapsable(in), params_(in.params_)
66 auto_ptr<InsetBase> InsetCharStyle::clone() const
68 return auto_ptr<InsetBase>(new InsetCharStyle(*this));
72 string const InsetCharStyle::editMessage() const
74 return _("Opened CharStyle Inset");
78 void InsetCharStyle::write(Buffer const & buf, ostream & os) const
81 InsetCollapsable::write(buf, os);
85 void InsetCharStyle::read(Buffer const & buf, LyXLex & lex)
87 InsetCollapsable::read(buf, lex);
92 void InsetCharStyle::setButtonLabel()
94 LyXFont font(params_.labelfont);
95 font.realize(LyXFont(LyXFont::ALL_SANE));
96 string const s = "Style: " + params_.type;
97 setLabel(isOpen() ? s : getNewLabel(s) );
102 void InsetCharStyle::metrics(MetricsInfo & mi, Dimension & dim) const
104 InsetCollapsable::metrics(mi, dim);
109 void InsetCharStyle::getDrawFont(LyXFont & font) const
116 InsetCharStyle::priv_dispatch(FuncRequest const & cmd,
117 idx_type & idx, pos_type & pos)
119 DispatchResult dr = InsetCollapsable::priv_dispatch(cmd, idx, pos);
127 int outputVerbatim(std::ostream & os, InsetText inset)
130 ParagraphList::iterator par = inset.paragraphs().begin();
131 ParagraphList::iterator end = inset.paragraphs().end();
133 lyx::pos_type siz = par->size();
134 for (lyx::pos_type i = 0; i < siz; ++i) {
135 if (par->isNewline(i)) {
139 os << par->getChar(i);
154 int InsetCharStyle::latex(Buffer const &, ostream & os,
155 OutputParams const &) const
157 os << "%\n\\" << params_.latexname;
158 if (!params_.latexparam.empty())
159 os << params_.latexparam;
161 int i = outputVerbatim(os, inset);
168 int InsetCharStyle::linuxdoc(Buffer const &, std::ostream & os,
169 OutputParams const &) const
171 os << "<" << params_.latexname;
172 if (!params_.latexparam.empty())
173 os << " " << params_.latexparam;
175 int const i = outputVerbatim(os, inset);
176 os << "</" << params_.latexname << ">";
181 int InsetCharStyle::docbook(Buffer const &, std::ostream & os,
182 OutputParams const &) const
184 os << "<" << params_.latexname;
185 if (!params_.latexparam.empty())
186 os << " " << params_.latexparam;
188 int const i = outputVerbatim(os, inset);
189 os << "</" << params_.latexname << ">";
194 int InsetCharStyle::plaintext(Buffer const &, std::ostream & os,
195 OutputParams const & runparams) const
197 return outputVerbatim(os, inset);
201 void InsetCharStyle::validate(LaTeXFeatures & features) const
203 features.require(params_.type);
207 void InsetCharStyleParams::write(ostream & os) const
209 os << "CharStyle " << type << "\n";
213 void InsetCharStyleParams::read(LyXLex & lex)
217 string token = lex.getString();
222 type = lex.getString();