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
|
2007-10-14 10:41:10 +00:00
|
|
|
|
* \author Uwe St<EFBFBD>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"
|
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"
|
2007-04-26 04:41:58 +00:00
|
|
|
|
#include "OutputParams.h"
|
2007-11-07 23:25:08 +00:00
|
|
|
|
#include "TextClass.h"
|
2006-11-13 16:53:49 +00:00
|
|
|
|
#include "TocBackend.h"
|
2003-03-05 23:19:45 +00:00
|
|
|
|
|
2005-01-06 16:39:35 +00:00
|
|
|
|
#include "support/convert.h"
|
2007-11-01 22:17:22 +00:00
|
|
|
|
#include "support/docstream.h"
|
2008-02-18 07:14:42 +00:00
|
|
|
|
#include "support/debug.h"
|
|
|
|
|
#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
|
|
|
|
|
|
|
|
|
namespace lyx {
|
2006-09-09 18:52:00 +00:00
|
|
|
|
|
2003-05-13 16:24:49 +00:00
|
|
|
|
|
2008-03-04 22:28:18 +00:00
|
|
|
|
InsetWrap::InsetWrap(Buffer const & buf, string const & type)
|
|
|
|
|
: InsetCollapsable(buf), name_(from_utf8(type))
|
2002-09-10 10:18:58 +00:00
|
|
|
|
{
|
2008-03-04 22:28:18 +00:00
|
|
|
|
setLabel(_("wrap: ") + floatName(type, buf.params()));
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-04-26 14:56:30 +00:00
|
|
|
|
void InsetWrap::doDispatch(Cursor & cur, FuncRequest & cmd)
|
2002-09-10 10:18:58 +00:00
|
|
|
|
{
|
2003-03-05 23:19:45 +00:00
|
|
|
|
switch (cmd.action) {
|
|
|
|
|
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
|
|
|
|
|
{
|
|
|
|
|
switch (cmd.action) {
|
|
|
|
|
case LFUN_INSET_MODIFY:
|
|
|
|
|
case LFUN_INSET_DIALOG_UPDATE:
|
|
|
|
|
flag.enabled(true);
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
return InsetCollapsable::getStatus(cur, cmd, flag);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
|
void InsetWrap::updateLabels(ParIterator const & it)
|
2007-08-12 21:43:58 +00:00
|
|
|
|
{
|
2008-03-02 16:56:57 +00:00
|
|
|
|
setLabel(_("wrap: ") + floatName(params_.type, buffer().params()));
|
2008-02-28 01:42:02 +00:00
|
|
|
|
Counters & cnts = buffer().params().documentClass().counters();
|
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);
|
|
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
|
InsetCollapsable::updateLabels(it);
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
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';
|
2007-09-24 13:43:58 +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
|
|
|
|
{
|
2004-04-02 08:54:37 +00:00
|
|
|
|
string token;
|
2007-09-24 13:43:58 +00:00
|
|
|
|
|
|
|
|
|
lex >> token;
|
|
|
|
|
if (token == "lines")
|
|
|
|
|
lex >> lines;
|
|
|
|
|
else {
|
|
|
|
|
lyxerr << "InsetWrap::Read:: Missing 'lines'-tag!"
|
|
|
|
|
<< endl;
|
|
|
|
|
// take countermeasures
|
|
|
|
|
lex.pushToken(token);
|
|
|
|
|
}
|
|
|
|
|
if (!lex)
|
|
|
|
|
return;
|
2004-04-02 08:54:37 +00:00
|
|
|
|
lex >> token;
|
|
|
|
|
if (token == "placement")
|
|
|
|
|
lex >> placement;
|
|
|
|
|
else {
|
2007-09-24 13:43:58 +00:00
|
|
|
|
lyxerr << "InsetWrap::Read:: Missing 'placement'-tag!"
|
|
|
|
|
<< endl;
|
|
|
|
|
lex.pushToken(token);
|
|
|
|
|
}
|
|
|
|
|
if (!lex)
|
|
|
|
|
return;
|
|
|
|
|
lex >> token;
|
|
|
|
|
if (token == "overhang") {
|
|
|
|
|
lex.next();
|
|
|
|
|
overhang = Length(lex.getString());
|
|
|
|
|
} else {
|
|
|
|
|
lyxerr << "InsetWrap::Read:: Missing 'overhang'-tag!"
|
|
|
|
|
<< endl;
|
2004-04-02 08:54:37 +00:00
|
|
|
|
lex.pushToken(token);
|
2002-09-10 10:18:58 +00:00
|
|
|
|
}
|
2004-04-02 08:54:37 +00:00
|
|
|
|
if (!lex)
|
|
|
|
|
return;
|
|
|
|
|
lex >> token;
|
|
|
|
|
if (token == "width") {
|
2002-09-10 10:18:58 +00:00
|
|
|
|
lex.next();
|
2007-04-28 12:58:49 +00:00
|
|
|
|
width = Length(lex.getString());
|
2004-04-02 08:54:37 +00:00
|
|
|
|
} else {
|
|
|
|
|
lyxerr << "InsetWrap::Read:: Missing 'width'-tag!"
|
|
|
|
|
<< endl;
|
|
|
|
|
lex.pushToken(token);
|
2002-09-10 10:18:58 +00:00
|
|
|
|
}
|
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");
|
2002-09-10 10:18:58 +00:00
|
|
|
|
InsetCollapsable::validate(features);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
|
docstring InsetWrap::editMessage() const
|
2002-09-10 10:18:58 +00:00
|
|
|
|
{
|
2006-09-09 18:52:00 +00:00
|
|
|
|
return _("Opened Wrap Inset");
|
2002-09-10 10:18:58 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
|
int InsetWrap::latex(odocstream & os, OutputParams const & runparams) const
|
2002-09-10 10:18:58 +00:00
|
|
|
|
{
|
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") << ' '
|
|
|
|
|
<< floatName(params_.type, buffer().params()) << ":\n";
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-10-13 09:04:52 +00:00
|
|
|
|
bool InsetWrap::insetAllowed(InsetCode code) const
|
2002-09-10 10:18:58 +00:00
|
|
|
|
{
|
|
|
|
|
switch(code) {
|
|
|
|
|
case FLOAT_CODE:
|
|
|
|
|
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-04-24 20:02:49 +00:00
|
|
|
|
if (in.empty())
|
|
|
|
|
return;
|
2003-05-26 09:13:55 +00:00
|
|
|
|
|
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);
|
2003-03-05 23:19:45 +00:00
|
|
|
|
|
2003-12-11 15:23:15 +00:00
|
|
|
|
string name;
|
|
|
|
|
lex >> name;
|
2008-03-27 00:07:54 +00:00
|
|
|
|
if (!lex || name != "wrap") {
|
2008-03-27 22:26:24 +00:00
|
|
|
|
LYXERR0("Expected arg 1 to be \"wrap\" in " << in);
|
2008-03-27 00:07:54 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
2003-03-05 23:19:45 +00:00
|
|
|
|
|
|
|
|
|
// This is part of the inset proper that is usually swallowed
|
2007-04-29 23:33:02 +00:00
|
|
|
|
// by Text::readInset
|
2003-12-11 15:23:15 +00:00
|
|
|
|
string id;
|
|
|
|
|
lex >> id;
|
2008-03-27 00:07:54 +00:00
|
|
|
|
if (!lex || id != "Wrap") {
|
2008-03-27 22:26:24 +00:00
|
|
|
|
LYXERR0("Expected arg 2 to be \"Wrap\" in " << in);
|
2008-03-27 00:07:54 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
2003-03-05 23:19:45 +00:00
|
|
|
|
|
2004-04-02 08:54:37 +00:00
|
|
|
|
// We have to read the type here!
|
|
|
|
|
lex >> params.type;
|
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
|