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"
27 #include "paragraph_funcs.h"
30 #include "frontends/font_metrics.h"
31 #include "frontends/Painter.h"
38 using std::istringstream;
40 using std::ostringstream;
43 void InsetCharStyle::init()
45 setInsetName("CharStyle");
52 InsetCharStyle::InsetCharStyle(BufferParams const & bp,
53 CharStyles::iterator cs)
54 : InsetCollapsable(bp)
56 params_.type = cs->name;
57 params_.latextype = cs->latextype;
58 params_.latexname = cs->latexname;
59 params_.latexparam = cs->latexparam;
60 params_.font = cs->font;
61 params_.labelfont = cs->labelfont;
66 InsetCharStyle::InsetCharStyle(InsetCharStyle const & in)
67 : InsetCollapsable(in), params_(in.params_)
73 auto_ptr<InsetBase> InsetCharStyle::clone() const
75 return auto_ptr<InsetBase>(new InsetCharStyle(*this));
79 string const InsetCharStyle::editMessage() const
81 return _("Opened CharStyle Inset");
85 void InsetCharStyle::write(Buffer const & buf, ostream & os) const
88 InsetCollapsable::write(buf, os);
92 void InsetCharStyle::read(Buffer const & buf, LyXLex & lex)
94 InsetCollapsable::read(buf, lex);
99 void InsetCharStyle::metrics(MetricsInfo & mi, Dimension & dim) const
101 LyXFont tmpfont = mi.base.font;
102 getDrawFont(mi.base.font);
103 InsetText::metrics(mi, dim);
104 mi.base.font = tmpfont;
107 dim_.des += ascent();
111 void InsetCharStyle::draw(PainterInfo & pi, int x, int y) const
113 setPosCache(pi, x, y);
115 LyXFont tmpfont = pi.base.font;
116 getDrawFont(pi.base.font);
117 InsetText::draw(pi, x, y);
118 pi.base.font = tmpfont;
120 int desc = InsetText::descent();
124 pi.pain.line(x, y + desc - 4, x, y + desc, params_.labelfont.color());
125 pi.pain.line(x, y + desc, x + dim_.wid - 2, y + desc,
126 params_.labelfont.color());
127 pi.pain.line(x + dim_.wid - 2, y + desc, x + dim_.wid - 2, y + desc - 4,
128 params_.labelfont.color());
131 LyXFont font(params_.labelfont);
132 font.realize(LyXFont(LyXFont::ALL_SANE));
138 font_metrics::rectText(params_.type, font, w, a, d);
139 pi.pain.rectText(x + (dim_.wid - w) / 2, y + desc + a,
140 params_.type, font, LColor::none, LColor::none);
145 void InsetCharStyle::getDrawFont(LyXFont & font) const
151 void InsetCharStyle::priv_dispatch(LCursor & cur, FuncRequest & cmd)
154 switch (cmd.action) {
155 case LFUN_MOUSE_PRESS:
156 if (cmd.button() == mouse_button::button3)
157 has_label_ = !has_label_;
159 InsetText::priv_dispatch(cur, cmd);
163 InsetCollapsable::priv_dispatch(cur, cmd);
169 int InsetCharStyle::latex(Buffer const & buf, ostream & os,
170 OutputParams const & runparams) const
172 os << "\\" << params_.latexname;
173 if (!params_.latexparam.empty())
174 os << params_.latexparam;
176 int i = InsetText::latex(buf, os, runparams);
182 int InsetCharStyle::linuxdoc(Buffer const & buf, ostream & os,
183 OutputParams const & runparams) const
185 sgml::openTag(os, params_.latexname, params_.latexparam);
186 int i = InsetText::linuxdoc(buf, os, runparams);
187 sgml::closeTag(os, params_.latexname);
192 int InsetCharStyle::docbook(Buffer const & buf, ostream & os,
193 OutputParams const & runparams) const
195 ParagraphList::const_iterator par = paragraphs().begin();
196 ParagraphList::const_iterator end = paragraphs().end();
198 sgml::openTag(os, params_.latexname, par->getID() + params_.latexparam);
200 for (; par != end; ++par) {
201 par->simpleDocBookOnePar(buf, os, runparams,
202 outerFont(par - paragraphs().begin(),
206 sgml::closeTag(os, params_.latexname);
211 int InsetCharStyle::plaintext(Buffer const & buf, ostream & os,
212 OutputParams const & runparams) const
214 return InsetText::plaintext(buf, os, runparams);
218 void InsetCharStyle::validate(LaTeXFeatures & features) const
220 features.require(params_.type);
224 void InsetCharStyleParams::write(ostream & os) const
226 os << "CharStyle " << type << "\n";
230 void InsetCharStyleParams::read(LyXLex & lex)
234 string token = lex.getString();
239 type = lex.getString();