2003-10-27 12:41:26 +00:00
|
|
|
/**
|
2007-04-25 01:24:38 +00:00
|
|
|
* \file InsetLine.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.
|
|
|
|
*
|
2010-09-17 01:28:08 +00:00
|
|
|
* \author Abdelrazak Younes
|
2008-11-14 15:58:50 +00:00
|
|
|
* \author André Pönitz
|
2010-09-07 00:41:00 +00:00
|
|
|
* \author Uwe Stöhr
|
2003-10-27 12:41:26 +00:00
|
|
|
*
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
2007-04-25 01:24:38 +00:00
|
|
|
#include "InsetLine.h"
|
2003-10-27 12:41:26 +00:00
|
|
|
|
2010-09-07 00:41:00 +00:00
|
|
|
#include "Buffer.h"
|
2010-10-31 01:04:03 +00:00
|
|
|
#include "Cursor.h"
|
2007-11-01 22:17:22 +00:00
|
|
|
#include "Dimension.h"
|
2010-09-07 00:41:00 +00:00
|
|
|
#include "DispatchResult.h"
|
|
|
|
#include "FuncRequest.h"
|
|
|
|
#include "FuncStatus.h"
|
2003-10-27 12:41:26 +00:00
|
|
|
#include "LaTeXFeatures.h"
|
2008-06-18 18:54:31 +00:00
|
|
|
#include "MetricsInfo.h"
|
2020-07-09 15:19:01 +00:00
|
|
|
#include "output_docbook.h"
|
2009-11-25 22:07:17 +00:00
|
|
|
#include "output_xhtml.h"
|
2016-06-19 02:39:38 +00:00
|
|
|
#include "texstream.h"
|
2007-10-28 18:51:54 +00:00
|
|
|
#include "Text.h"
|
2003-10-27 12:41:26 +00:00
|
|
|
|
2010-09-07 00:41:00 +00:00
|
|
|
#include "frontends/FontMetrics.h"
|
2008-02-18 07:14:42 +00:00
|
|
|
#include "frontends/Painter.h"
|
|
|
|
|
|
|
|
#include "support/debug.h"
|
2007-11-01 22:17:22 +00:00
|
|
|
#include "support/docstream.h"
|
2010-09-07 00:41:00 +00:00
|
|
|
#include "support/gettext.h"
|
2020-08-03 12:15:09 +00:00
|
|
|
#include "support/Length.h"
|
2010-09-07 00:41:00 +00:00
|
|
|
#include "support/lstrings.h"
|
2006-10-21 00:16:43 +00:00
|
|
|
|
2012-10-28 08:20:23 +00:00
|
|
|
#include <cstdlib>
|
|
|
|
|
2007-12-12 10:16:00 +00:00
|
|
|
using namespace std;
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
namespace lyx {
|
|
|
|
|
|
|
|
using frontend::Painter;
|
2006-06-20 08:39:16 +00:00
|
|
|
|
2003-10-27 12:41:26 +00:00
|
|
|
|
2010-09-07 00:41:00 +00:00
|
|
|
InsetLine::InsetLine(Buffer * buf, InsetCommandParams const & p)
|
2015-09-13 17:47:21 +00:00
|
|
|
: InsetCommand(buf, p), height_(0), offset_(0)
|
2010-09-07 00:41:00 +00:00
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
|
ParamInfo const & InsetLine::findInfo(string const & /* cmdName */)
|
2003-10-27 12:41:26 +00:00
|
|
|
{
|
2010-09-07 00:41:00 +00:00
|
|
|
static ParamInfo param_info_;
|
|
|
|
if (param_info_.empty()) {
|
|
|
|
param_info_.add("offset", ParamInfo::LYX_INTERNAL);
|
|
|
|
param_info_.add("width", ParamInfo::LYX_INTERNAL);
|
|
|
|
param_info_.add("height", ParamInfo::LYX_INTERNAL);
|
|
|
|
}
|
|
|
|
return param_info_;
|
2003-10-27 12:41:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-09-07 00:41:00 +00:00
|
|
|
docstring InsetLine::screenLabel() const
|
2003-10-27 12:41:26 +00:00
|
|
|
{
|
2010-09-07 00:41:00 +00:00
|
|
|
return _("Horizontal line");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void InsetLine::doDispatch(Cursor & cur, FuncRequest & cmd)
|
|
|
|
{
|
|
|
|
switch (cmd.action()) {
|
|
|
|
|
|
|
|
case LFUN_INSET_MODIFY: {
|
|
|
|
InsetCommandParams p(LINE_CODE);
|
|
|
|
// FIXME UNICODE
|
2010-10-29 00:25:28 +00:00
|
|
|
InsetCommand::string2params(to_utf8(cmd.argument()), p);
|
2010-09-07 00:41:00 +00:00
|
|
|
if (p.getCmdName().empty()) {
|
|
|
|
cur.noScreenUpdate();
|
|
|
|
break;
|
|
|
|
}
|
2010-12-08 09:24:04 +00:00
|
|
|
cur.recordUndo();
|
2010-09-07 00:41:00 +00:00
|
|
|
setParams(p);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
InsetCommand::doDispatch(cur, cmd);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool InsetLine::getStatus(Cursor & cur, FuncRequest const & cmd,
|
|
|
|
FuncStatus & status) const
|
|
|
|
{
|
|
|
|
switch (cmd.action()) {
|
|
|
|
case LFUN_INSET_DIALOG_UPDATE:
|
|
|
|
case LFUN_INSET_MODIFY:
|
|
|
|
status.setEnabled(true);
|
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
return InsetCommand::getStatus(cur, cmd, status);
|
|
|
|
}
|
2003-10-27 12:41:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-09-21 20:39:47 +00:00
|
|
|
void InsetLine::metrics(MetricsInfo & mi, Dimension & dim) const
|
2003-10-27 12:41:26 +00:00
|
|
|
{
|
2010-09-07 00:41:00 +00:00
|
|
|
frontend::FontMetrics const & fm = theFontMetrics(mi.base.font);
|
2010-09-15 11:19:29 +00:00
|
|
|
int const max_width = mi.base.textwidth;
|
2010-09-07 13:37:22 +00:00
|
|
|
|
2010-09-14 13:42:09 +00:00
|
|
|
Length const width(to_ascii(getParam("width")));
|
2018-01-05 18:59:31 +00:00
|
|
|
dim.wid = mi.base.inPixels(width);
|
2010-09-07 00:41:00 +00:00
|
|
|
|
|
|
|
// assure that the line inset is not outside of the window
|
|
|
|
// check that it doesn't exceed the outer boundary
|
2010-09-15 11:19:29 +00:00
|
|
|
if (dim.wid > max_width)
|
|
|
|
dim.wid = max_width;
|
2010-09-07 00:41:00 +00:00
|
|
|
|
|
|
|
// set a minimal width
|
2010-09-15 11:19:29 +00:00
|
|
|
int const minw = (dim.wid < 0) ? 24 : 4;
|
2012-10-26 08:56:53 +00:00
|
|
|
dim.wid = max(minw, abs(dim.wid));
|
2010-09-07 00:41:00 +00:00
|
|
|
|
2010-09-16 07:36:20 +00:00
|
|
|
Length height = Length(to_ascii(getParam("height")));
|
2018-01-05 18:59:31 +00:00
|
|
|
height_ = mi.base.inPixels(height);
|
2010-09-16 07:36:20 +00:00
|
|
|
|
|
|
|
// get the length of the parameters in pixels
|
|
|
|
Length offset = Length(to_ascii(getParam("offset")));
|
2018-01-05 18:59:31 +00:00
|
|
|
offset_ = mi.base.inPixels(offset);
|
2010-09-16 07:36:20 +00:00
|
|
|
|
2010-09-16 10:40:19 +00:00
|
|
|
dim.asc = max(fm.maxAscent(), offset_ + height_);
|
|
|
|
dim.des = max(fm.maxDescent(), - offset_);
|
2003-10-27 12:41:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void InsetLine::draw(PainterInfo & pi, int x, int y) const
|
|
|
|
{
|
2010-09-15 12:43:07 +00:00
|
|
|
Dimension const dim = dimension(*pi.base.bv);
|
2010-09-15 11:19:29 +00:00
|
|
|
|
2010-09-15 12:43:07 +00:00
|
|
|
// get the surrounding text color
|
2021-06-14 13:36:45 +00:00
|
|
|
Color line_color = pi.base.font.realColor();
|
2010-09-15 12:43:07 +00:00
|
|
|
|
2010-09-07 00:41:00 +00:00
|
|
|
// the offset is a vertical one
|
2021-06-14 13:36:45 +00:00
|
|
|
pi.pain.fillRectangle(x, y - offset_ - height_, dim.wid, height_, line_color);
|
2003-10-27 12:41:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-02-10 20:02:48 +00:00
|
|
|
void InsetLine::latex(otexstream & os, OutputParams const &) const
|
2003-10-27 12:41:26 +00:00
|
|
|
{
|
2010-09-07 00:41:00 +00:00
|
|
|
bool have_offset = true;
|
|
|
|
Length offset_len = Length(to_ascii(getParam("offset")));
|
|
|
|
if (offset_len.value() == 0)
|
|
|
|
have_offset = false;
|
|
|
|
|
|
|
|
string const offset =
|
|
|
|
Length(to_ascii(getParam("offset"))).asLatexString();
|
|
|
|
string const width =
|
|
|
|
Length(to_ascii(getParam("width"))).asLatexString();
|
|
|
|
string const height =
|
|
|
|
Length(to_ascii(getParam("height"))).asLatexString();
|
|
|
|
|
|
|
|
os << "\\rule";
|
|
|
|
// only output the optional parameter if the offset is not 0
|
|
|
|
if (have_offset)
|
|
|
|
os << "[" << from_ascii(offset) << "]";
|
|
|
|
os << "{" << from_ascii(width) << "}{" << from_ascii(height) << '}';
|
2003-10-27 12:41:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-03-08 19:52:18 +00:00
|
|
|
int InsetLine::plaintext(odocstringstream & os,
|
|
|
|
OutputParams const &, size_t) const
|
2003-10-27 12:41:26 +00:00
|
|
|
{
|
2007-02-15 22:27:45 +00:00
|
|
|
os << "\n-------------------------------------------\n";
|
2007-02-20 17:52:41 +00:00
|
|
|
return PLAINTEXT_NEWLINE;
|
2003-10-27 12:41:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-06-08 21:27:49 +00:00
|
|
|
void InsetLine::docbook(XMLStream & xs, OutputParams const &) const
|
2003-10-27 12:41:26 +00:00
|
|
|
{
|
2020-06-08 21:27:49 +00:00
|
|
|
xs << xml::CR();
|
2003-10-27 12:41:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-09 23:35:40 +00:00
|
|
|
docstring InsetLine::xhtml(XMLStream & xs, OutputParams const &) const
|
2009-06-05 17:48:14 +00:00
|
|
|
{
|
2019-05-09 23:35:40 +00:00
|
|
|
xs << xml::CompTag("hr") << xml::CR();
|
2009-06-12 17:23:17 +00:00
|
|
|
return docstring();
|
2009-06-05 17:48:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
} // namespace lyx
|