2003-11-28 15:53:34 +00:00
|
|
|
|
/**
|
|
|
|
|
* \file insetvspace.C
|
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
|
*
|
|
|
|
|
* \author various
|
|
|
|
|
* \author Andr<EFBFBD> P<EFBFBD>nitz
|
|
|
|
|
*
|
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
|
|
#include "insetvspace.h"
|
|
|
|
|
|
|
|
|
|
#include "buffer.h"
|
2004-01-20 14:25:24 +00:00
|
|
|
|
#include "cursor.h"
|
2003-11-28 17:38:39 +00:00
|
|
|
|
#include "dispatchresult.h"
|
|
|
|
|
#include "funcrequest.h"
|
|
|
|
|
#include "gettext.h"
|
2003-11-28 15:53:34 +00:00
|
|
|
|
#include "LColor.h"
|
|
|
|
|
#include "lyxlex.h"
|
|
|
|
|
#include "lyxtext.h"
|
|
|
|
|
#include "metricsinfo.h"
|
|
|
|
|
|
|
|
|
|
#include "frontends/font_metrics.h"
|
2003-11-28 17:38:39 +00:00
|
|
|
|
#include "frontends/Painter.h"
|
2003-11-28 15:53:34 +00:00
|
|
|
|
|
2004-07-24 10:55:30 +00:00
|
|
|
|
#include <sstream>
|
2003-11-28 15:53:34 +00:00
|
|
|
|
|
2006-08-13 22:54:59 +00:00
|
|
|
|
using lyx::docstring;
|
|
|
|
|
|
2003-11-28 15:53:34 +00:00
|
|
|
|
using std::istringstream;
|
|
|
|
|
using std::ostream;
|
|
|
|
|
using std::ostringstream;
|
|
|
|
|
using std::string;
|
|
|
|
|
using std::max;
|
|
|
|
|
|
|
|
|
|
|
2003-12-01 14:16:27 +00:00
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
|
|
int const ADD_TO_VSPACE_WIDTH = 5;
|
|
|
|
|
|
|
|
|
|
} // namespace anon
|
|
|
|
|
|
2003-11-28 15:53:34 +00:00
|
|
|
|
|
|
|
|
|
InsetVSpace::InsetVSpace(VSpace const & space)
|
|
|
|
|
: space_(space)
|
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
2003-11-28 17:38:39 +00:00
|
|
|
|
InsetVSpace::~InsetVSpace()
|
|
|
|
|
{
|
|
|
|
|
InsetVSpaceMailer(*this).hideDialog();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-11-23 23:04:52 +00:00
|
|
|
|
std::auto_ptr<InsetBase> InsetVSpace::doClone() const
|
2003-11-28 15:53:34 +00:00
|
|
|
|
{
|
|
|
|
|
return std::auto_ptr<InsetBase>(new InsetVSpace(*this));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-11-24 21:58:42 +00:00
|
|
|
|
void InsetVSpace::doDispatch(LCursor & cur, FuncRequest & cmd)
|
2003-11-28 17:38:39 +00:00
|
|
|
|
{
|
|
|
|
|
switch (cmd.action) {
|
|
|
|
|
|
|
|
|
|
case LFUN_INSET_MODIFY: {
|
2006-09-01 15:41:38 +00:00
|
|
|
|
InsetVSpaceMailer::string2params(lyx::to_utf8(cmd.argument()), space_);
|
2004-02-16 11:58:51 +00:00
|
|
|
|
break;
|
2003-11-28 17:38:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case LFUN_MOUSE_PRESS:
|
2004-01-20 14:25:24 +00:00
|
|
|
|
InsetVSpaceMailer(*this).showDialog(&cur.bv());
|
2004-02-16 11:58:51 +00:00
|
|
|
|
break;
|
2003-11-28 17:38:39 +00:00
|
|
|
|
|
|
|
|
|
default:
|
2004-11-25 19:13:07 +00:00
|
|
|
|
InsetBase::doDispatch(cur, cmd);
|
2004-02-16 11:58:51 +00:00
|
|
|
|
break;
|
2003-11-28 17:38:39 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2003-12-02 12:27:07 +00:00
|
|
|
|
|
2003-11-28 17:38:39 +00:00
|
|
|
|
|
2003-11-28 15:53:34 +00:00
|
|
|
|
void InsetVSpace::read(Buffer const &, LyXLex & lex)
|
|
|
|
|
{
|
2003-12-02 12:27:07 +00:00
|
|
|
|
BOOST_ASSERT(lex.isOK());
|
|
|
|
|
string vsp;
|
|
|
|
|
lex >> vsp;
|
|
|
|
|
if (lex)
|
|
|
|
|
space_ = VSpace(vsp);
|
2003-12-01 21:19:16 +00:00
|
|
|
|
|
2003-12-02 12:27:07 +00:00
|
|
|
|
string end_token;
|
|
|
|
|
lex >> end_token;
|
|
|
|
|
if (end_token != "\\end_inset")
|
2003-12-01 21:19:16 +00:00
|
|
|
|
lex.printError("Missing \\end_inset at this point. "
|
|
|
|
|
"Read: `$$Token'");
|
2003-11-28 15:53:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void InsetVSpace::write(Buffer const &, ostream & os) const
|
|
|
|
|
{
|
|
|
|
|
os << "VSpace " << space_.asLyXCommand();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2005-09-12 14:57:50 +00:00
|
|
|
|
string const InsetVSpace::label() const
|
|
|
|
|
{
|
2006-09-09 15:27:44 +00:00
|
|
|
|
// FIXME UNICODE
|
|
|
|
|
static string const label = lyx::to_utf8(_("Vertical Space"));
|
2005-09-12 14:57:50 +00:00
|
|
|
|
return label + " (" + space_.asGUIName() + ')';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
int const arrow_size = 4;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-11-28 15:53:34 +00:00
|
|
|
|
void InsetVSpace::metrics(MetricsInfo & mi, Dimension & dim) const
|
|
|
|
|
{
|
2005-10-19 20:01:49 +00:00
|
|
|
|
int height = 3 * arrow_size;
|
|
|
|
|
if (space_.length().len().value() >= 0.0)
|
|
|
|
|
height = max(height, space_.inPixels(*mi.base.bv));
|
2003-12-01 14:16:27 +00:00
|
|
|
|
|
|
|
|
|
LyXFont font;
|
|
|
|
|
font.decSize();
|
2005-10-19 20:01:49 +00:00
|
|
|
|
font.decSize();
|
2003-11-28 15:53:34 +00:00
|
|
|
|
|
2005-09-12 14:57:50 +00:00
|
|
|
|
int w = 0;
|
|
|
|
|
int a = 0;
|
|
|
|
|
int d = 0;
|
2006-09-09 15:27:44 +00:00
|
|
|
|
string lab = label();
|
|
|
|
|
docstring dlab(lab.begin(), lab.end());
|
2006-08-13 22:54:59 +00:00
|
|
|
|
font_metrics::rectText(dlab, font, w, a, d);
|
2003-11-28 15:53:34 +00:00
|
|
|
|
|
2005-10-19 20:01:49 +00:00
|
|
|
|
height = max(height, a + d);
|
|
|
|
|
|
|
|
|
|
dim.asc = height / 2 + (a - d) / 2; // align cursor with the
|
|
|
|
|
dim.des = height - dim.asc; // label text
|
|
|
|
|
dim.wid = ADD_TO_VSPACE_WIDTH + 2 * arrow_size + 5 + w;
|
2003-11-28 15:53:34 +00:00
|
|
|
|
dim_ = dim;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void InsetVSpace::draw(PainterInfo & pi, int x, int y) const
|
|
|
|
|
{
|
2004-01-30 11:41:12 +00:00
|
|
|
|
setPosCache(pi, x, y);
|
2003-11-28 15:53:34 +00:00
|
|
|
|
|
2003-12-01 14:16:27 +00:00
|
|
|
|
x += ADD_TO_VSPACE_WIDTH;
|
2003-11-28 15:53:34 +00:00
|
|
|
|
|
|
|
|
|
int const start = y - dim_.asc;
|
|
|
|
|
int const end = y + dim_.des;
|
|
|
|
|
|
|
|
|
|
// y-values for top arrow
|
|
|
|
|
int ty1, ty2;
|
|
|
|
|
// y-values for bottom arrow
|
|
|
|
|
int by1, by2;
|
|
|
|
|
|
|
|
|
|
if (space_.kind() == VSpace::VFILL) {
|
|
|
|
|
ty1 = ty2 = start;
|
|
|
|
|
by1 = by2 = end;
|
|
|
|
|
} else {
|
|
|
|
|
// adding or removing space
|
|
|
|
|
bool const added = space_.kind() != VSpace::LENGTH ||
|
2005-10-19 20:01:49 +00:00
|
|
|
|
space_.length().len().value() >= 0.0;
|
2003-11-28 15:53:34 +00:00
|
|
|
|
ty1 = added ? (start + arrow_size) : start;
|
|
|
|
|
ty2 = added ? start : (start + arrow_size);
|
|
|
|
|
by1 = added ? (end - arrow_size) : end;
|
|
|
|
|
by2 = added ? end : (end - arrow_size);
|
|
|
|
|
}
|
|
|
|
|
|
2003-12-01 14:16:27 +00:00
|
|
|
|
int const midx = x + arrow_size;
|
2003-11-28 15:53:34 +00:00
|
|
|
|
int const rightx = midx + arrow_size;
|
|
|
|
|
|
|
|
|
|
// first the string
|
|
|
|
|
int w = 0;
|
|
|
|
|
int a = 0;
|
|
|
|
|
int d = 0;
|
|
|
|
|
|
|
|
|
|
LyXFont font;
|
|
|
|
|
font.setColor(LColor::added_space);
|
|
|
|
|
font.decSize();
|
|
|
|
|
font.decSize();
|
2006-09-09 15:27:44 +00:00
|
|
|
|
string lab = label();
|
|
|
|
|
docstring dlab(lab.begin(), lab.end());
|
2006-08-13 22:54:59 +00:00
|
|
|
|
font_metrics::rectText(dlab, font, w, a, d);
|
2003-11-28 15:53:34 +00:00
|
|
|
|
|
2006-04-05 23:56:29 +00:00
|
|
|
|
pi.pain.rectText(x + 2 * arrow_size + 5,
|
2005-10-19 20:01:49 +00:00
|
|
|
|
start + (end - start) / 2 + (a - d) / 2,
|
2006-08-13 22:54:59 +00:00
|
|
|
|
dlab, font, LColor::none, LColor::none);
|
2003-11-28 15:53:34 +00:00
|
|
|
|
|
|
|
|
|
// top arrow
|
|
|
|
|
pi.pain.line(x, ty1, midx, ty2, LColor::added_space);
|
|
|
|
|
pi.pain.line(midx, ty2, rightx, ty1, LColor::added_space);
|
|
|
|
|
|
|
|
|
|
// bottom arrow
|
|
|
|
|
pi.pain.line(x, by1, midx, by2, LColor::added_space);
|
|
|
|
|
pi.pain.line(midx, by2, rightx, by1, LColor::added_space);
|
|
|
|
|
|
|
|
|
|
// joining line
|
|
|
|
|
pi.pain.line(midx, ty2, midx, by2, LColor::added_space);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int InsetVSpace::latex(Buffer const & buf, ostream & os,
|
|
|
|
|
OutputParams const &) const
|
|
|
|
|
{
|
|
|
|
|
os << space_.asLatexCommand(buf.params()) << '\n';
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int InsetVSpace::plaintext(Buffer const &, ostream & os,
|
|
|
|
|
OutputParams const &) const
|
|
|
|
|
{
|
|
|
|
|
os << "\n\n";
|
|
|
|
|
return 2;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int InsetVSpace::docbook(Buffer const &, std::ostream & os,
|
|
|
|
|
OutputParams const &) const
|
|
|
|
|
{
|
|
|
|
|
os << '\n';
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
string const InsetVSpaceMailer::name_ = "vspace";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
InsetVSpaceMailer::InsetVSpaceMailer(InsetVSpace & inset)
|
|
|
|
|
: inset_(inset)
|
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
string const InsetVSpaceMailer::inset2string(Buffer const &) const
|
|
|
|
|
{
|
2003-12-02 12:27:07 +00:00
|
|
|
|
return params2string(inset_.space());
|
2003-11-28 15:53:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void InsetVSpaceMailer::string2params(string const & in, VSpace & vspace)
|
|
|
|
|
{
|
|
|
|
|
vspace = VSpace();
|
|
|
|
|
if (in.empty())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
istringstream data(in);
|
|
|
|
|
LyXLex lex(0,0);
|
|
|
|
|
lex.setStream(data);
|
2003-12-11 15:23:15 +00:00
|
|
|
|
|
|
|
|
|
string name;
|
|
|
|
|
lex >> name;
|
|
|
|
|
if (!lex || name != name_)
|
|
|
|
|
return print_mailer_error("InsetVSpaceMailer", in, 1, name_);
|
|
|
|
|
|
|
|
|
|
string vsp;
|
|
|
|
|
lex >> vsp;
|
2003-12-02 10:19:51 +00:00
|
|
|
|
if (lex)
|
|
|
|
|
vspace = VSpace(vsp);
|
2003-11-28 15:53:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
string const InsetVSpaceMailer::params2string(VSpace const & vspace)
|
|
|
|
|
{
|
|
|
|
|
ostringstream data;
|
|
|
|
|
data << name_ << ' ' << vspace.asLyXCommand();
|
|
|
|
|
return data.str();
|
|
|
|
|
}
|