2003-10-27 12:41:26 +00:00
|
|
|
/**
|
2007-11-23 02:10:00 +00:00
|
|
|
* \file InsetNewpage.cpp
|
2003-10-27 12:41:26 +00:00
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
*
|
2008-11-14 15:58:50 +00:00
|
|
|
* \author André Pönitz
|
|
|
|
* \author Jürgen Spitzmüller
|
2003-10-27 12:41:26 +00:00
|
|
|
*
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
2007-11-23 02:10:00 +00:00
|
|
|
#include "InsetNewpage.h"
|
2003-10-27 12:41:26 +00:00
|
|
|
|
2010-11-29 09:47:46 +00:00
|
|
|
#include "Cursor.h"
|
2008-03-25 09:26:03 +00:00
|
|
|
#include "FuncRequest.h"
|
|
|
|
#include "FuncStatus.h"
|
|
|
|
#include "Lexer.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
#include "MetricsInfo.h"
|
2020-06-08 21:27:49 +00:00
|
|
|
#include "xml.h"
|
2016-06-19 02:39:38 +00:00
|
|
|
#include "texstream.h"
|
2008-06-18 18:54:31 +00:00
|
|
|
#include "Text.h"
|
2006-12-29 23:54:48 +00:00
|
|
|
#include "TextMetrics.h"
|
2003-10-27 12:41:26 +00:00
|
|
|
|
2006-10-07 16:15:06 +00:00
|
|
|
#include "frontends/FontMetrics.h"
|
2003-10-27 12:41:26 +00:00
|
|
|
#include "frontends/Painter.h"
|
|
|
|
|
2008-02-18 07:14:42 +00:00
|
|
|
#include "support/debug.h"
|
2007-11-14 21:57:43 +00:00
|
|
|
#include "support/docstring.h"
|
2007-11-28 22:12:03 +00:00
|
|
|
#include "support/docstream.h"
|
2008-02-18 07:14:42 +00:00
|
|
|
#include "support/gettext.h"
|
2007-11-14 21:57:43 +00:00
|
|
|
|
2007-12-12 19:28:07 +00:00
|
|
|
using namespace std;
|
2006-10-21 00:16:43 +00:00
|
|
|
|
2008-03-15 00:02:41 +00:00
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
namespace lyx {
|
|
|
|
|
2020-10-05 10:38:09 +00:00
|
|
|
InsetNewpage::InsetNewpage() : Inset(nullptr)
|
2008-03-25 09:26:03 +00:00
|
|
|
{}
|
|
|
|
|
|
|
|
|
2008-03-27 22:26:24 +00:00
|
|
|
InsetNewpage::InsetNewpage(InsetNewpageParams const & params)
|
2020-10-05 10:38:09 +00:00
|
|
|
: Inset(nullptr), params_(params)
|
2008-03-27 22:26:24 +00:00
|
|
|
{}
|
|
|
|
|
2008-03-25 09:26:03 +00:00
|
|
|
|
|
|
|
void InsetNewpageParams::write(ostream & os) const
|
|
|
|
{
|
|
|
|
switch (kind) {
|
|
|
|
case InsetNewpageParams::NEWPAGE:
|
|
|
|
os << "newpage";
|
|
|
|
break;
|
|
|
|
case InsetNewpageParams::PAGEBREAK:
|
|
|
|
os << "pagebreak";
|
|
|
|
break;
|
|
|
|
case InsetNewpageParams::CLEARPAGE:
|
|
|
|
os << "clearpage";
|
|
|
|
break;
|
|
|
|
case InsetNewpageParams::CLEARDOUBLEPAGE:
|
|
|
|
os << "cleardoublepage";
|
|
|
|
break;
|
2020-10-13 17:13:59 +00:00
|
|
|
case InsetNewpageParams::NOPAGEBREAK:
|
|
|
|
os << "nopagebreak";
|
|
|
|
break;
|
2008-03-25 09:26:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void InsetNewpageParams::read(Lexer & lex)
|
2003-10-27 12:41:26 +00:00
|
|
|
{
|
2008-04-05 10:34:29 +00:00
|
|
|
lex.setContext("InsetNewpageParams::read");
|
|
|
|
string token;
|
|
|
|
lex >> token;
|
2008-03-25 09:26:03 +00:00
|
|
|
|
2008-04-05 10:34:29 +00:00
|
|
|
if (token == "newpage")
|
2008-03-25 09:26:03 +00:00
|
|
|
kind = InsetNewpageParams::NEWPAGE;
|
2008-04-05 10:34:29 +00:00
|
|
|
else if (token == "pagebreak")
|
2008-03-25 09:26:03 +00:00
|
|
|
kind = InsetNewpageParams::PAGEBREAK;
|
2008-04-05 10:34:29 +00:00
|
|
|
else if (token == "clearpage")
|
2008-03-25 09:26:03 +00:00
|
|
|
kind = InsetNewpageParams::CLEARPAGE;
|
2008-04-05 10:34:29 +00:00
|
|
|
else if (token == "cleardoublepage")
|
2008-03-25 09:26:03 +00:00
|
|
|
kind = InsetNewpageParams::CLEARDOUBLEPAGE;
|
2020-10-13 17:13:59 +00:00
|
|
|
else if (token == "nopagebreak")
|
|
|
|
kind = InsetNewpageParams::NOPAGEBREAK;
|
2008-03-25 09:26:03 +00:00
|
|
|
else
|
2008-04-05 21:24:57 +00:00
|
|
|
lex.printError("Unknown kind");
|
2003-10-27 12:41:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
void InsetNewpage::write(ostream & os) const
|
2003-10-27 12:41:26 +00:00
|
|
|
{
|
2008-03-25 09:26:03 +00:00
|
|
|
os << "Newpage ";
|
|
|
|
params_.write(os);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void InsetNewpage::read(Lexer & lex)
|
|
|
|
{
|
|
|
|
params_.read(lex);
|
2009-02-19 04:42:30 +00:00
|
|
|
lex >> "\\end_inset";
|
2003-10-27 12:41:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-11-23 02:10:00 +00:00
|
|
|
void InsetNewpage::metrics(MetricsInfo & mi, Dimension & dim) const
|
2003-10-27 12:41:26 +00:00
|
|
|
{
|
2020-10-13 17:13:59 +00:00
|
|
|
if (params_.kind == InsetNewpageParams::NOPAGEBREAK) {
|
|
|
|
frontend::FontMetrics const & fm = theFontMetrics(mi.base.font);
|
|
|
|
dim.asc = fm.maxAscent();
|
|
|
|
dim.des = fm.maxDescent();
|
|
|
|
dim.wid = 3 * fm.width('n');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2003-10-27 12:41:26 +00:00
|
|
|
dim.asc = defaultRowHeight();
|
|
|
|
dim.des = defaultRowHeight();
|
|
|
|
dim.wid = mi.base.textwidth;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-11-23 02:10:00 +00:00
|
|
|
void InsetNewpage::draw(PainterInfo & pi, int x, int y) const
|
2003-10-27 12:41:26 +00:00
|
|
|
{
|
2020-10-13 17:13:59 +00:00
|
|
|
if (params_.kind == InsetNewpageParams::NOPAGEBREAK) {
|
|
|
|
|
|
|
|
FontInfo font;
|
|
|
|
font.setColor(ColorName());
|
|
|
|
|
|
|
|
frontend::FontMetrics const & fm = theFontMetrics(pi.base.font);
|
|
|
|
int const wid = 3 * fm.width('n');
|
|
|
|
int const asc = fm.maxAscent();
|
|
|
|
|
|
|
|
int xp[3];
|
|
|
|
int yp[3];
|
|
|
|
|
|
|
|
//left side arrow
|
|
|
|
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);
|
|
|
|
xp[0] = int(x + wid * 0.25);
|
|
|
|
xp[1] = int(x + wid * 0.4);
|
|
|
|
xp[2] = int(x + wid * 0.25);
|
|
|
|
pi.pain.lines(xp, yp, 3, ColorName());
|
|
|
|
|
|
|
|
yp[0] = yp[1] = int(y - 0.500 * asc * 0.75);
|
|
|
|
xp[0] = int(x + wid * 0.03);
|
|
|
|
xp[1] = int(x + wid * 0.4);
|
|
|
|
pi.pain.lines(xp, yp, 2, ColorName());
|
|
|
|
|
|
|
|
//right side arrow
|
|
|
|
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);
|
|
|
|
xp[0] = int(x + wid * 0.75);
|
|
|
|
xp[1] = int(x + wid * 0.6);
|
|
|
|
xp[2] = int(x + wid * 0.75);
|
|
|
|
pi.pain.lines(xp, yp, 3, ColorName());
|
|
|
|
|
|
|
|
yp[0] = yp[1] = int(y - 0.500 * asc * 0.75);
|
|
|
|
xp[0] = int(x + wid * 0.97);
|
|
|
|
xp[1] = int(x + wid * 0.6);
|
|
|
|
pi.pain.lines(xp, yp, 2, ColorName());
|
|
|
|
|
|
|
|
//mid-rule
|
2020-11-26 20:14:43 +00:00
|
|
|
xp[0] = xp[1] = int(x + wid * 0.5);
|
2020-10-13 17:13:59 +00:00
|
|
|
yp[0] = int(y - 0.875 * asc * 0.75);
|
|
|
|
yp[1] = int(y - 0.125 * asc * 0.75);
|
|
|
|
pi.pain.lines(xp, yp, 2, ColorName());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2007-11-28 22:12:03 +00:00
|
|
|
using frontend::Painter;
|
|
|
|
|
2007-10-28 18:51:54 +00:00
|
|
|
FontInfo font;
|
2007-11-25 21:53:39 +00:00
|
|
|
font.setColor(ColorName());
|
2003-10-27 12:41:26 +00:00
|
|
|
font.decSize();
|
|
|
|
|
2007-09-25 07:07:11 +00:00
|
|
|
Dimension const dim = dimension(*pi.base.bv);
|
|
|
|
|
2003-10-27 12:41:26 +00:00
|
|
|
int w = 0;
|
|
|
|
int a = 0;
|
|
|
|
int d = 0;
|
2006-11-25 16:52:09 +00:00
|
|
|
theFontMetrics(font).rectText(insetLabel(), w, a, d);
|
2003-10-27 12:41:26 +00:00
|
|
|
|
2007-09-25 07:07:11 +00:00
|
|
|
int const text_start = int(x + (dim.wid - w) / 2);
|
2003-10-27 12:41:26 +00:00
|
|
|
int const text_end = text_start + w;
|
|
|
|
|
2006-11-25 16:52:09 +00:00
|
|
|
pi.pain.rectText(text_start, y + d, insetLabel(), font,
|
2007-10-25 12:41:02 +00:00
|
|
|
Color_none, Color_none);
|
2003-10-27 12:41:26 +00:00
|
|
|
|
|
|
|
pi.pain.line(x, y, text_start, y,
|
2007-11-25 21:53:39 +00:00
|
|
|
ColorName(), Painter::line_onoffdash);
|
2007-09-25 07:07:11 +00:00
|
|
|
pi.pain.line(text_end, y, int(x + dim.wid), y,
|
2007-11-25 21:53:39 +00:00
|
|
|
ColorName(), Painter::line_onoffdash);
|
2003-10-27 12:41:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-03-25 09:26:03 +00:00
|
|
|
void InsetNewpage::doDispatch(Cursor & cur, FuncRequest & cmd)
|
|
|
|
{
|
2010-04-09 19:00:42 +00:00
|
|
|
switch (cmd.action()) {
|
2008-03-25 09:26:03 +00:00
|
|
|
|
|
|
|
case LFUN_INSET_MODIFY: {
|
|
|
|
InsetNewpageParams params;
|
2010-11-29 09:47:46 +00:00
|
|
|
cur.recordUndo();
|
2008-03-27 22:26:24 +00:00
|
|
|
string2params(to_utf8(cmd.argument()), params);
|
2008-03-25 09:26:03 +00:00
|
|
|
params_.kind = params.kind;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
Inset::doDispatch(cur, cmd);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool InsetNewpage::getStatus(Cursor & cur, FuncRequest const & cmd,
|
|
|
|
FuncStatus & status) const
|
|
|
|
{
|
2010-04-09 19:00:42 +00:00
|
|
|
switch (cmd.action()) {
|
2008-03-25 09:26:03 +00:00
|
|
|
// we handle these
|
|
|
|
case LFUN_INSET_MODIFY:
|
|
|
|
if (cmd.getArg(0) == "newpage") {
|
|
|
|
InsetNewpageParams params;
|
2008-03-27 22:26:24 +00:00
|
|
|
string2params(to_utf8(cmd.argument()), params);
|
2008-03-25 09:26:03 +00:00
|
|
|
status.setOnOff(params_.kind == params.kind);
|
2017-07-03 17:53:14 +00:00
|
|
|
}
|
2008-05-29 15:14:00 +00:00
|
|
|
status.setEnabled(true);
|
2008-03-25 09:26:03 +00:00
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
return Inset::getStatus(cur, cmd, status);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
docstring InsetNewpage::insetLabel() const
|
|
|
|
{
|
|
|
|
switch (params_.kind) {
|
|
|
|
case InsetNewpageParams::NEWPAGE:
|
|
|
|
return _("New Page");
|
|
|
|
case InsetNewpageParams::PAGEBREAK:
|
|
|
|
return _("Page Break");
|
|
|
|
case InsetNewpageParams::CLEARPAGE:
|
|
|
|
return _("Clear Page");
|
|
|
|
case InsetNewpageParams::CLEARDOUBLEPAGE:
|
|
|
|
return _("Clear Double Page");
|
2020-10-13 17:13:59 +00:00
|
|
|
case InsetNewpageParams::NOPAGEBREAK:
|
|
|
|
return _("No Page Break");
|
2008-03-25 09:26:03 +00:00
|
|
|
default:
|
|
|
|
return _("New Page");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ColorCode InsetNewpage::ColorName() const
|
|
|
|
{
|
|
|
|
switch (params_.kind) {
|
|
|
|
case InsetNewpageParams::PAGEBREAK:
|
2020-10-13 17:13:59 +00:00
|
|
|
case InsetNewpageParams::NOPAGEBREAK:
|
2008-03-25 09:26:03 +00:00
|
|
|
return Color_pagebreak;
|
2008-09-16 11:33:07 +00:00
|
|
|
case InsetNewpageParams::NEWPAGE:
|
2008-03-25 09:26:03 +00:00
|
|
|
case InsetNewpageParams::CLEARPAGE:
|
|
|
|
case InsetNewpageParams::CLEARDOUBLEPAGE:
|
|
|
|
return Color_newpage;
|
|
|
|
}
|
2008-09-16 11:33:07 +00:00
|
|
|
// not really useful, but to avoids gcc complaints
|
|
|
|
return Color_newpage;
|
2008-03-25 09:26:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-04-22 12:57:12 +00:00
|
|
|
void InsetNewpage::latex(otexstream & os, OutputParams const & runparams) const
|
2003-10-27 12:41:26 +00:00
|
|
|
{
|
2017-04-02 21:56:25 +00:00
|
|
|
if (runparams.inDeletedInset) {
|
|
|
|
os << "\\mbox{}\\\\\\makebox[\\columnwidth]{\\dotfill\\ "
|
|
|
|
<< insetLabel() << "\\ \\dotfill}";
|
|
|
|
} else {
|
|
|
|
switch (params_.kind) {
|
2008-03-25 09:26:03 +00:00
|
|
|
case InsetNewpageParams::NEWPAGE:
|
2016-12-16 09:20:25 +00:00
|
|
|
os << "\\newpage" << termcmd;
|
2008-03-25 09:26:03 +00:00
|
|
|
break;
|
|
|
|
case InsetNewpageParams::PAGEBREAK:
|
2016-04-22 12:57:12 +00:00
|
|
|
if (runparams.moving_arg)
|
|
|
|
os << "\\protect";
|
2016-12-16 09:20:25 +00:00
|
|
|
os << "\\pagebreak" << termcmd;
|
2008-03-25 09:26:03 +00:00
|
|
|
break;
|
|
|
|
case InsetNewpageParams::CLEARPAGE:
|
2016-12-16 09:20:25 +00:00
|
|
|
os << "\\clearpage" << termcmd;
|
2008-03-25 09:26:03 +00:00
|
|
|
break;
|
|
|
|
case InsetNewpageParams::CLEARDOUBLEPAGE:
|
2016-12-16 09:20:25 +00:00
|
|
|
os << "\\cleardoublepage" << termcmd;
|
2008-03-25 09:26:03 +00:00
|
|
|
break;
|
2020-10-13 17:13:59 +00:00
|
|
|
case InsetNewpageParams::NOPAGEBREAK:
|
|
|
|
os << "\\nopagebreak" << termcmd;
|
|
|
|
break;
|
2008-03-25 09:26:03 +00:00
|
|
|
default:
|
2016-12-16 09:20:25 +00:00
|
|
|
os << "\\newpage" << termcmd;
|
2008-03-25 09:26:03 +00:00
|
|
|
break;
|
2017-04-02 21:56:25 +00:00
|
|
|
}
|
2008-03-25 09:26:03 +00:00
|
|
|
}
|
2003-10-27 12:41:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-03-08 19:52:18 +00:00
|
|
|
int InsetNewpage::plaintext(odocstringstream & os,
|
|
|
|
OutputParams const &, size_t) const
|
2003-10-27 12:41:26 +00:00
|
|
|
{
|
2020-10-13 17:13:59 +00:00
|
|
|
if (params_.kind == InsetNewpageParams::NOPAGEBREAK)
|
|
|
|
return 0;
|
2003-11-01 14:09:35 +00:00
|
|
|
os << '\n';
|
2007-02-20 17:52:41 +00:00
|
|
|
return PLAINTEXT_NEWLINE;
|
2003-10-27 12:41:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-06-08 21:27:49 +00:00
|
|
|
void InsetNewpage::docbook(XMLStream & os, OutputParams const &) const
|
2003-10-27 12:41:26 +00:00
|
|
|
{
|
2020-10-13 17:13:59 +00:00
|
|
|
if (params_.kind != InsetNewpageParams::NOPAGEBREAK)
|
|
|
|
os << xml::CR();
|
2003-10-27 12:41:26 +00:00
|
|
|
}
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
|
2019-05-09 23:35:40 +00:00
|
|
|
docstring InsetNewpage::xhtml(XMLStream & xs, OutputParams const &) const
|
2009-06-05 17:48:14 +00:00
|
|
|
{
|
2020-10-13 17:13:59 +00:00
|
|
|
if (params_.kind != InsetNewpageParams::NOPAGEBREAK)
|
|
|
|
xs << xml::CompTag("br");
|
2009-11-28 20:33:19 +00:00
|
|
|
return docstring();
|
2009-06-05 17:48:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-10-29 14:48:55 +00:00
|
|
|
string InsetNewpage::contextMenuName() const
|
2008-03-25 09:26:03 +00:00
|
|
|
{
|
2011-10-29 14:48:55 +00:00
|
|
|
return "context-newpage";
|
2008-03-25 09:26:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-03-27 22:26:24 +00:00
|
|
|
void InsetNewpage::string2params(string const & in, InsetNewpageParams & params)
|
2008-03-25 09:26:03 +00:00
|
|
|
{
|
|
|
|
params = InsetNewpageParams();
|
|
|
|
if (in.empty())
|
|
|
|
return;
|
|
|
|
|
|
|
|
istringstream data(in);
|
2008-04-02 23:06:22 +00:00
|
|
|
Lexer lex;
|
2008-03-25 09:26:03 +00:00
|
|
|
lex.setStream(data);
|
|
|
|
|
|
|
|
string name;
|
|
|
|
lex >> name;
|
2008-03-27 22:26:24 +00:00
|
|
|
if (!lex || name != "newpage") {
|
|
|
|
LYXERR0("Expected arg 2 to be \"wrap\" in " << in);
|
|
|
|
return;
|
|
|
|
}
|
2008-03-25 09:26:03 +00:00
|
|
|
|
|
|
|
params.read(lex);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-03-27 22:26:24 +00:00
|
|
|
string InsetNewpage::params2string(InsetNewpageParams const & params)
|
2008-03-25 09:26:03 +00:00
|
|
|
{
|
|
|
|
ostringstream data;
|
2008-03-27 22:26:24 +00:00
|
|
|
data << "newpage" << ' ';
|
2008-03-25 09:26:03 +00:00
|
|
|
params.write(data);
|
|
|
|
return data.str();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
} // namespace lyx
|