2003-11-28 15:53:34 +00:00
|
|
|
/**
|
2007-04-25 01:24:38 +00:00
|
|
|
* \file InsetVSpace.cpp
|
2003-11-28 15:53:34 +00:00
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
*
|
|
|
|
* \author various
|
2008-11-14 15:58:50 +00:00
|
|
|
* \author André Pönitz
|
2003-11-28 15:53:34 +00:00
|
|
|
*
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
2007-04-25 01:24:38 +00:00
|
|
|
#include "InsetVSpace.h"
|
2003-11-28 15:53:34 +00:00
|
|
|
|
2007-04-26 04:41:58 +00:00
|
|
|
#include "Buffer.h"
|
2008-03-27 00:21:35 +00:00
|
|
|
#include "BufferView.h"
|
2007-04-26 14:56:30 +00:00
|
|
|
#include "Cursor.h"
|
2007-11-01 22:17:22 +00:00
|
|
|
#include "Dimension.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
#include "DispatchResult.h"
|
|
|
|
#include "FuncRequest.h"
|
2008-03-24 13:33:48 +00:00
|
|
|
#include "FuncStatus.h"
|
2007-04-26 11:30:54 +00:00
|
|
|
#include "Lexer.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
#include "MetricsInfo.h"
|
|
|
|
#include "OutputParams.h"
|
2009-11-21 23:02:59 +00:00
|
|
|
#include "output_xhtml.h"
|
2008-06-18 18:54:31 +00:00
|
|
|
#include "Text.h"
|
2003-11-28 15:53:34 +00:00
|
|
|
|
2008-03-27 00:21:35 +00:00
|
|
|
#include "support/debug.h"
|
2009-11-21 23:16:04 +00:00
|
|
|
#include "support/docstream.h"
|
2008-03-27 00:21:35 +00:00
|
|
|
#include "support/gettext.h"
|
2008-06-18 18:54:31 +00:00
|
|
|
#include "support/lassert.h"
|
2008-03-27 00:21:35 +00:00
|
|
|
|
|
|
|
#include "frontends/Application.h"
|
2006-10-07 16:15:06 +00:00
|
|
|
#include "frontends/FontMetrics.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
|
|
|
|
2007-12-12 10:16:00 +00:00
|
|
|
using namespace std;
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
namespace lyx {
|
2006-08-13 22:54:59 +00:00
|
|
|
|
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)
|
2009-11-08 15:53:21 +00:00
|
|
|
: Inset(0), space_(space)
|
2003-11-28 15:53:34 +00:00
|
|
|
{}
|
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
void InsetVSpace::doDispatch(Cursor & cur, FuncRequest & cmd)
|
2003-11-28 17:38:39 +00:00
|
|
|
{
|
2010-04-09 19:00:42 +00:00
|
|
|
switch (cmd.action()) {
|
2003-11-28 17:38:39 +00:00
|
|
|
|
|
|
|
case LFUN_INSET_MODIFY: {
|
2010-11-29 09:47:46 +00:00
|
|
|
cur.recordUndo();
|
2008-03-27 00:21:35 +00:00
|
|
|
InsetVSpace::string2params(to_utf8(cmd.argument()), space_);
|
2004-02-16 11:58:51 +00:00
|
|
|
break;
|
2003-11-28 17:38:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
2007-04-29 13:39:47 +00:00
|
|
|
Inset::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
|
|
|
|
2008-03-24 13:33:48 +00:00
|
|
|
bool InsetVSpace::getStatus(Cursor & cur, FuncRequest const & cmd,
|
|
|
|
FuncStatus & status) const
|
|
|
|
{
|
2010-04-09 19:00:42 +00:00
|
|
|
switch (cmd.action()) {
|
2008-03-24 13:33:48 +00:00
|
|
|
// we handle these
|
|
|
|
case LFUN_INSET_MODIFY:
|
|
|
|
if (cmd.getArg(0) == "vspace") {
|
|
|
|
VSpace vspace;
|
2008-03-27 00:21:35 +00:00
|
|
|
InsetVSpace::string2params(to_utf8(cmd.argument()), vspace);
|
2008-03-24 13:33:48 +00:00
|
|
|
status.setOnOff(vspace == space_);
|
2008-05-26 10:23:07 +00:00
|
|
|
}
|
2008-05-29 15:14:00 +00:00
|
|
|
status.setEnabled(true);
|
2008-03-24 13:33:48 +00:00
|
|
|
return true;
|
2009-04-10 00:20:12 +00:00
|
|
|
|
2008-03-24 13:33:48 +00:00
|
|
|
default:
|
|
|
|
return Inset::getStatus(cur, cmd, status);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
void InsetVSpace::read(Lexer & lex)
|
2003-11-28 15:53:34 +00:00
|
|
|
{
|
2008-04-10 21:49:34 +00:00
|
|
|
LASSERT(lex.isOK(), /**/);
|
2003-12-02 12:27:07 +00:00
|
|
|
string vsp;
|
|
|
|
lex >> vsp;
|
2007-03-26 13:43:49 +00:00
|
|
|
if (lex)
|
2003-12-02 12:27:07 +00:00
|
|
|
space_ = VSpace(vsp);
|
2008-04-05 21:24:57 +00:00
|
|
|
lex >> "\\end_inset";
|
2003-11-28 15:53:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
void InsetVSpace::write(ostream & os) const
|
2003-11-28 15:53:34 +00:00
|
|
|
{
|
|
|
|
os << "VSpace " << space_.asLyXCommand();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-11-11 20:55:40 +00:00
|
|
|
docstring const InsetVSpace::label() const
|
2005-09-12 14:57:50 +00:00
|
|
|
{
|
2006-11-11 20:55:40 +00:00
|
|
|
static docstring const label = _("Vertical Space");
|
2006-11-11 20:59:04 +00:00
|
|
|
return label + " (" + space_.asGUIName() + ')';
|
2005-09-12 14:57:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
namespace {
|
2008-08-13 21:39:59 +00:00
|
|
|
int const vspace_arrow_size = 4;
|
2005-09-12 14:57:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-09-21 20:39:47 +00:00
|
|
|
void InsetVSpace::metrics(MetricsInfo & mi, Dimension & dim) const
|
2003-11-28 15:53:34 +00:00
|
|
|
{
|
2008-08-13 21:39:59 +00:00
|
|
|
int height = 3 * vspace_arrow_size;
|
2005-10-19 20:01:49 +00:00
|
|
|
if (space_.length().len().value() >= 0.0)
|
|
|
|
height = max(height, space_.inPixels(*mi.base.bv));
|
2003-12-01 14:16:27 +00:00
|
|
|
|
2007-10-28 18:51:54 +00:00
|
|
|
FontInfo font;
|
2003-12-01 14:16:27 +00:00
|
|
|
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-11-11 20:55:40 +00:00
|
|
|
theFontMetrics(font).rectText(label(), 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
|
2008-08-13 21:39:59 +00:00
|
|
|
dim.wid = ADD_TO_VSPACE_WIDTH + 2 * vspace_arrow_size + 5 + w;
|
2007-09-25 07:41:03 +00:00
|
|
|
// Cache the inset dimension.
|
|
|
|
setDimCache(mi, dim);
|
2003-11-28 15:53:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void InsetVSpace::draw(PainterInfo & pi, int x, int y) const
|
|
|
|
{
|
2007-09-25 07:41:03 +00:00
|
|
|
Dimension const dim = dimension(*pi.base.bv);
|
2003-12-01 14:16:27 +00:00
|
|
|
x += ADD_TO_VSPACE_WIDTH;
|
2007-09-25 07:41:03 +00:00
|
|
|
int const start = y - dim.asc;
|
|
|
|
int const end = y + dim.des;
|
2003-11-28 15:53:34 +00:00
|
|
|
|
|
|
|
// 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;
|
2008-08-13 21:39:59 +00:00
|
|
|
ty1 = added ? (start + vspace_arrow_size) : start;
|
|
|
|
ty2 = added ? start : (start + vspace_arrow_size);
|
|
|
|
by1 = added ? (end - vspace_arrow_size) : end;
|
|
|
|
by2 = added ? end : (end - vspace_arrow_size);
|
2003-11-28 15:53:34 +00:00
|
|
|
}
|
|
|
|
|
2008-08-13 21:39:59 +00:00
|
|
|
int const midx = x + vspace_arrow_size;
|
|
|
|
int const rightx = midx + vspace_arrow_size;
|
2003-11-28 15:53:34 +00:00
|
|
|
|
|
|
|
// first the string
|
|
|
|
int w = 0;
|
|
|
|
int a = 0;
|
|
|
|
int d = 0;
|
|
|
|
|
2007-10-28 18:51:54 +00:00
|
|
|
FontInfo font;
|
2007-10-25 12:41:02 +00:00
|
|
|
font.setColor(Color_added_space);
|
2003-11-28 15:53:34 +00:00
|
|
|
font.decSize();
|
|
|
|
font.decSize();
|
2006-11-11 20:55:40 +00:00
|
|
|
docstring const lab = label();
|
|
|
|
theFontMetrics(font).rectText(lab, w, a, d);
|
2003-11-28 15:53:34 +00:00
|
|
|
|
2008-08-13 21:39:59 +00:00
|
|
|
pi.pain.rectText(x + 2 * vspace_arrow_size + 5,
|
2005-10-19 20:01:49 +00:00
|
|
|
start + (end - start) / 2 + (a - d) / 2,
|
2007-10-25 12:41:02 +00:00
|
|
|
lab, font, Color_none, Color_none);
|
2003-11-28 15:53:34 +00:00
|
|
|
|
|
|
|
// top arrow
|
2007-10-25 12:41:02 +00:00
|
|
|
pi.pain.line(x, ty1, midx, ty2, Color_added_space);
|
|
|
|
pi.pain.line(midx, ty2, rightx, ty1, Color_added_space);
|
2003-11-28 15:53:34 +00:00
|
|
|
|
|
|
|
// bottom arrow
|
2007-10-25 12:41:02 +00:00
|
|
|
pi.pain.line(x, by1, midx, by2, Color_added_space);
|
|
|
|
pi.pain.line(midx, by2, rightx, by1, Color_added_space);
|
2003-11-28 15:53:34 +00:00
|
|
|
|
|
|
|
// joining line
|
2007-10-25 12:41:02 +00:00
|
|
|
pi.pain.line(midx, ty2, midx, by2, Color_added_space);
|
2003-11-28 15:53:34 +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 InsetVSpace::latex(otexstream & os, OutputParams const &) const
|
2003-11-28 15:53:34 +00:00
|
|
|
{
|
2008-02-27 20:43:16 +00:00
|
|
|
os << from_ascii(space_.asLatexCommand(buffer().params())) << '\n';
|
2003-11-28 15:53:34 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
int InsetVSpace::plaintext(odocstream & os, OutputParams const &) const
|
2003-11-28 15:53:34 +00:00
|
|
|
{
|
|
|
|
os << "\n\n";
|
2007-02-20 17:52:41 +00:00
|
|
|
return PLAINTEXT_NEWLINE;
|
2003-11-28 15:53:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
int InsetVSpace::docbook(odocstream & os, OutputParams const &) const
|
2003-11-28 15:53:34 +00:00
|
|
|
{
|
|
|
|
os << '\n';
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-21 23:16:04 +00:00
|
|
|
docstring InsetVSpace::xhtml(XHTMLStream &, OutputParams const &) const
|
2009-06-12 15:07:04 +00:00
|
|
|
{
|
2009-11-21 23:16:04 +00:00
|
|
|
odocstringstream ods;
|
|
|
|
XHTMLStream xds(ods);
|
|
|
|
string const len = space_.asHTMLLength();
|
|
|
|
string const attr = "style='height:" + (len.empty() ? "1em" : len) + "'";
|
2010-01-19 22:08:04 +00:00
|
|
|
xds << html::StartTag("div", attr, true) << html::EndTag("div");
|
2009-11-30 17:20:10 +00:00
|
|
|
return ods.str();
|
2009-06-12 15:07:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-11-29 21:27:25 +00:00
|
|
|
docstring InsetVSpace::contextMenuName() const
|
2008-03-24 13:33:48 +00:00
|
|
|
{
|
|
|
|
return from_ascii("context-vspace");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-03-27 00:21:35 +00:00
|
|
|
void InsetVSpace::string2params(string const & in, VSpace & vspace)
|
2003-11-28 15:53:34 +00:00
|
|
|
{
|
|
|
|
vspace = VSpace();
|
|
|
|
if (in.empty())
|
|
|
|
return;
|
|
|
|
|
|
|
|
istringstream data(in);
|
2008-04-02 23:06:22 +00:00
|
|
|
Lexer lex;
|
2003-11-28 15:53:34 +00:00
|
|
|
lex.setStream(data);
|
2008-04-05 10:34:29 +00:00
|
|
|
lex.setContext("InsetVSpace::string2params");
|
|
|
|
lex >> "vspace" >> vspace;
|
2003-11-28 15:53:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-03-27 00:21:35 +00:00
|
|
|
string InsetVSpace::params2string(VSpace const & vspace)
|
2003-11-28 15:53:34 +00:00
|
|
|
{
|
|
|
|
ostringstream data;
|
2008-03-27 00:21:35 +00:00
|
|
|
data << "vspace" << ' ' << vspace.asLyXCommand();
|
2003-11-28 15:53:34 +00:00
|
|
|
return data.str();
|
|
|
|
}
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
} // namespace lyx
|