2009-01-30 00:56:37 +00:00
|
|
|
/**
|
|
|
|
* \file InsetPhantom.cpp
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
*
|
|
|
|
* \author Uwe Stöhr
|
|
|
|
*
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#include "InsetPhantom.h"
|
|
|
|
|
|
|
|
#include "Buffer.h"
|
|
|
|
#include "BufferParams.h"
|
|
|
|
#include "BufferView.h"
|
|
|
|
#include "BufferParams.h"
|
|
|
|
#include "Counters.h"
|
|
|
|
#include "Cursor.h"
|
|
|
|
#include "Dimension.h"
|
|
|
|
#include "DispatchResult.h"
|
|
|
|
#include "Exporter.h"
|
|
|
|
#include "FuncRequest.h"
|
|
|
|
#include "FuncStatus.h"
|
|
|
|
#include "InsetIterator.h"
|
|
|
|
#include "LaTeXFeatures.h"
|
|
|
|
#include "Lexer.h"
|
|
|
|
#include "MetricsInfo.h"
|
|
|
|
#include "OutputParams.h"
|
2016-06-19 02:39:38 +00:00
|
|
|
#include "texstream.h"
|
2009-01-30 00:56:37 +00:00
|
|
|
#include "TextClass.h"
|
|
|
|
|
|
|
|
#include "support/docstream.h"
|
|
|
|
#include "support/gettext.h"
|
2009-05-07 18:04:05 +00:00
|
|
|
#include "support/lstrings.h"
|
2009-01-30 00:56:37 +00:00
|
|
|
#include "support/Translator.h"
|
|
|
|
|
|
|
|
#include "frontends/Application.h"
|
|
|
|
#include "frontends/FontMetrics.h"
|
|
|
|
#include "frontends/Painter.h"
|
|
|
|
|
|
|
|
#include <algorithm>
|
|
|
|
#include <sstream>
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
namespace lyx {
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
typedef Translator<string, InsetPhantomParams::Type> PhantomTranslator;
|
|
|
|
typedef Translator<docstring, InsetPhantomParams::Type> PhantomTranslatorLoc;
|
|
|
|
|
|
|
|
PhantomTranslator const init_phantomtranslator()
|
|
|
|
{
|
|
|
|
PhantomTranslator translator("Phantom", InsetPhantomParams::Phantom);
|
|
|
|
translator.addPair("HPhantom", InsetPhantomParams::HPhantom);
|
|
|
|
translator.addPair("VPhantom", InsetPhantomParams::VPhantom);
|
|
|
|
return translator;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
PhantomTranslatorLoc const init_phantomtranslator_loc()
|
|
|
|
{
|
|
|
|
PhantomTranslatorLoc translator(_("Phantom"), InsetPhantomParams::Phantom);
|
|
|
|
translator.addPair(_("HPhantom"), InsetPhantomParams::HPhantom);
|
|
|
|
translator.addPair(_("VPhantom"), InsetPhantomParams::VPhantom);
|
|
|
|
return translator;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
PhantomTranslator const & phantomtranslator()
|
|
|
|
{
|
2013-10-07 22:59:05 +00:00
|
|
|
static PhantomTranslator const translator =
|
|
|
|
init_phantomtranslator();
|
2009-01-30 00:56:37 +00:00
|
|
|
return translator;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
PhantomTranslatorLoc const & phantomtranslator_loc()
|
|
|
|
{
|
2013-10-07 22:59:05 +00:00
|
|
|
static PhantomTranslatorLoc const translator =
|
|
|
|
init_phantomtranslator_loc();
|
2009-01-30 00:56:37 +00:00
|
|
|
return translator;
|
|
|
|
}
|
|
|
|
|
2017-07-23 11:11:54 +00:00
|
|
|
} // namespace
|
2009-01-30 00:56:37 +00:00
|
|
|
|
|
|
|
|
|
|
|
InsetPhantomParams::InsetPhantomParams()
|
|
|
|
: type(Phantom)
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
|
void InsetPhantomParams::write(ostream & os) const
|
|
|
|
{
|
|
|
|
string const label = phantomtranslator().find(type);
|
|
|
|
os << "Phantom " << label << "\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void InsetPhantomParams::read(Lexer & lex)
|
|
|
|
{
|
|
|
|
string label;
|
|
|
|
lex >> label;
|
|
|
|
if (lex)
|
|
|
|
type = phantomtranslator().find(label);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// InsetPhantom
|
|
|
|
//
|
|
|
|
/////////////////////////////////////////////////////////////////////
|
|
|
|
|
2009-11-08 15:53:21 +00:00
|
|
|
InsetPhantom::InsetPhantom(Buffer * buf, string const & label)
|
2017-10-16 08:12:21 +00:00
|
|
|
: InsetCollapsible(buf)
|
2009-01-30 00:56:37 +00:00
|
|
|
{
|
2009-02-01 21:21:38 +00:00
|
|
|
setDrawFrame(false);
|
2009-01-30 00:56:37 +00:00
|
|
|
params_.type = phantomtranslator().find(label);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
InsetPhantom::~InsetPhantom()
|
|
|
|
{
|
|
|
|
hideDialogs("phantom", this);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-28 22:33:04 +00:00
|
|
|
docstring InsetPhantom::layoutName() const
|
2009-01-30 00:56:37 +00:00
|
|
|
{
|
|
|
|
return from_ascii("Phantom:" + phantomtranslator().find(params_.type));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void InsetPhantom::draw(PainterInfo & pi, int x, int y) const
|
|
|
|
{
|
|
|
|
// draw the text
|
2017-10-16 08:12:21 +00:00
|
|
|
InsetCollapsible::draw(pi, x, y);
|
2009-02-01 18:48:48 +00:00
|
|
|
|
|
|
|
// draw the inset marker
|
|
|
|
drawMarkers(pi, x, y);
|
2015-05-17 15:27:12 +00:00
|
|
|
|
2009-01-30 00:56:37 +00:00
|
|
|
// draw the arrow(s)
|
|
|
|
static int const arrow_size = 4;
|
|
|
|
ColorCode const origcol = pi.base.font.color();
|
|
|
|
pi.base.font.setColor(Color_special);
|
|
|
|
pi.base.font.setColor(origcol);
|
2016-12-06 08:48:49 +00:00
|
|
|
Dimension const dim = dimension(*pi.base.bv);
|
2009-01-30 00:56:37 +00:00
|
|
|
|
|
|
|
if (params_.type == InsetPhantomParams::Phantom ||
|
|
|
|
params_.type == InsetPhantomParams::VPhantom) {
|
|
|
|
// y1---------
|
|
|
|
// / \.
|
|
|
|
// y2----- / | \.
|
|
|
|
// |
|
|
|
|
// |
|
|
|
|
// y3----- \ | /
|
|
|
|
// \ /
|
|
|
|
// y4---------
|
|
|
|
// | | |
|
|
|
|
// / | \.
|
|
|
|
// x1 x2 x3
|
|
|
|
|
|
|
|
int const x2 = x + dim.wid / 2;
|
|
|
|
int const x1 = x2 - arrow_size;
|
|
|
|
int const x3 = x2 + arrow_size;
|
|
|
|
|
|
|
|
int const y1 = y - dim.asc;
|
|
|
|
int const y2 = y1 + arrow_size;
|
|
|
|
int const y4 = y + dim.des;
|
|
|
|
int const y3 = y4 - arrow_size;
|
|
|
|
|
|
|
|
// top arrow
|
|
|
|
pi.pain.line(x2, y1, x1, y2, Color_added_space);
|
|
|
|
pi.pain.line(x2, y1, x3, y2, Color_added_space);
|
|
|
|
|
|
|
|
// bottom arrow
|
|
|
|
pi.pain.line(x2, y4, x1, y3, Color_added_space);
|
|
|
|
pi.pain.line(x2, y4, x3, y3, Color_added_space);
|
|
|
|
|
|
|
|
// joining line
|
|
|
|
pi.pain.line(x2, y1, x2, y4, Color_added_space);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (params_.type == InsetPhantomParams::Phantom ||
|
|
|
|
params_.type == InsetPhantomParams::HPhantom) {
|
|
|
|
// y1---- / \.
|
|
|
|
// / \.
|
|
|
|
// y2--- <---------------->
|
|
|
|
// \ /
|
|
|
|
// y3---- \ /
|
|
|
|
// | | | |
|
|
|
|
// x1 x2 x3 x4
|
|
|
|
|
2009-02-01 18:48:48 +00:00
|
|
|
x = x + TEXT_TO_INSET_OFFSET;
|
2009-01-30 00:56:37 +00:00
|
|
|
int const x1 = x;
|
|
|
|
int const x2 = x + arrow_size;
|
2009-02-01 18:48:48 +00:00
|
|
|
int const x4 = x + dim.wid - 2 * TEXT_TO_INSET_OFFSET;
|
2009-01-30 00:56:37 +00:00
|
|
|
int const x3 = x4 - arrow_size;
|
|
|
|
|
|
|
|
int const y2 = y + (dim.des - dim.asc) / 2;
|
|
|
|
int const y1 = y2 - arrow_size;
|
|
|
|
int const y3 = y2 + arrow_size;
|
|
|
|
|
|
|
|
// left arrow
|
|
|
|
pi.pain.line(x1, y2, x2, y3, Color_added_space);
|
|
|
|
pi.pain.line(x1, y2, x2, y1, Color_added_space);
|
|
|
|
|
|
|
|
// right arrow
|
|
|
|
pi.pain.line(x4, y2, x3, y3, Color_added_space);
|
|
|
|
pi.pain.line(x4, y2, x3, y1, Color_added_space);
|
|
|
|
|
|
|
|
// joining line
|
|
|
|
pi.pain.line(x1, y2, x4, y2, Color_added_space);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void InsetPhantom::write(ostream & os) const
|
|
|
|
{
|
|
|
|
params_.write(os);
|
2017-10-16 08:12:21 +00:00
|
|
|
InsetCollapsible::write(os);
|
2009-01-30 00:56:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void InsetPhantom::read(Lexer & lex)
|
|
|
|
{
|
|
|
|
params_.read(lex);
|
2017-10-16 08:12:21 +00:00
|
|
|
InsetCollapsible::read(lex);
|
2009-01-30 00:56:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void InsetPhantom::setButtonLabel()
|
|
|
|
{
|
|
|
|
docstring const label = phantomtranslator_loc().find(params_.type);
|
|
|
|
setLabel(label);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool InsetPhantom::showInsetDialog(BufferView * bv) const
|
|
|
|
{
|
|
|
|
bv->showDialog("phantom", params2string(params()),
|
|
|
|
const_cast<InsetPhantom *>(this));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void InsetPhantom::doDispatch(Cursor & cur, FuncRequest & cmd)
|
|
|
|
{
|
2010-04-09 19:00:42 +00:00
|
|
|
switch (cmd.action()) {
|
2009-01-30 00:56:37 +00:00
|
|
|
|
|
|
|
case LFUN_INSET_MODIFY:
|
2015-03-12 14:57:29 +00:00
|
|
|
cur.recordUndoInset(this);
|
2009-01-30 00:56:37 +00:00
|
|
|
string2params(to_utf8(cmd.argument()), params_);
|
2010-12-02 18:00:33 +00:00
|
|
|
setButtonLabel();
|
|
|
|
cur.forceBufferUpdate();
|
2009-01-30 00:56:37 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case LFUN_INSET_DIALOG_UPDATE:
|
|
|
|
cur.bv().updateDialog("phantom", params2string(params()));
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2017-10-16 08:12:21 +00:00
|
|
|
InsetCollapsible::doDispatch(cur, cmd);
|
2009-01-30 00:56:37 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool InsetPhantom::getStatus(Cursor & cur, FuncRequest const & cmd,
|
|
|
|
FuncStatus & flag) const
|
|
|
|
{
|
2010-04-09 19:00:42 +00:00
|
|
|
switch (cmd.action()) {
|
2009-01-30 00:56:37 +00:00
|
|
|
|
|
|
|
case LFUN_INSET_MODIFY:
|
2009-04-10 17:21:40 +00:00
|
|
|
if (cmd.getArg(0) == "phantom") {
|
|
|
|
InsetPhantomParams params;
|
|
|
|
string2params(to_utf8(cmd.argument()), params);
|
|
|
|
flag.setOnOff(params_.type == params.type);
|
|
|
|
}
|
2009-01-30 00:56:37 +00:00
|
|
|
flag.setEnabled(true);
|
|
|
|
return true;
|
|
|
|
|
|
|
|
case LFUN_INSET_DIALOG_UPDATE:
|
|
|
|
flag.setEnabled(true);
|
|
|
|
return true;
|
|
|
|
|
|
|
|
default:
|
2017-10-16 08:12:21 +00:00
|
|
|
return InsetCollapsible::getStatus(cur, cmd, flag);
|
2009-01-30 00:56:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-02-03 10:03:47 +00:00
|
|
|
docstring InsetPhantom::toolTip(BufferView const &, int, int) const
|
2009-02-01 20:18:52 +00:00
|
|
|
{
|
2010-11-17 17:25:22 +00:00
|
|
|
docstring const res = phantomtranslator_loc().find(params_.type);
|
|
|
|
return toolTipText(res + from_ascii(": "));
|
2009-02-01 20:18:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-02-10 20:02:48 +00:00
|
|
|
void InsetPhantom::latex(otexstream & os, OutputParams const & runparams) const
|
2009-01-30 00:56:37 +00:00
|
|
|
{
|
2015-03-16 13:15:05 +00:00
|
|
|
if (runparams.moving_arg)
|
2015-05-17 15:27:12 +00:00
|
|
|
os << "\\protect";
|
2015-03-16 13:22:03 +00:00
|
|
|
|
2015-03-16 13:47:38 +00:00
|
|
|
switch (params_.type) {
|
|
|
|
case InsetPhantomParams::Phantom:
|
2009-01-30 00:56:37 +00:00
|
|
|
os << "\\phantom{";
|
2015-03-16 13:47:38 +00:00
|
|
|
break;
|
|
|
|
case InsetPhantomParams::HPhantom:
|
2009-01-30 00:56:37 +00:00
|
|
|
os << "\\hphantom{";
|
2015-03-16 13:47:38 +00:00
|
|
|
break;
|
|
|
|
case InsetPhantomParams::VPhantom:
|
2009-01-30 00:56:37 +00:00
|
|
|
os << "\\vphantom{";
|
2015-03-16 13:47:38 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
os << "\\phantom{";
|
|
|
|
break;
|
|
|
|
}
|
2017-10-16 08:12:21 +00:00
|
|
|
InsetCollapsible::latex(os, runparams);
|
2009-01-30 00:56:37 +00:00
|
|
|
os << "}";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-03-08 19:52:18 +00:00
|
|
|
int InsetPhantom::plaintext(odocstringstream & os,
|
|
|
|
OutputParams const & runparams, size_t max_length) const
|
2009-01-30 00:56:37 +00:00
|
|
|
{
|
2015-03-16 13:47:38 +00:00
|
|
|
switch (params_.type) {
|
|
|
|
case InsetPhantomParams::Phantom:
|
2009-01-30 00:56:37 +00:00
|
|
|
os << '[' << buffer().B_("phantom") << ":";
|
2015-03-16 13:49:58 +00:00
|
|
|
break;
|
2015-03-16 13:47:38 +00:00
|
|
|
case InsetPhantomParams::HPhantom:
|
2009-01-30 00:56:37 +00:00
|
|
|
os << '[' << buffer().B_("hphantom") << ":";
|
2015-03-16 13:49:58 +00:00
|
|
|
break;
|
2015-03-16 13:47:38 +00:00
|
|
|
case InsetPhantomParams::VPhantom:
|
2009-01-30 00:56:37 +00:00
|
|
|
os << '[' << buffer().B_("vphantom") << ":";
|
2015-03-16 13:49:58 +00:00
|
|
|
break;
|
2015-03-16 13:47:38 +00:00
|
|
|
default:
|
|
|
|
os << '[' << buffer().B_("phantom") << ":";
|
2015-03-16 13:49:58 +00:00
|
|
|
break;
|
2015-03-16 13:47:38 +00:00
|
|
|
}
|
2017-10-16 08:12:21 +00:00
|
|
|
InsetCollapsible::plaintext(os, runparams, max_length);
|
2009-01-30 00:56:37 +00:00
|
|
|
os << "]";
|
|
|
|
|
|
|
|
return PLAINTEXT_NEWLINE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-02-04 16:18:43 +00:00
|
|
|
int InsetPhantom::docbook(odocstream & os, OutputParams const & runparams) const
|
2009-01-30 00:56:37 +00:00
|
|
|
{
|
2015-10-15 18:52:28 +00:00
|
|
|
docstring cmdname;
|
2015-03-16 13:47:38 +00:00
|
|
|
switch (params_.type) {
|
|
|
|
case InsetPhantomParams::Phantom:
|
|
|
|
case InsetPhantomParams::HPhantom:
|
|
|
|
case InsetPhantomParams::VPhantom:
|
|
|
|
default:
|
2015-10-15 18:52:28 +00:00
|
|
|
cmdname = from_ascii("phantom");
|
2015-03-16 13:49:58 +00:00
|
|
|
break;
|
2015-03-16 13:47:38 +00:00
|
|
|
}
|
2009-01-30 00:56:37 +00:00
|
|
|
os << "<" + cmdname + ">";
|
2017-10-16 08:12:21 +00:00
|
|
|
int const i = InsetCollapsible::docbook(os, runparams);
|
2009-01-30 00:56:37 +00:00
|
|
|
os << "</" + cmdname + ">";
|
|
|
|
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-21 23:31:13 +00:00
|
|
|
docstring InsetPhantom::xhtml(XHTMLStream &, OutputParams const &) const
|
2009-06-12 17:23:17 +00:00
|
|
|
{
|
|
|
|
return docstring();
|
|
|
|
}
|
|
|
|
|
2011-10-29 14:48:55 +00:00
|
|
|
string InsetPhantom::contextMenuName() const
|
2009-01-30 00:56:37 +00:00
|
|
|
{
|
2011-10-29 14:48:55 +00:00
|
|
|
return "context-phantom";
|
2009-01-30 00:56:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
string InsetPhantom::params2string(InsetPhantomParams const & params)
|
|
|
|
{
|
|
|
|
ostringstream data;
|
|
|
|
data << "phantom" << ' ';
|
|
|
|
params.write(data);
|
|
|
|
return data.str();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void InsetPhantom::string2params(string const & in, InsetPhantomParams & params)
|
|
|
|
{
|
|
|
|
params = InsetPhantomParams();
|
|
|
|
|
|
|
|
if (in.empty())
|
|
|
|
return;
|
|
|
|
|
|
|
|
istringstream data(in);
|
|
|
|
Lexer lex;
|
|
|
|
lex.setStream(data);
|
|
|
|
lex.setContext("InsetPhantom::string2params");
|
|
|
|
lex >> "phantom" >> "Phantom";
|
|
|
|
|
|
|
|
params.read(lex);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace lyx
|