2 * \file InsetSeparator.cpp
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Enrico Forestieri
8 * Full author contact details are available in file CREDITS.
13 #include "InsetSeparator.h"
16 #include "Dimension.h"
17 #include "FuncRequest.h"
18 #include "FuncStatus.h"
20 #include "MetricsInfo.h"
21 #include "OutputParams.h"
22 #include "output_xhtml.h"
24 #include "frontends/Application.h"
25 #include "frontends/FontMetrics.h"
26 #include "frontends/Painter.h"
28 #include "support/debug.h"
29 #include "support/docstream.h"
30 #include "support/docstring.h"
36 InsetSeparator::InsetSeparator() : Inset(0)
40 InsetSeparator::InsetSeparator(InsetSeparatorParams const & params)
41 : Inset(0), params_(params)
45 void InsetSeparatorParams::write(ostream & os) const
49 case InsetSeparatorParams::PLAIN:
52 case InsetSeparatorParams::PARBREAK:
59 void InsetSeparatorParams::read(Lexer & lex)
62 lex.setContext("InsetSeparatorParams::read");
65 kind = InsetSeparatorParams::PLAIN;
66 else if (token == "parbreak")
67 kind = InsetSeparatorParams::PARBREAK;
69 lex.printError("Unknown kind: `$$Token'");
73 void InsetSeparator::write(ostream & os) const
80 void InsetSeparator::read(Lexer & lex)
87 void InsetSeparator::doDispatch(Cursor & cur, FuncRequest & cmd)
89 switch (cmd.action()) {
91 case LFUN_INSET_MODIFY: {
92 InsetSeparatorParams params;
94 string2params(to_utf8(cmd.argument()), params);
95 params_.kind = params.kind;
100 Inset::doDispatch(cur, cmd);
106 bool InsetSeparator::getStatus(Cursor & cur, FuncRequest const & cmd,
107 FuncStatus & status) const
109 switch (cmd.action()) {
111 case LFUN_INSET_MODIFY:
112 if (cmd.getArg(0) == "plain") {
113 InsetSeparatorParams params;
114 string2params(to_utf8(cmd.argument()), params);
115 status.setOnOff(params_.kind == params.kind);
117 status.setEnabled(true);
120 return Inset::getStatus(cur, cmd, status);
125 ColorCode InsetSeparator::ColorName() const
127 switch (params_.kind) {
128 case InsetSeparatorParams::PLAIN:
131 case InsetSeparatorParams::PARBREAK:
132 return Color_pagebreak;
135 // not really useful, but to avoids gcc complaints
140 void InsetSeparator::latex(otexstream & os, OutputParams const & rp) const
142 switch (params_.kind) {
143 case InsetSeparatorParams::PLAIN:
144 os << breakln << "%\n";
146 case InsetSeparatorParams::PARBREAK:
147 os << breakln << "\n";
150 os << breakln << "%\n";
156 int InsetSeparator::plaintext(odocstringstream & os,
157 OutputParams const &, size_t) const
160 return PLAINTEXT_NEWLINE;
164 int InsetSeparator::docbook(odocstream & os, OutputParams const &) const
171 docstring InsetSeparator::xhtml(XHTMLStream & xs, OutputParams const &) const
173 xs << html::CR() << html::CompTag("br") << html::CR();
178 void InsetSeparator::metrics(MetricsInfo & mi, Dimension & dim) const
180 frontend::FontMetrics const & fm = theFontMetrics(mi.base.font);
181 dim.asc = fm.maxAscent();
182 dim.des = fm.maxDescent();
183 dim.wid = fm.width('m');
184 if (params_.kind == InsetSeparatorParams::PLAIN)
189 void InsetSeparator::draw(PainterInfo & pi, int x, int y) const
192 font.setColor(ColorName());
194 frontend::FontMetrics const & fm = theFontMetrics(pi.base.font);
195 int const wid = fm.width('m');
196 int const asc = fm.maxAscent();
201 if (params_.kind == InsetSeparatorParams::PLAIN) {
202 yp[0] = int(y - 0.500 * asc * 0.75);
203 yp[1] = int(y - 0.500 * asc * 0.75);
206 xp[1] = int(x + wid * 5);
208 pi.pain.lines(xp, yp, 2, ColorName());
210 yp[0] = int(y - 0.875 * asc * 0.75);
211 yp[1] = int(y - 0.500 * asc * 0.75);
212 yp[2] = int(y - 0.125 * asc * 0.75);
215 xp[0] = int(x + wid * 0.375);
217 xp[2] = int(x + wid * 0.375);
219 xp[0] = int(x + wid * 0.625);
220 xp[1] = int(x + wid);
221 xp[2] = int(x + wid * 0.625);
224 pi.pain.lines(xp, yp, 3, ColorName());
226 yp[0] = int(y - 0.500 * asc * 0.75);
227 yp[1] = int(y - 0.500 * asc * 0.75);
228 yp[2] = int(y - asc * 0.75);
232 xp[1] = int(x + wid);
233 xp[2] = int(x + wid);
235 xp[0] = int(x + wid);
240 pi.pain.lines(xp, yp, 3, ColorName());
245 string InsetSeparator::contextMenuName() const
247 return "context-separator";
251 void InsetSeparator::string2params(string const & in, InsetSeparatorParams & params)
253 params = InsetSeparatorParams();
256 istringstream data(in);
259 lex.setContext("InsetSeparator::string2params");
265 string InsetSeparator::params2string(InsetSeparatorParams const & params)
268 data << "separator" << ' ';