2003-03-12 19:16:42 +00:00
|
|
|
/**
|
2007-04-25 01:24:38 +00:00
|
|
|
* \file InsetNewline.cpp
|
2003-03-12 19:16:42 +00:00
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
*
|
|
|
|
* \author John Levon
|
2008-11-14 15:58:50 +00:00
|
|
|
* \author Jürgen Spitzmüller
|
2003-03-12 19:16:42 +00:00
|
|
|
*
|
2003-08-23 00:17:00 +00:00
|
|
|
* Full author contact details are available in file CREDITS.
|
2003-03-12 19:16:42 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
2007-04-25 01:24:38 +00:00
|
|
|
#include "InsetNewline.h"
|
2003-03-12 19:16:42 +00:00
|
|
|
|
2008-03-27 22:26:24 +00:00
|
|
|
#include "Dimension.h"
|
2008-03-26 08:10:01 +00:00
|
|
|
#include "FuncRequest.h"
|
|
|
|
#include "FuncStatus.h"
|
|
|
|
#include "Lexer.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
#include "MetricsInfo.h"
|
|
|
|
#include "OutputParams.h"
|
2009-11-19 23:04:10 +00:00
|
|
|
#include "output_xhtml.h"
|
2003-08-26 16:36:53 +00:00
|
|
|
|
2008-03-27 22:26:24 +00:00
|
|
|
#include "frontends/Application.h"
|
2006-10-07 16:15:06 +00:00
|
|
|
#include "frontends/FontMetrics.h"
|
2003-09-05 09:01:27 +00:00
|
|
|
#include "frontends/Painter.h"
|
2003-03-12 19:16:42 +00:00
|
|
|
|
2008-02-18 07:14:42 +00:00
|
|
|
#include "support/debug.h"
|
2007-11-28 22:12:03 +00:00
|
|
|
#include "support/docstream.h"
|
2008-03-27 22:26:24 +00:00
|
|
|
#include "support/docstring.h"
|
2007-11-25 18:34:37 +00:00
|
|
|
|
2007-12-12 10:16:00 +00:00
|
|
|
using namespace std;
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
namespace lyx {
|
2006-10-19 16:51:30 +00:00
|
|
|
|
2009-11-08 15:53:21 +00:00
|
|
|
InsetNewline::InsetNewline() : Inset(0)
|
2008-03-26 08:10:01 +00:00
|
|
|
{}
|
2003-03-12 19:16:42 +00:00
|
|
|
|
2008-03-27 22:26:24 +00:00
|
|
|
|
2008-03-26 08:10:01 +00:00
|
|
|
void InsetNewlineParams::write(ostream & os) const
|
2003-03-12 19:16:42 +00:00
|
|
|
{
|
2008-03-26 08:10:01 +00:00
|
|
|
string command;
|
|
|
|
switch (kind) {
|
|
|
|
case InsetNewlineParams::NEWLINE:
|
|
|
|
os << "newline";
|
|
|
|
break;
|
|
|
|
case InsetNewlineParams::LINEBREAK:
|
|
|
|
os << "linebreak";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void InsetNewlineParams::read(Lexer & lex)
|
|
|
|
{
|
2008-04-05 10:34:29 +00:00
|
|
|
string token;
|
|
|
|
lex.setContext("InsetNewlineParams::read");
|
|
|
|
lex >> token;
|
|
|
|
if (token == "newline")
|
2008-03-26 08:10:01 +00:00
|
|
|
kind = InsetNewlineParams::NEWLINE;
|
2008-04-05 10:34:29 +00:00
|
|
|
else if (token == "linebreak")
|
2008-03-26 08:10:01 +00:00
|
|
|
kind = InsetNewlineParams::LINEBREAK;
|
|
|
|
else
|
2008-04-05 10:34:29 +00:00
|
|
|
lex.printError("Unknown kind: `$$Token'");
|
2003-03-12 19:16:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
void InsetNewline::write(ostream & os) const
|
2003-03-12 19:16:42 +00:00
|
|
|
{
|
2008-03-26 08:10:01 +00:00
|
|
|
os << "Newline ";
|
|
|
|
params_.write(os);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void InsetNewline::read(Lexer & lex)
|
|
|
|
{
|
|
|
|
params_.read(lex);
|
2009-02-19 04:42:30 +00:00
|
|
|
lex >> "\\end_inset";
|
2003-03-12 19:16:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-09-21 20:39:47 +00:00
|
|
|
void InsetNewline::metrics(MetricsInfo & mi, Dimension & dim) const
|
2003-03-12 19:16:42 +00:00
|
|
|
{
|
2006-10-21 00:16:43 +00:00
|
|
|
frontend::FontMetrics const & fm = theFontMetrics(mi.base.font);
|
2006-10-07 16:15:06 +00:00
|
|
|
dim.asc = fm.maxAscent();
|
|
|
|
dim.des = fm.maxDescent();
|
|
|
|
dim.wid = fm.width('n');
|
2003-03-12 19:16:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-03-26 08:10:01 +00:00
|
|
|
void InsetNewline::doDispatch(Cursor & cur, FuncRequest & cmd)
|
|
|
|
{
|
|
|
|
switch (cmd.action) {
|
|
|
|
|
|
|
|
case LFUN_INSET_MODIFY: {
|
|
|
|
InsetNewlineParams params;
|
2008-03-27 22:26:24 +00:00
|
|
|
string2params(to_utf8(cmd.argument()), params);
|
2008-03-26 08:10:01 +00:00
|
|
|
params_.kind = params.kind;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
Inset::doDispatch(cur, cmd);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool InsetNewline::getStatus(Cursor & cur, FuncRequest const & cmd,
|
|
|
|
FuncStatus & status) const
|
|
|
|
{
|
|
|
|
switch (cmd.action) {
|
|
|
|
// we handle these
|
|
|
|
case LFUN_INSET_MODIFY:
|
|
|
|
if (cmd.getArg(0) == "newline") {
|
|
|
|
InsetNewlineParams params;
|
2008-03-27 22:26:24 +00:00
|
|
|
string2params(to_utf8(cmd.argument()), params);
|
2008-03-26 08:10:01 +00:00
|
|
|
status.setOnOff(params_.kind == params.kind);
|
2008-03-27 22:26:24 +00:00
|
|
|
}
|
2008-05-29 15:14:00 +00:00
|
|
|
status.setEnabled(true);
|
2008-03-26 08:10:01 +00:00
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
return Inset::getStatus(cur, cmd, status);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ColorCode InsetNewline::ColorName() const
|
|
|
|
{
|
|
|
|
switch (params_.kind) {
|
|
|
|
case InsetNewlineParams::NEWLINE:
|
|
|
|
return Color_eolmarker;
|
|
|
|
break;
|
|
|
|
case InsetNewlineParams::LINEBREAK:
|
|
|
|
return Color_pagebreak;
|
|
|
|
break;
|
|
|
|
}
|
2008-09-16 11:33:07 +00:00
|
|
|
// not really useful, but to avoids gcc complaints
|
|
|
|
return Color_eolmarker;
|
2008-03-26 08:10:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-09-10 16:02:32 +00:00
|
|
|
int InsetNewline::latex(odocstream & os, OutputParams const & rp) const
|
2003-03-12 19:16:42 +00:00
|
|
|
{
|
2008-03-26 08:10:01 +00:00
|
|
|
switch (params_.kind) {
|
|
|
|
case InsetNewlineParams::NEWLINE:
|
2008-09-10 16:02:32 +00:00
|
|
|
if (rp.inTableCell == OutputParams::PLAIN)
|
2008-09-09 18:42:17 +00:00
|
|
|
os << "\\newline\n";
|
|
|
|
else
|
|
|
|
os << "\\\\\n";
|
2008-03-26 08:10:01 +00:00
|
|
|
break;
|
|
|
|
case InsetNewlineParams::LINEBREAK:
|
|
|
|
os << "\\linebreak{}\n";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
os << "\\\\\n";
|
|
|
|
break;
|
|
|
|
}
|
2003-03-12 19:16:42 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
int InsetNewline::plaintext(odocstream & os, OutputParams const &) const
|
2003-03-12 19:16:42 +00:00
|
|
|
{
|
|
|
|
os << '\n';
|
2007-02-20 17:52:41 +00:00
|
|
|
return PLAINTEXT_NEWLINE;
|
2003-03-12 19:16:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
int InsetNewline::docbook(odocstream & os, OutputParams const &) const
|
2003-03-12 19:16:42 +00:00
|
|
|
{
|
2003-06-06 18:35:03 +00:00
|
|
|
os << '\n';
|
2003-03-12 19:16:42 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-19 23:04:10 +00:00
|
|
|
docstring InsetNewline::xhtml(XHTMLStream & xs, OutputParams const &) const
|
2009-06-05 17:48:14 +00:00
|
|
|
{
|
2010-01-19 22:08:04 +00:00
|
|
|
xs << html::CompTag("br");
|
2009-11-19 23:04:10 +00:00
|
|
|
xs.cr();
|
2009-06-12 17:23:17 +00:00
|
|
|
return docstring();
|
2009-06-05 17:48:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-05-30 06:48:24 +00:00
|
|
|
void InsetNewline::draw(PainterInfo & pi, int x, int y) const
|
2003-03-12 19:16:42 +00:00
|
|
|
{
|
2007-11-25 18:34:37 +00:00
|
|
|
FontInfo font;
|
|
|
|
font.setColor(ColorName());
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
frontend::FontMetrics const & fm = theFontMetrics(pi.base.font);
|
2006-10-07 16:15:06 +00:00
|
|
|
int const wid = fm.width('n');
|
|
|
|
int const asc = fm.maxAscent();
|
2003-03-12 19:16:42 +00:00
|
|
|
|
|
|
|
int xp[3];
|
|
|
|
int yp[3];
|
|
|
|
|
|
|
|
yp[0] = int(y - 0.875 * asc * 0.75);
|
|
|
|
yp[1] = int(y - 0.500 * asc * 0.75);
|
|
|
|
yp[2] = int(y - 0.125 * asc * 0.75);
|
|
|
|
|
2004-08-14 23:57:29 +00:00
|
|
|
if (pi.ltr_pos) {
|
2003-03-12 19:16:42 +00:00
|
|
|
xp[0] = int(x + wid * 0.375);
|
|
|
|
xp[1] = int(x);
|
|
|
|
xp[2] = int(x + wid * 0.375);
|
|
|
|
} else {
|
|
|
|
xp[0] = int(x + wid * 0.625);
|
|
|
|
xp[1] = int(x + wid);
|
|
|
|
xp[2] = int(x + wid * 0.625);
|
|
|
|
}
|
|
|
|
|
2007-11-25 18:34:37 +00:00
|
|
|
pi.pain.lines(xp, yp, 3, ColorName());
|
2003-03-12 19:16:42 +00:00
|
|
|
|
|
|
|
yp[0] = int(y - 0.500 * asc * 0.75);
|
|
|
|
yp[1] = int(y - 0.500 * asc * 0.75);
|
|
|
|
yp[2] = int(y - asc * 0.75);
|
|
|
|
|
2004-08-14 23:57:29 +00:00
|
|
|
if (pi.ltr_pos) {
|
2003-03-12 19:16:42 +00:00
|
|
|
xp[0] = int(x);
|
|
|
|
xp[1] = int(x + wid);
|
|
|
|
xp[2] = int(x + wid);
|
|
|
|
} else {
|
|
|
|
xp[0] = int(x + wid);
|
|
|
|
xp[1] = int(x);
|
|
|
|
xp[2] = int(x);
|
|
|
|
}
|
|
|
|
|
2007-11-25 18:34:37 +00:00
|
|
|
pi.pain.lines(xp, yp, 3, ColorName());
|
|
|
|
|
2008-03-26 08:10:01 +00:00
|
|
|
if (params_.kind == InsetNewlineParams::LINEBREAK) {
|
|
|
|
|
|
|
|
yp[2] = int(y - 0.500 * asc * 0.75);
|
|
|
|
|
|
|
|
if (pi.ltr_pos) {
|
|
|
|
xp[0] = int(x + 1.3 * wid);
|
|
|
|
xp[1] = int(x + 2 * wid);
|
|
|
|
xp[2] = int(x + 2 * wid);
|
|
|
|
} else {
|
|
|
|
xp[0] = int(x - 0.3 * wid);
|
|
|
|
xp[1] = int(x - wid);
|
|
|
|
xp[2] = int(x - wid);
|
|
|
|
}
|
|
|
|
pi.pain.lines(xp, yp, 3, ColorName());
|
|
|
|
|
|
|
|
yp[0] = int(y - 0.875 * asc * 0.75);
|
|
|
|
yp[1] = int(y - 0.500 * asc * 0.75);
|
|
|
|
yp[2] = int(y - 0.125 * asc * 0.75);
|
2007-11-25 18:34:37 +00:00
|
|
|
|
2008-03-26 08:10:01 +00:00
|
|
|
if (pi.ltr_pos) {
|
|
|
|
xp[0] = int(x + 2 * wid * 0.813);
|
|
|
|
xp[1] = int(x + 2 * wid);
|
|
|
|
xp[2] = int(x + 2 * wid * 0.813);
|
|
|
|
} else {
|
|
|
|
xp[0] = int(x - wid * 0.625);
|
|
|
|
xp[1] = int(x - wid);
|
|
|
|
xp[2] = int(x - wid * 0.625);
|
|
|
|
}
|
|
|
|
pi.pain.lines(xp, yp, 3, ColorName());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
docstring InsetNewline::contextMenu(BufferView const &, int, int) const
|
|
|
|
{
|
|
|
|
return from_ascii("context-newline");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-03-27 22:26:24 +00:00
|
|
|
void InsetNewline::string2params(string const & in, InsetNewlineParams & params)
|
2008-03-26 08:10:01 +00:00
|
|
|
{
|
|
|
|
params = InsetNewlineParams();
|
|
|
|
if (in.empty())
|
|
|
|
return;
|
|
|
|
istringstream data(in);
|
2008-04-02 23:06:22 +00:00
|
|
|
Lexer lex;
|
2008-03-26 08:10:01 +00:00
|
|
|
lex.setStream(data);
|
2008-04-05 10:34:29 +00:00
|
|
|
lex.setContext("InsetNewline::string2params");
|
|
|
|
lex >> "newline";
|
2008-03-26 08:10:01 +00:00
|
|
|
params.read(lex);
|
2003-03-12 19:16:42 +00:00
|
|
|
}
|
2004-02-20 10:32:44 +00:00
|
|
|
|
|
|
|
|
2008-03-27 22:26:24 +00:00
|
|
|
string InsetNewline::params2string(InsetNewlineParams const & params)
|
2004-02-20 10:32:44 +00:00
|
|
|
{
|
2008-03-26 08:10:01 +00:00
|
|
|
ostringstream data;
|
2008-03-27 22:26:24 +00:00
|
|
|
data << "newline" << ' ';
|
2008-03-26 08:10:01 +00:00
|
|
|
params.write(data);
|
|
|
|
return data.str();
|
2004-02-20 10:32:44 +00:00
|
|
|
}
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
} // namespace lyx
|