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"
16 #include "Dimension.h"
17 #include "FuncRequest.h"
18 #include "FuncStatus.h"
20 #include "MetricsInfo.h"
21 #include "OutputParams.h"
23 #include "frontends/Application.h"
24 #include "frontends/FontMetrics.h"
25 #include "frontends/Painter.h"
27 #include "support/debug.h"
28 #include "support/docstream.h"
29 #include "support/docstring.h"
35 InsetNewline::InsetNewline()
39 void InsetNewlineParams::write(ostream & os) const
43 case InsetNewlineParams::NEWLINE:
46 case InsetNewlineParams::LINEBREAK:
53 void InsetNewlineParams::read(Lexer & lex)
56 lex.setContext("InsetNewlineParams::read");
58 if (token == "newline")
59 kind = InsetNewlineParams::NEWLINE;
60 else if (token == "linebreak")
61 kind = InsetNewlineParams::LINEBREAK;
63 lex.printError("Unknown kind: `$$Token'");
68 void InsetNewline::write(ostream & os) const
75 void InsetNewline::read(Lexer & lex)
81 void InsetNewline::metrics(MetricsInfo & mi, Dimension & dim) const
83 frontend::FontMetrics const & fm = theFontMetrics(mi.base.font);
84 dim.asc = fm.maxAscent();
85 dim.des = fm.maxDescent();
86 dim.wid = fm.width('n');
90 void InsetNewline::doDispatch(Cursor & cur, FuncRequest & cmd)
94 case LFUN_INSET_MODIFY: {
95 InsetNewlineParams params;
96 string2params(to_utf8(cmd.argument()), params);
97 params_.kind = params.kind;
102 Inset::doDispatch(cur, cmd);
108 bool InsetNewline::getStatus(Cursor & cur, FuncRequest const & cmd,
109 FuncStatus & status) const
111 switch (cmd.action) {
113 case LFUN_INSET_MODIFY:
114 if (cmd.getArg(0) == "newline") {
115 InsetNewlineParams params;
116 string2params(to_utf8(cmd.argument()), params);
117 status.setOnOff(params_.kind == params.kind);
119 status.setEnabled(true);
122 return Inset::getStatus(cur, cmd, status);
127 ColorCode InsetNewline::ColorName() const
129 switch (params_.kind) {
130 case InsetNewlineParams::NEWLINE:
131 return Color_eolmarker;
133 case InsetNewlineParams::LINEBREAK:
134 return Color_pagebreak;
137 return Color_eolmarker;
143 int InsetNewline::latex(odocstream & os, OutputParams const & rp) const
145 switch (params_.kind) {
146 case InsetNewlineParams::NEWLINE:
147 if (rp.inTableCell == OutputParams::PLAIN)
152 case InsetNewlineParams::LINEBREAK:
153 os << "\\linebreak{}\n";
163 int InsetNewline::plaintext(odocstream & os, OutputParams const &) const
166 return PLAINTEXT_NEWLINE;
170 int InsetNewline::docbook(odocstream & os, OutputParams const &) const
177 void InsetNewline::draw(PainterInfo & pi, int x, int y) const
180 font.setColor(ColorName());
182 frontend::FontMetrics const & fm = theFontMetrics(pi.base.font);
183 int const wid = fm.width('n');
184 int const asc = fm.maxAscent();
189 yp[0] = int(y - 0.875 * asc * 0.75);
190 yp[1] = int(y - 0.500 * asc * 0.75);
191 yp[2] = int(y - 0.125 * asc * 0.75);
194 xp[0] = int(x + wid * 0.375);
196 xp[2] = int(x + wid * 0.375);
198 xp[0] = int(x + wid * 0.625);
199 xp[1] = int(x + wid);
200 xp[2] = int(x + wid * 0.625);
203 pi.pain.lines(xp, yp, 3, ColorName());
205 yp[0] = int(y - 0.500 * asc * 0.75);
206 yp[1] = int(y - 0.500 * asc * 0.75);
207 yp[2] = int(y - asc * 0.75);
211 xp[1] = int(x + wid);
212 xp[2] = int(x + wid);
214 xp[0] = int(x + wid);
219 pi.pain.lines(xp, yp, 3, ColorName());
221 if (params_.kind == InsetNewlineParams::LINEBREAK) {
223 yp[2] = int(y - 0.500 * asc * 0.75);
226 xp[0] = int(x + 1.3 * wid);
227 xp[1] = int(x + 2 * wid);
228 xp[2] = int(x + 2 * wid);
230 xp[0] = int(x - 0.3 * wid);
231 xp[1] = int(x - wid);
232 xp[2] = int(x - wid);
234 pi.pain.lines(xp, yp, 3, ColorName());
236 yp[0] = int(y - 0.875 * asc * 0.75);
237 yp[1] = int(y - 0.500 * asc * 0.75);
238 yp[2] = int(y - 0.125 * asc * 0.75);
241 xp[0] = int(x + 2 * wid * 0.813);
242 xp[1] = int(x + 2 * wid);
243 xp[2] = int(x + 2 * wid * 0.813);
245 xp[0] = int(x - wid * 0.625);
246 xp[1] = int(x - wid);
247 xp[2] = int(x - wid * 0.625);
249 pi.pain.lines(xp, yp, 3, ColorName());
254 docstring InsetNewline::contextMenu(BufferView const &, int, int) const
256 return from_ascii("context-newline");
260 void InsetNewline::string2params(string const & in, InsetNewlineParams & params)
262 params = InsetNewlineParams();
265 istringstream data(in);
268 lex.setContext("InsetNewline::string2params");
274 string InsetNewline::params2string(InsetNewlineParams const & params)
277 data << "newline" << ' ';