2002-09-10 10:18:58 +00:00
|
|
|
/**
|
2007-04-25 01:24:38 +00:00
|
|
|
* \file InsetWrap.cpp
|
2002-09-10 10:18:58 +00:00
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
*
|
|
|
|
* \author Dekel Tsur
|
2008-11-14 15:58:50 +00:00
|
|
|
* \author Uwe Stöhr
|
2002-09-10 10:18:58 +00:00
|
|
|
*
|
2003-08-23 00:17:00 +00:00
|
|
|
* Full author contact details are available in file CREDITS.
|
2002-09-10 10:18:58 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
2007-04-25 01:24:38 +00:00
|
|
|
#include "InsetWrap.h"
|
2008-04-10 09:22:49 +00:00
|
|
|
#include "InsetCaption.h"
|
2003-03-05 23:19:45 +00:00
|
|
|
|
2007-04-26 04:41:58 +00:00
|
|
|
#include "Buffer.h"
|
|
|
|
#include "BufferParams.h"
|
2003-03-05 23:19:45 +00:00
|
|
|
#include "BufferView.h"
|
2007-08-12 21:43:58 +00:00
|
|
|
#include "Counters.h"
|
2007-04-26 14:56:30 +00:00
|
|
|
#include "Cursor.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
#include "DispatchResult.h"
|
2003-09-04 03:54:04 +00:00
|
|
|
#include "Floating.h"
|
2003-03-05 23:19:45 +00:00
|
|
|
#include "FloatList.h"
|
2007-04-26 04:41:58 +00:00
|
|
|
#include "FuncRequest.h"
|
2005-04-22 08:57:22 +00:00
|
|
|
#include "FuncStatus.h"
|
2003-03-05 23:19:45 +00:00
|
|
|
#include "LaTeXFeatures.h"
|
2007-04-26 11:30:54 +00:00
|
|
|
#include "Lexer.h"
|
2009-11-21 22:57:40 +00:00
|
|
|
#include "output_xhtml.h"
|
2007-11-07 23:25:08 +00:00
|
|
|
#include "TextClass.h"
|
2003-03-05 23:19:45 +00:00
|
|
|
|
2008-02-18 07:14:42 +00:00
|
|
|
#include "support/debug.h"
|
2008-06-18 18:54:31 +00:00
|
|
|
#include "support/docstream.h"
|
2008-02-18 07:14:42 +00:00
|
|
|
#include "support/gettext.h"
|
2003-09-05 09:01:27 +00:00
|
|
|
|
2008-03-27 00:07:54 +00:00
|
|
|
#include "frontends/Application.h"
|
|
|
|
|
2007-12-12 10:16:00 +00:00
|
|
|
using namespace std;
|
2006-10-21 00:16:43 +00:00
|
|
|
|
2006-09-09 18:52:00 +00:00
|
|
|
|
2008-04-03 22:39:06 +00:00
|
|
|
namespace lyx {
|
2003-05-13 16:24:49 +00:00
|
|
|
|
2009-11-08 15:53:21 +00:00
|
|
|
InsetWrap::InsetWrap(Buffer * buf, string const & type)
|
2008-04-03 22:39:06 +00:00
|
|
|
: InsetCollapsable(buf)
|
2002-09-10 10:18:58 +00:00
|
|
|
{
|
2009-07-13 12:56:20 +00:00
|
|
|
setLabel(_("wrap: ") + floatName(type));
|
2003-03-05 23:19:45 +00:00
|
|
|
params_.type = type;
|
2007-09-24 13:43:58 +00:00
|
|
|
params_.lines = 0;
|
|
|
|
params_.placement = "o";
|
|
|
|
params_.overhang = Length(0, Length::PCW);
|
2007-04-28 12:58:49 +00:00
|
|
|
params_.width = Length(50, Length::PCW);
|
2002-09-10 10:18:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
InsetWrap::~InsetWrap()
|
|
|
|
{
|
2008-03-28 18:48:01 +00:00
|
|
|
hideDialogs("wrap", this);
|
2002-09-10 10:18:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-04-03 22:39:06 +00:00
|
|
|
docstring InsetWrap::name() const
|
|
|
|
{
|
2008-12-16 15:34:32 +00:00
|
|
|
return "Wrap:" + from_utf8(params_.type);
|
2008-04-03 22:39:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-04-10 09:22:49 +00:00
|
|
|
docstring InsetWrap::toolTip(BufferView const & bv, int x, int y) const
|
|
|
|
{
|
2010-11-17 17:25:22 +00:00
|
|
|
if (isOpen(bv))
|
|
|
|
return InsetCollapsable::toolTip(bv, x, y);
|
2008-04-10 09:22:49 +00:00
|
|
|
OutputParams rp(&buffer().params().encoding());
|
|
|
|
docstring caption_tip = getCaptionText(rp);
|
2010-11-17 17:25:22 +00:00
|
|
|
if (!caption_tip.empty())
|
|
|
|
caption_tip += from_ascii("\n");
|
|
|
|
return toolTipText(caption_tip);
|
2008-04-10 09:22:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
void InsetWrap::doDispatch(Cursor & cur, FuncRequest & cmd)
|
2002-09-10 10:18:58 +00:00
|
|
|
{
|
2010-04-09 19:00:42 +00:00
|
|
|
switch (cmd.action()) {
|
2003-03-05 23:19:45 +00:00
|
|
|
case LFUN_INSET_MODIFY: {
|
|
|
|
InsetWrapParams params;
|
2008-03-27 00:07:54 +00:00
|
|
|
InsetWrap::string2params(to_utf8(cmd.argument()), params);
|
2007-09-24 13:43:58 +00:00
|
|
|
params_.lines = params.lines;
|
2003-03-05 23:19:45 +00:00
|
|
|
params_.placement = params.placement;
|
2007-09-24 13:43:58 +00:00
|
|
|
params_.overhang = params.overhang;
|
|
|
|
params_.width = params.width;
|
2004-02-16 11:58:51 +00:00
|
|
|
break;
|
2003-03-05 23:19:45 +00:00
|
|
|
}
|
2003-03-07 15:58:02 +00:00
|
|
|
|
2003-07-25 17:11:25 +00:00
|
|
|
case LFUN_INSET_DIALOG_UPDATE:
|
2008-03-27 00:07:54 +00:00
|
|
|
cur.bv().updateDialog("wrap", params2string(params()));
|
2004-02-16 11:58:51 +00:00
|
|
|
break;
|
2004-04-03 08:37:12 +00:00
|
|
|
|
2003-03-05 23:19:45 +00:00
|
|
|
default:
|
2004-11-24 21:58:42 +00:00
|
|
|
InsetCollapsable::doDispatch(cur, cmd);
|
2004-02-16 11:58:51 +00:00
|
|
|
break;
|
2002-09-10 10:18:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
bool InsetWrap::getStatus(Cursor & cur, FuncRequest const & cmd,
|
2005-04-22 08:57:22 +00:00
|
|
|
FuncStatus & flag) const
|
|
|
|
{
|
2010-04-09 19:00:42 +00:00
|
|
|
switch (cmd.action()) {
|
2005-04-22 08:57:22 +00:00
|
|
|
case LFUN_INSET_MODIFY:
|
|
|
|
case LFUN_INSET_DIALOG_UPDATE:
|
2008-05-29 15:14:00 +00:00
|
|
|
flag.setEnabled(true);
|
2005-04-22 08:57:22 +00:00
|
|
|
return true;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return InsetCollapsable::getStatus(cur, cmd, flag);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-03-03 22:13:45 +00:00
|
|
|
void InsetWrap::updateBuffer(ParIterator const & it, UpdateType utype)
|
2007-08-12 21:43:58 +00:00
|
|
|
{
|
2009-07-13 12:56:20 +00:00
|
|
|
setLabel(_("wrap: ") + floatName(params_.type));
|
2008-11-02 16:49:48 +00:00
|
|
|
Counters & cnts =
|
|
|
|
buffer().masterBuffer()->params().documentClass().counters();
|
2010-01-20 19:42:12 +00:00
|
|
|
if (utype == OutputUpdate) {
|
2010-01-20 19:03:17 +00:00
|
|
|
// counters are local to the wrap
|
|
|
|
cnts.saveLastCounter();
|
|
|
|
}
|
2007-08-12 21:43:58 +00:00
|
|
|
string const saveflt = cnts.current_float();
|
|
|
|
|
|
|
|
// Tell to captions what the current float is
|
|
|
|
cnts.current_float(params().type);
|
|
|
|
|
2010-03-03 22:13:45 +00:00
|
|
|
InsetCollapsable::updateBuffer(it, utype);
|
2007-08-12 21:43:58 +00:00
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
// reset afterwards
|
2007-08-12 21:43:58 +00:00
|
|
|
cnts.current_float(saveflt);
|
2010-01-20 19:42:12 +00:00
|
|
|
if (utype == OutputUpdate)
|
2010-01-20 19:03:17 +00:00
|
|
|
cnts.restoreLastCounter();
|
2007-08-12 21:43:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-03-05 23:19:45 +00:00
|
|
|
void InsetWrapParams::write(ostream & os) const
|
|
|
|
{
|
2003-08-05 08:07:07 +00:00
|
|
|
os << "Wrap " << type << '\n';
|
2008-04-03 22:39:06 +00:00
|
|
|
os << "lines " << lines << '\n';
|
|
|
|
os << "placement " << placement << '\n';
|
|
|
|
os << "overhang " << overhang.asString() << '\n';
|
2003-03-05 23:19:45 +00:00
|
|
|
os << "width \"" << width.asString() << "\"\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-26 11:30:54 +00:00
|
|
|
void InsetWrapParams::read(Lexer & lex)
|
2002-09-10 10:18:58 +00:00
|
|
|
{
|
2008-04-03 22:39:06 +00:00
|
|
|
lex.setContext("InsetWrapParams::read");
|
|
|
|
lex >> "lines" >> lines;
|
|
|
|
lex >> "placement" >> placement;
|
|
|
|
lex >> "overhang" >> overhang;
|
|
|
|
lex >> "width" >> width;
|
2003-03-05 23:19:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
void InsetWrap::write(ostream & os) const
|
2003-03-05 23:19:45 +00:00
|
|
|
{
|
|
|
|
params_.write(os);
|
2008-02-27 20:43:16 +00:00
|
|
|
InsetCollapsable::write(os);
|
2003-03-05 23:19:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
void InsetWrap::read(Lexer & lex)
|
2003-03-05 23:19:45 +00:00
|
|
|
{
|
|
|
|
params_.read(lex);
|
2008-02-27 20:43:16 +00:00
|
|
|
InsetCollapsable::read(lex);
|
2002-09-10 10:18:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void InsetWrap::validate(LaTeXFeatures & features) const
|
|
|
|
{
|
2007-09-09 23:47:22 +00:00
|
|
|
features.require("wrapfig");
|
2009-02-07 12:27:24 +00:00
|
|
|
features.inFloat(true);
|
2002-09-10 10:18:58 +00:00
|
|
|
InsetCollapsable::validate(features);
|
2009-02-07 12:27:24 +00:00
|
|
|
features.inFloat(false);
|
2002-09-10 10:18:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-02-07 12:27:24 +00:00
|
|
|
int InsetWrap::latex(odocstream & os, OutputParams const & runparams_in) const
|
2002-09-10 10:18:58 +00:00
|
|
|
{
|
2009-02-07 12:27:24 +00:00
|
|
|
OutputParams runparams(runparams_in);
|
|
|
|
runparams.inFloat = OutputParams::MAINFLOAT;
|
2007-09-09 23:47:22 +00:00
|
|
|
os << "\\begin{wrap" << from_ascii(params_.type) << '}';
|
2007-09-24 13:43:58 +00:00
|
|
|
// no optional argument when lines are zero
|
|
|
|
if (params_.lines != 0)
|
|
|
|
os << '[' << params_.lines << ']';
|
|
|
|
os << '{' << from_ascii(params_.placement) << '}';
|
|
|
|
Length over(params_.overhang);
|
|
|
|
// no optional argument when the value is zero
|
|
|
|
if (over.value() != 0)
|
|
|
|
os << '[' << from_ascii(params_.overhang.asLatexString()) << ']';
|
2006-10-21 00:16:43 +00:00
|
|
|
os << '{' << from_ascii(params_.width.asLatexString()) << "}%\n";
|
2008-02-27 20:43:16 +00:00
|
|
|
int const i = InsetText::latex(os, runparams);
|
2007-09-09 23:47:22 +00:00
|
|
|
os << "\\end{wrap" << from_ascii(params_.type) << "}%\n";
|
2002-09-10 10:18:58 +00:00
|
|
|
return i + 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
int InsetWrap::plaintext(odocstream & os, OutputParams const & runparams) const
|
2007-02-16 08:15:16 +00:00
|
|
|
{
|
2008-02-27 20:43:16 +00:00
|
|
|
os << '[' << buffer().B_("wrap") << ' '
|
2009-07-13 12:56:20 +00:00
|
|
|
<< floatName(params_.type) << ":\n";
|
2008-02-27 20:43:16 +00:00
|
|
|
InsetText::plaintext(os, runparams);
|
2007-02-16 08:15:16 +00:00
|
|
|
os << "\n]";
|
|
|
|
|
2007-02-20 17:52:41 +00:00
|
|
|
return PLAINTEXT_NEWLINE + 1; // one char on a separate line
|
2007-02-16 08:15:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
int InsetWrap::docbook(odocstream & os, OutputParams const & runparams) const
|
2002-09-10 10:18:58 +00:00
|
|
|
{
|
2007-05-28 22:27:45 +00:00
|
|
|
// FIXME UNICODE
|
|
|
|
os << '<' << from_ascii(params_.type) << '>';
|
2008-02-27 20:43:16 +00:00
|
|
|
int const i = InsetText::docbook(os, runparams);
|
2006-10-21 00:16:43 +00:00
|
|
|
os << "</" << from_ascii(params_.type) << '>';
|
2002-09-10 10:18:58 +00:00
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-21 22:57:40 +00:00
|
|
|
docstring InsetWrap::xhtml(XHTMLStream & xs, OutputParams const & rp) const
|
2009-06-12 17:26:48 +00:00
|
|
|
{
|
|
|
|
string const len = params_.width.asHTMLString();
|
2009-11-21 22:57:40 +00:00
|
|
|
string const width = len.empty() ? "50%" : len;
|
|
|
|
string const attr = "class='wrap' style='width: " + len + ";'";
|
2010-01-19 22:08:04 +00:00
|
|
|
xs << html::StartTag("div", attr);
|
2009-11-21 22:57:40 +00:00
|
|
|
docstring const deferred =
|
|
|
|
InsetText::insetAsXHTML(xs, rp, InsetText::WriteInnerTag);
|
2009-06-12 17:26:48 +00:00
|
|
|
if (!len.empty())
|
2010-01-19 22:08:04 +00:00
|
|
|
xs << html::EndTag("div");
|
2009-11-21 22:57:40 +00:00
|
|
|
return deferred;
|
2009-06-12 17:26:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-13 09:04:52 +00:00
|
|
|
bool InsetWrap::insetAllowed(InsetCode code) const
|
2002-09-10 10:18:58 +00:00
|
|
|
{
|
|
|
|
switch(code) {
|
2008-06-05 16:05:52 +00:00
|
|
|
case WRAP_CODE:
|
2002-09-10 10:18:58 +00:00
|
|
|
case FOOT_CODE:
|
|
|
|
case MARGIN_CODE:
|
2002-11-27 10:30:28 +00:00
|
|
|
return false;
|
2002-09-10 10:18:58 +00:00
|
|
|
default:
|
|
|
|
return InsetCollapsable::insetAllowed(code);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-11-27 10:30:28 +00:00
|
|
|
|
2002-09-10 10:18:58 +00:00
|
|
|
bool InsetWrap::showInsetDialog(BufferView * bv) const
|
|
|
|
{
|
2004-03-25 09:16:36 +00:00
|
|
|
if (!InsetText::showInsetDialog(bv))
|
2008-03-27 00:07:54 +00:00
|
|
|
bv->showDialog("wrap", params2string(params()),
|
|
|
|
const_cast<InsetWrap *>(this));
|
2002-09-10 10:18:58 +00:00
|
|
|
return true;
|
|
|
|
}
|
2003-03-05 23:19:45 +00:00
|
|
|
|
|
|
|
|
2008-03-27 00:07:54 +00:00
|
|
|
void InsetWrap::string2params(string const & in, InsetWrapParams & params)
|
2003-03-05 23:19:45 +00:00
|
|
|
{
|
|
|
|
params = InsetWrapParams();
|
2003-09-15 11:00:00 +00:00
|
|
|
istringstream data(in);
|
2008-04-02 23:06:22 +00:00
|
|
|
Lexer lex;
|
2003-03-07 14:08:10 +00:00
|
|
|
lex.setStream(data);
|
2008-04-03 22:39:06 +00:00
|
|
|
lex.setContext("InsetWrap::string2params");
|
|
|
|
lex >> "wrap";
|
|
|
|
lex >> "Wrap"; // Part of the inset proper, swallowed by Text::readInset
|
|
|
|
lex >> params.type; // We have to read the type here!
|
2003-12-11 15:23:15 +00:00
|
|
|
params.read(lex);
|
2003-03-05 23:19:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-03-27 00:07:54 +00:00
|
|
|
string InsetWrap::params2string(InsetWrapParams const & params)
|
2003-03-05 23:19:45 +00:00
|
|
|
{
|
|
|
|
ostringstream data;
|
2008-03-27 00:07:54 +00:00
|
|
|
data << "wrap" << ' ';
|
2003-03-05 23:19:45 +00:00
|
|
|
params.write(data);
|
2003-09-15 11:00:00 +00:00
|
|
|
return data.str();
|
2003-03-05 23:19:45 +00:00
|
|
|
}
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
} // namespace lyx
|