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.
|
|
|
|
|
*
|
|
|
|
|
* \author Andr<EFBFBD> P<EFBFBD>nitz
|
2008-03-25 09:26:03 +00:00
|
|
|
|
* \author J<EFBFBD>rgen Spitzm<EFBFBD>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
|
|
|
|
|
2008-03-25 09:26:03 +00:00
|
|
|
|
#include "FuncRequest.h"
|
|
|
|
|
#include "FuncStatus.h"
|
2007-04-29 23:33:02 +00:00
|
|
|
|
#include "Text.h"
|
2008-03-25 09:26:03 +00:00
|
|
|
|
#include "Lexer.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
|
#include "MetricsInfo.h"
|
|
|
|
|
#include "OutputParams.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 {
|
|
|
|
|
|
2008-03-25 09:26:03 +00:00
|
|
|
|
InsetNewpage::InsetNewpage()
|
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
2008-03-27 22:26:24 +00:00
|
|
|
|
InsetNewpage::InsetNewpage(InsetNewpageParams const & params)
|
|
|
|
|
: params_(params)
|
|
|
|
|
{}
|
|
|
|
|
|
2008-03-25 09:26:03 +00:00
|
|
|
|
|
|
|
|
|
void InsetNewpageParams::write(ostream & os) const
|
|
|
|
|
{
|
|
|
|
|
string command;
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void InsetNewpageParams::read(Lexer & lex)
|
2003-10-27 12:41:26 +00:00
|
|
|
|
{
|
2008-03-25 09:26:03 +00:00
|
|
|
|
lex.next();
|
|
|
|
|
string const command = lex.getString();
|
|
|
|
|
|
|
|
|
|
if (command == "newpage")
|
|
|
|
|
kind = InsetNewpageParams::NEWPAGE;
|
|
|
|
|
else if (command == "pagebreak")
|
|
|
|
|
kind = InsetNewpageParams::PAGEBREAK;
|
|
|
|
|
else if (command == "clearpage")
|
|
|
|
|
kind = InsetNewpageParams::CLEARPAGE;
|
|
|
|
|
else if (command == "cleardoublepage")
|
|
|
|
|
kind = InsetNewpageParams::CLEARDOUBLEPAGE;
|
|
|
|
|
else
|
|
|
|
|
lex.printError("InsetNewpage: Unknown kind: `$$Token'");
|
|
|
|
|
|
|
|
|
|
string token;
|
|
|
|
|
lex >> token;
|
|
|
|
|
if (!lex)
|
|
|
|
|
return;
|
|
|
|
|
if (token != "\\end_inset")
|
|
|
|
|
lex.printError("Missing \\end_inset at this point. "
|
|
|
|
|
"Read: `$$Token'");
|
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);
|
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
|
|
|
|
{
|
|
|
|
|
dim.asc = defaultRowHeight();
|
|
|
|
|
dim.des = defaultRowHeight();
|
|
|
|
|
dim.wid = mi.base.textwidth;
|
2007-09-25 07:07:11 +00:00
|
|
|
|
// Cache the inset dimension.
|
|
|
|
|
setDimCache(mi, dim);
|
2003-10-27 12:41:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
{
|
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)
|
|
|
|
|
{
|
|
|
|
|
switch (cmd.action) {
|
|
|
|
|
|
|
|
|
|
case LFUN_INSET_MODIFY: {
|
|
|
|
|
InsetNewpageParams params;
|
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
|
|
|
|
|
{
|
|
|
|
|
switch (cmd.action) {
|
|
|
|
|
// 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);
|
2008-03-27 22:26:24 +00:00
|
|
|
|
} else {
|
2008-03-25 09:26:03 +00:00
|
|
|
|
status.enabled(true);
|
2008-03-27 22:26:24 +00:00
|
|
|
|
}
|
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");
|
|
|
|
|
break;
|
|
|
|
|
case InsetNewpageParams::PAGEBREAK:
|
|
|
|
|
return _("Page Break");
|
|
|
|
|
break;
|
|
|
|
|
case InsetNewpageParams::CLEARPAGE:
|
|
|
|
|
return _("Clear Page");
|
|
|
|
|
break;
|
|
|
|
|
case InsetNewpageParams::CLEARDOUBLEPAGE:
|
|
|
|
|
return _("Clear Double Page");
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
return _("New Page");
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ColorCode InsetNewpage::ColorName() const
|
|
|
|
|
{
|
|
|
|
|
switch (params_.kind) {
|
|
|
|
|
case InsetNewpageParams::NEWPAGE:
|
|
|
|
|
return Color_newpage;
|
|
|
|
|
break;
|
|
|
|
|
case InsetNewpageParams::PAGEBREAK:
|
|
|
|
|
return Color_pagebreak;
|
|
|
|
|
break;
|
|
|
|
|
case InsetNewpageParams::CLEARPAGE:
|
|
|
|
|
return Color_newpage;
|
|
|
|
|
break;
|
|
|
|
|
case InsetNewpageParams::CLEARDOUBLEPAGE:
|
|
|
|
|
return Color_newpage;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
return Color_newpage;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
|
int InsetNewpage::latex(odocstream & os, OutputParams const &) const
|
2003-10-27 12:41:26 +00:00
|
|
|
|
{
|
2008-03-25 09:26:03 +00:00
|
|
|
|
switch (params_.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;
|
|
|
|
|
default:
|
|
|
|
|
os << "\\newpage{}";
|
|
|
|
|
break;
|
|
|
|
|
}
|
2003-10-27 12:41:26 +00:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
|
int InsetNewpage::plaintext(odocstream & os, OutputParams const &) const
|
2003-10-27 12:41:26 +00:00
|
|
|
|
{
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
|
int InsetNewpage::docbook(odocstream & os, OutputParams const &) const
|
2003-10-27 12:41:26 +00:00
|
|
|
|
{
|
|
|
|
|
os << '\n';
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
|
|
|
2008-03-25 09:26:03 +00:00
|
|
|
|
docstring InsetNewpage::contextMenu(BufferView const &, int, int) const
|
|
|
|
|
{
|
|
|
|
|
return from_ascii("context-newpage");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
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
|