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 "frontends/font_metrics.h"
29 #include "frontends/Painter.h"
36 using std::istringstream;
38 using std::ostringstream;
41 void InsetCharStyle::init()
43 setInsetName("CharStyle");
48 InsetCharStyle::InsetCharStyle(BufferParams const & bp,
49 CharStyles::iterator cs)
50 : InsetCollapsable(bp), has_label_(true)
52 params_.type = cs->name;
53 params_.latextype = cs->latextype;
54 params_.latexname = cs->latexname;
55 params_.latexparam = cs->latexparam;
56 params_.font = cs->font;
57 params_.labelfont = cs->labelfont;
62 InsetCharStyle::InsetCharStyle(InsetCharStyle const & in)
63 : InsetCollapsable(in), params_(in.params_), has_label_(true)
69 auto_ptr<InsetBase> InsetCharStyle::clone() const
71 return auto_ptr<InsetBase>(new InsetCharStyle(*this));
75 string const InsetCharStyle::editMessage() const
77 return _("Opened CharStyle Inset");
81 void InsetCharStyle::write(Buffer const & buf, ostream & os) const
84 InsetCollapsable::write(buf, os);
88 void InsetCharStyle::read(Buffer const & buf, LyXLex & lex)
90 InsetCollapsable::read(buf, lex);
95 void InsetCharStyle::metrics(MetricsInfo & mi, Dimension & dim) const
97 LyXFont tmpfont = mi.base.font;
98 getDrawFont(mi.base.font);
99 InsetCollapsable::metrics(mi, dim);
100 mi.base.font = tmpfont;
103 dim_.des += ascent();
107 void InsetCharStyle::draw(PainterInfo & pi, int x, int y) const
109 setPosCache(pi, x, y);
111 // FIXME: setStatus(Inlined); this is not a const operation
112 LyXFont tmpfont = pi.base.font;
113 //setDrawFrame(InsetText::NEVER);
114 getDrawFont(pi.base.font);
115 InsetText::draw(pi, x, y);
116 pi.base.font = tmpfont;
118 pi.pain.line(x + 2, y + InsetText::descent() - 4, x + 2,
119 y + InsetText::descent(), params_.labelfont.color());
120 pi.pain.line(x + 2, y + InsetText::descent(), x + dim_.wid - 2,
121 y + InsetText::descent(), params_.labelfont.color());
122 pi.pain.line(x + dim_.wid - 2, y + InsetText::descent(), x + dim_.wid - 2,
123 y + InsetText::descent() - 4, params_.labelfont.color());
126 LyXFont font(params_.labelfont);
127 font.realize(LyXFont(LyXFont::ALL_SANE));
133 font_metrics::rectText(params_.type, font, w, a, d);
134 pi.pain.rectText(x + (dim_.wid - w) / 2,
135 y + InsetText::descent() + a,
136 params_.type, font, LColor::none, LColor::none);
141 void InsetCharStyle::getDrawFont(LyXFont & font) const
147 void InsetCharStyle::priv_dispatch(LCursor & cur, FuncRequest & cmd)
150 switch (cmd.action) {
151 case LFUN_MOUSE_PRESS:
152 if (cmd.button() == mouse_button::button3)
153 has_label_ = !has_label_;
155 InsetText::dispatch(cur, cmd);
159 InsetCollapsable::priv_dispatch(cur, cmd);
167 int outputVerbatim(std::ostream & os, InsetText const & inset)
170 ParagraphList::const_iterator par = inset.paragraphs().begin();
171 ParagraphList::const_iterator end = inset.paragraphs().end();
173 lyx::pos_type siz = par->size();
174 for (lyx::pos_type i = 0; i < siz; ++i) {
175 if (par->isNewline(i)) {
179 os << par->getChar(i);
194 int InsetCharStyle::latex(Buffer const &, ostream & os,
195 OutputParams const &) const
197 os << "%\n\\" << params_.latexname;
198 if (!params_.latexparam.empty())
199 os << params_.latexparam;
201 int i = outputVerbatim(os, *this);
208 int InsetCharStyle::linuxdoc(Buffer const &, std::ostream & os,
209 OutputParams const &) const
211 os << "<" << params_.latexname;
212 if (!params_.latexparam.empty())
213 os << " " << params_.latexparam;
215 int const i = outputVerbatim(os, *this);
216 os << "</" << params_.latexname << ">";
221 int InsetCharStyle::docbook(Buffer const &, std::ostream & os,
222 OutputParams const &) const
224 os << "<" << params_.latexname;
225 if (!params_.latexparam.empty())
226 os << " " << params_.latexparam;
228 int const i = outputVerbatim(os, *this);
229 os << "</" << params_.latexname << ">";
234 int InsetCharStyle::plaintext(Buffer const &, std::ostream & os,
235 OutputParams const & /*runparams*/) const
237 return outputVerbatim(os, *this);
241 void InsetCharStyle::validate(LaTeXFeatures & features) const
243 features.require(params_.type);
247 void InsetCharStyleParams::write(ostream & os) const
249 os << "CharStyle " << type << "\n";
253 void InsetCharStyleParams::read(LyXLex & lex)
257 string token = lex.getString();
262 type = lex.getString();