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);
162 // paragraph breaks not allowed in charstyle insets!
163 case LFUN_BREAKPARAGRAPH:
164 case LFUN_BREAKPARAGRAPHKEEPLAYOUT:
165 case LFUN_BREAKPARAGRAPH_SKIP:
169 InsetCollapsable::priv_dispatch(cur, cmd);
175 int InsetCharStyle::latex(Buffer const & buf, ostream & os,
176 OutputParams const & runparams) const
178 os << "\\" << params_.latexname;
179 if (!params_.latexparam.empty())
180 os << params_.latexparam;
182 int i = InsetText::latex(buf, os, runparams);
188 int InsetCharStyle::linuxdoc(Buffer const & buf, ostream & os,
189 OutputParams const & runparams) const
191 sgml::openTag(os, params_.latexname, params_.latexparam);
192 int i = InsetText::linuxdoc(buf, os, runparams);
193 sgml::closeTag(os, params_.latexname);
198 int InsetCharStyle::docbook(Buffer const & buf, ostream & os,
199 OutputParams const & runparams) const
201 ParagraphList::const_iterator par = paragraphs().begin();
202 ParagraphList::const_iterator end = paragraphs().end();
204 sgml::openTag(os, params_.latexname, par->getID(buf, runparams) + params_.latexparam);
206 for (; par != end; ++par) {
207 par->simpleDocBookOnePar(buf, os, runparams,
208 outerFont(par - paragraphs().begin(),
212 sgml::closeTag(os, params_.latexname);
217 int InsetCharStyle::plaintext(Buffer const & buf, ostream & os,
218 OutputParams const & runparams) const
220 return InsetText::plaintext(buf, os, runparams);
224 void InsetCharStyle::validate(LaTeXFeatures & features) const
226 features.require(params_.type);
230 void InsetCharStyleParams::write(ostream & os) const
232 os << "CharStyle " << type << "\n";
236 void InsetCharStyleParams::read(LyXLex & lex)
240 string token = lex.getString();
245 type = lex.getString();