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"
|
2010-09-07 00:41:00 +00:00
|
|
|
#include "Length.h"
|
2008-06-18 18:54:31 +00:00
|
|
|
#include "MetricsInfo.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
#include "OutputParams.h"
|
2009-11-25 22:07:17 +00:00
|
|
|
#include "output_xhtml.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"
|
|
|
|
#include "support/lstrings.h"
|
2006-10-21 00:16:43 +00:00
|
|
|
|
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)
|
2010-10-29 00:46:21 +00:00
|
|
|
: InsetCommand(buf, p)
|
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")));
|
2010-09-15 11:19:29 +00:00
|
|
|
dim.wid = width.inPixels(max_width, fm.width(char_type('M')));
|
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;
|
|
|
|
dim.wid = max(minw, max(dim.wid, -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")));
|
|
|
|
height_ = height.inPixels(dim.height(), fm.width(char_type('M')));
|
|
|
|
|
|
|
|
// get the length of the parameters in pixels
|
|
|
|
Length offset = Length(to_ascii(getParam("offset")));
|
|
|
|
offset_ = offset.inPixels(max_width, fm.width(char_type('M')));
|
|
|
|
|
2010-09-16 10:40:19 +00:00
|
|
|
dim.asc = max(fm.maxAscent(), offset_ + height_);
|
|
|
|
dim.des = max(fm.maxDescent(), - offset_);
|
2010-09-16 07:36:20 +00:00
|
|
|
|
2010-09-07 00:41:00 +00:00
|
|
|
// Cache the inset dimension
|
2007-09-25 07:07:11 +00:00
|
|
|
setDimCache(mi, dim);
|
2003-10-27 12:41:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-09-15 12:43:07 +00:00
|
|
|
Dimension const InsetLine::dimension(BufferView const & bv) const
|
|
|
|
{
|
|
|
|
// We cannot use InsetCommand::dimension() as this returns the dimension
|
|
|
|
// of the button, which is not used here.
|
|
|
|
return Inset::dimension(bv);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
|
Color Line_color = pi.base.font.realColor();
|
|
|
|
|
2010-09-07 00:41:00 +00:00
|
|
|
// the offset is a vertical one
|
2010-09-16 07:36:20 +00:00
|
|
|
// the horizontal dimension must be corrected with the heigth because
|
|
|
|
// of left and right border of the painted line for big heigth.
|
|
|
|
pi.pain.line(x + height_/2 + 1,
|
|
|
|
y - offset_ - height_/2,
|
|
|
|
x + dim.wid - height_/2 - 2,
|
|
|
|
y - offset_ - height_/2,
|
|
|
|
Line_color, Painter::line_solid, float(height_));
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
int InsetLine::plaintext(odocstream & os, OutputParams const &) 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
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
int InsetLine::docbook(odocstream & os, OutputParams const &) const
|
2003-10-27 12:41:26 +00:00
|
|
|
{
|
|
|
|
os << '\n';
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-25 22:07:17 +00:00
|
|
|
docstring InsetLine::xhtml(XHTMLStream & xs, OutputParams const &) const
|
2009-06-05 17:48:14 +00:00
|
|
|
{
|
2011-04-01 19:18:25 +00:00
|
|
|
xs << html::CompTag("hr") << html::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
|