2 * \file InsetNewline.cpp
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
7 * \author Jürgen Spitzmüller
9 * Full author contact details are available in file CREDITS.
14 #include "InsetNewline.h"
17 #include "Dimension.h"
18 #include "FuncRequest.h"
19 #include "FuncStatus.h"
21 #include "MetricsInfo.h"
22 #include "OutputParams.h"
23 #include "output_xhtml.h"
25 #include "frontends/Application.h"
26 #include "frontends/FontMetrics.h"
27 #include "frontends/Painter.h"
29 #include "support/debug.h"
30 #include "support/docstream.h"
31 #include "support/docstring.h"
37 InsetNewline::InsetNewline() : Inset(0)
41 void InsetNewlineParams::write(ostream & os) const
44 case InsetNewlineParams::NEWLINE:
47 case InsetNewlineParams::LINEBREAK:
54 void InsetNewlineParams::read(Lexer & lex)
57 lex.setContext("InsetNewlineParams::read");
59 if (token == "newline")
60 kind = InsetNewlineParams::NEWLINE;
61 else if (token == "linebreak")
62 kind = InsetNewlineParams::LINEBREAK;
64 lex.printError("Unknown kind: `$$Token'");
68 void InsetNewline::write(ostream & os) const
75 void InsetNewline::read(Lexer & lex)
82 void InsetNewline::metrics(MetricsInfo & mi, Dimension & dim) const
84 frontend::FontMetrics const & fm = theFontMetrics(mi.base.font);
85 dim.asc = fm.maxAscent();
86 dim.des = fm.maxDescent();
87 dim.wid = fm.width('n');
91 void InsetNewline::doDispatch(Cursor & cur, FuncRequest & cmd)
93 switch (cmd.action()) {
95 case LFUN_INSET_MODIFY: {
96 InsetNewlineParams params;
98 string2params(to_utf8(cmd.argument()), params);
99 params_.kind = params.kind;
104 Inset::doDispatch(cur, cmd);
110 bool InsetNewline::getStatus(Cursor & cur, FuncRequest const & cmd,
111 FuncStatus & status) const
113 switch (cmd.action()) {
115 case LFUN_INSET_MODIFY:
116 if (cmd.getArg(0) == "newline") {
117 InsetNewlineParams params;
118 string2params(to_utf8(cmd.argument()), params);
119 status.setOnOff(params_.kind == params.kind);
121 status.setEnabled(true);
124 return Inset::getStatus(cur, cmd, status);
129 ColorCode InsetNewline::ColorName() const
131 switch (params_.kind) {
132 case InsetNewlineParams::NEWLINE:
133 return Color_eolmarker;
135 case InsetNewlineParams::LINEBREAK:
136 return Color_pagebreak;
139 // not really useful, but to avoids gcc complaints
140 return Color_eolmarker;
144 void InsetNewline::latex(otexstream & os, OutputParams const & rp) const
146 switch (params_.kind) {
147 case InsetNewlineParams::NEWLINE:
148 if (rp.inTableCell == OutputParams::PLAIN)
153 case InsetNewlineParams::LINEBREAK:
154 os << "\\linebreak{}\n";
163 int InsetNewline::plaintext(odocstringstream & os,
164 OutputParams const &, size_t) const
167 return PLAINTEXT_NEWLINE;
171 int InsetNewline::docbook(odocstream & os, OutputParams const &) const
178 docstring InsetNewline::xhtml(XHTMLStream & xs, OutputParams const &) const
180 xs << html::CR() << html::CompTag("br") << html::CR();
185 void InsetNewline::draw(PainterInfo & pi, int x, int y) const
188 font.setColor(ColorName());
190 frontend::FontMetrics const & fm = theFontMetrics(pi.base.font);
191 int const wid = fm.width('n');
192 int const asc = fm.maxAscent();
197 yp[0] = int(y - 0.875 * asc * 0.75);
198 yp[1] = int(y - 0.500 * asc * 0.75);
199 yp[2] = int(y - 0.125 * asc * 0.75);
202 xp[0] = int(x + wid * 0.375);
204 xp[2] = int(x + wid * 0.375);
206 xp[0] = int(x + wid * 0.625);
207 xp[1] = int(x + wid);
208 xp[2] = int(x + wid * 0.625);
211 pi.pain.lines(xp, yp, 3, ColorName());
213 yp[0] = int(y - 0.500 * asc * 0.75);
214 yp[1] = int(y - 0.500 * asc * 0.75);
215 yp[2] = int(y - asc * 0.75);
219 xp[1] = int(x + wid);
220 xp[2] = int(x + wid);
222 xp[0] = int(x + wid);
227 pi.pain.lines(xp, yp, 3, ColorName());
229 if (params_.kind == InsetNewlineParams::LINEBREAK) {
231 yp[2] = int(y - 0.500 * asc * 0.75);
234 xp[0] = int(x + 1.3 * wid);
235 xp[1] = int(x + 2 * wid);
236 xp[2] = int(x + 2 * wid);
238 xp[0] = int(x - 0.3 * wid);
239 xp[1] = int(x - wid);
240 xp[2] = int(x - wid);
242 pi.pain.lines(xp, yp, 3, ColorName());
244 yp[0] = int(y - 0.875 * asc * 0.75);
245 yp[1] = int(y - 0.500 * asc * 0.75);
246 yp[2] = int(y - 0.125 * asc * 0.75);
249 xp[0] = int(x + 2 * wid * 0.813);
250 xp[1] = int(x + 2 * wid);
251 xp[2] = int(x + 2 * wid * 0.813);
253 xp[0] = int(x - wid * 0.625);
254 xp[1] = int(x - wid);
255 xp[2] = int(x - wid * 0.625);
257 pi.pain.lines(xp, yp, 3, ColorName());
262 string InsetNewline::contextMenuName() const
264 return "context-newline";
268 void InsetNewline::string2params(string const & in, InsetNewlineParams & params)
270 params = InsetNewlineParams();
273 istringstream data(in);
276 lex.setContext("InsetNewline::string2params");
282 string InsetNewline::params2string(InsetNewlineParams const & params)
285 data << "newline" << ' ';