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"
|
|
|
|
#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()
|
|
|
|
{
|
|
|
|
static PhantomTranslator translator = init_phantomtranslator();
|
|
|
|
return translator;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
PhantomTranslatorLoc const & phantomtranslator_loc()
|
|
|
|
{
|
|
|
|
static PhantomTranslatorLoc translator = init_phantomtranslator_loc();
|
|
|
|
return translator;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // anon
|
|
|
|
|
|
|
|
|
|
|
|
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)
|
2009-01-30 00:56:37 +00:00
|
|
|
: InsetCollapsable(buf)
|
|
|
|
{
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
docstring InsetPhantom::name() const
|
|
|
|
{
|
|
|
|
return from_ascii("Phantom:" + phantomtranslator().find(params_.type));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void InsetPhantom::metrics(MetricsInfo & mi, Dimension & dim) const
|
|
|
|
{
|
2009-02-04 16:18:43 +00:00
|
|
|
InsetCollapsable::metrics(mi, dim);
|
2009-01-30 00:56:37 +00:00
|
|
|
|
|
|
|
// cache the inset dimension
|
|
|
|
setDimCache(mi, dim);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void InsetPhantom::draw(PainterInfo & pi, int x, int y) const
|
|
|
|
{
|
|
|
|
// draw the text
|
2009-02-04 16:18:43 +00:00
|
|
|
InsetCollapsable::draw(pi, x, y);
|
2009-02-01 18:48:48 +00:00
|
|
|
|
|
|
|
// draw the inset marker
|
|
|
|
drawMarkers(pi, x, y);
|
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);
|
2010-12-02 18:00:33 +00:00
|
|
|
Dimension const dim = Inset::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);
|
|
|
|
InsetCollapsable::write(os);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void InsetPhantom::read(Lexer & lex)
|
|
|
|
{
|
|
|
|
params_.read(lex);
|
|
|
|
InsetCollapsable::read(lex);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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:
|
2010-11-29 09:47:46 +00:00
|
|
|
cur.recordUndoInset(ATOMIC_UNDO, 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:
|
|
|
|
InsetCollapsable::doDispatch(cur, cmd);
|
|
|
|
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:
|
|
|
|
return InsetCollapsable::getStatus(cur, cmd, flag);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
Introduce a wrapper class for odocstream to help ensuring that no
blank lines may be inadvertently output. This is achieved by using two
special iomanip-like variables (breakln and safebreakln) in the lyx::
namespace. When they are inserted in the stream, a newline is output
only if not already at the beginning of a line. The difference between
breakln and safebreakln is that, if needed, the former outputs '\n'
and the latter "%\n".
In future, the new class will also be used for counting the number of
newlines issued. Even if the infractrure for doing that is already in
place, the counting is essentially still done the old way.
There are still places in the code where the functionality of the
class could be used, most probably. ATM, it is used for InsetTabular,
InsetListings, InsetFloat, and InsetText.
The Comment and GreyedOut insets required a special treatment and a
new InsetLayout parameter (Display) has been introduced. The default
for Display is "true", meaning that the corresponding latex
environment is of "display" type, i.e., it stands on its own, whereas
"false" means that the contents appear inline with the text. The
latter is the case for both Comment and GreyedOut insets.
Mostly, the only visible effects on latex exports should be the
disappearing of some redundant % chars and the appearing/disappearing
of null {} latex groups after a comment or lyxgreyedout environments
(they are related to the presence or absence of a space immediately
after those environments), as well as the fact that math environments
are now started on their own lines.
As a last thing, only the latex code between \begin{document} and
\end{document} goes through the new class, the preamble being directly
output through odocstream, as usual.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@37360 a592a061-630c-0410-9148-cb99ea01b6c8
2011-01-29 02:41:13 +00:00
|
|
|
int InsetPhantom::latex(otexstream & os, OutputParams const & runparams) const
|
2009-01-30 00:56:37 +00:00
|
|
|
{
|
|
|
|
if (params_.type == InsetPhantomParams::Phantom)
|
|
|
|
os << "\\phantom{";
|
|
|
|
else if (params_.type == InsetPhantomParams::HPhantom)
|
|
|
|
os << "\\hphantom{";
|
|
|
|
else if (params_.type == InsetPhantomParams::VPhantom)
|
|
|
|
os << "\\vphantom{";
|
2009-02-04 16:18:43 +00:00
|
|
|
int const i = InsetCollapsable::latex(os, runparams);
|
2009-01-30 00:56:37 +00:00
|
|
|
os << "}";
|
|
|
|
|
2009-02-04 16:18:43 +00:00
|
|
|
return i;
|
2009-01-30 00:56:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int InsetPhantom::plaintext(odocstream & os,
|
2009-02-04 16:18:43 +00:00
|
|
|
OutputParams const & runparams) const
|
2009-01-30 00:56:37 +00:00
|
|
|
{
|
|
|
|
if (params_.type == InsetPhantomParams::Phantom)
|
|
|
|
os << '[' << buffer().B_("phantom") << ":";
|
|
|
|
else if (params_.type == InsetPhantomParams::HPhantom)
|
|
|
|
os << '[' << buffer().B_("hphantom") << ":";
|
|
|
|
else if (params_.type == InsetPhantomParams::VPhantom)
|
|
|
|
os << '[' << buffer().B_("vphantom") << ":";
|
2009-02-04 16:18:43 +00:00
|
|
|
InsetCollapsable::plaintext(os, runparams);
|
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
|
|
|
{
|
|
|
|
string cmdname;
|
|
|
|
if (params_.type == InsetPhantomParams::Phantom)
|
|
|
|
cmdname = "phantom";
|
|
|
|
else if (params_.type == InsetPhantomParams::HPhantom)
|
|
|
|
cmdname = "phantom";
|
|
|
|
else if (params_.type == InsetPhantomParams::VPhantom)
|
|
|
|
cmdname = "phantom";
|
|
|
|
os << "<" + cmdname + ">";
|
2009-02-04 16:18:43 +00:00
|
|
|
int const i = InsetCollapsable::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();
|
|
|
|
}
|
|
|
|
|
2010-11-29 21:27:25 +00:00
|
|
|
docstring InsetPhantom::contextMenuName() const
|
2009-01-30 00:56:37 +00:00
|
|
|
{
|
|
|
|
return from_ascii("context-phantom");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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
|