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"
|
2003-03-05 23:19:45 +00:00
|
|
|
|
#include "debug.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"
|
2002-09-10 10:18:58 +00:00
|
|
|
|
#include "gettext.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"
|
2003-09-05 09:01:27 +00:00
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
|
|
namespace lyx {
|
2006-09-09 18:52:00 +00:00
|
|
|
|
|
2003-10-06 15:43:21 +00:00
|
|
|
|
using std::string;
|
2002-09-10 10:18:58 +00:00
|
|
|
|
using std::endl;
|
2003-09-05 18:02:24 +00:00
|
|
|
|
using std::istringstream;
|
2003-09-05 09:01:27 +00:00
|
|
|
|
using std::ostream;
|
2003-09-05 18:02:24 +00:00
|
|
|
|
using std::ostringstream;
|
2003-09-05 09:01:27 +00:00
|
|
|
|
|
2003-05-13 16:24:49 +00:00
|
|
|
|
|
2002-09-10 10:18:58 +00:00
|
|
|
|
InsetWrap::InsetWrap(BufferParams const & bp, string const & type)
|
2007-04-29 12:32:14 +00:00
|
|
|
|
: InsetCollapsable(bp), name_(from_utf8(type))
|
2002-09-10 10:18:58 +00:00
|
|
|
|
{
|
2006-10-08 09:36:16 +00:00
|
|
|
|
setLabel(_("wrap: ") + floatName(type, bp));
|
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()
|
|
|
|
|
{
|
2003-06-06 16:07:07 +00:00
|
|
|
|
InsetWrapMailer(*this).hideDialog();
|
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;
|
2006-10-21 00:16:43 +00:00
|
|
|
|
InsetWrapMailer::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:
|
2004-01-20 14:25:24 +00:00
|
|
|
|
InsetWrapMailer(*this).updateDialog(&cur.bv());
|
2004-02-16 11:58:51 +00:00
|
|
|
|
break;
|
2004-04-03 08:37:12 +00:00
|
|
|
|
|
2004-04-02 08:54:37 +00:00
|
|
|
|
case LFUN_MOUSE_RELEASE: {
|
|
|
|
|
if (cmd.button() == mouse_button::button3 && hitButton(cmd)) {
|
|
|
|
|
InsetWrapMailer(*this).showDialog(&cur.bv());
|
|
|
|
|
break;
|
|
|
|
|
}
|
2004-11-24 21:58:42 +00:00
|
|
|
|
InsetCollapsable::doDispatch(cur, cmd);
|
2004-04-02 08:54:37 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
2003-03-07 15:58:02 +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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-08-12 21:43:58 +00:00
|
|
|
|
void InsetWrap::updateLabels(Buffer const & buf, ParIterator const & it)
|
|
|
|
|
{
|
|
|
|
|
Counters & cnts = buf.params().getTextClass().counters();
|
|
|
|
|
string const saveflt = cnts.current_float();
|
|
|
|
|
|
|
|
|
|
// Tell to captions what the current float is
|
|
|
|
|
cnts.current_float(params().type);
|
|
|
|
|
|
|
|
|
|
InsetCollapsable::updateLabels(buf, it);
|
|
|
|
|
|
|
|
|
|
//reset afterwards
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-08-28 07:41:31 +00:00
|
|
|
|
void InsetWrap::write(Buffer const & buf, ostream & os) const
|
2003-03-05 23:19:45 +00:00
|
|
|
|
{
|
|
|
|
|
params_.write(os);
|
|
|
|
|
InsetCollapsable::write(buf, os);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-04-26 11:30:54 +00:00
|
|
|
|
void InsetWrap::read(Buffer const & buf, Lexer & lex)
|
2003-03-05 23:19:45 +00:00
|
|
|
|
{
|
|
|
|
|
params_.read(lex);
|
2002-09-10 10:18:58 +00:00
|
|
|
|
InsetCollapsable::read(buf, lex);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-08-30 18:03:17 +00:00
|
|
|
|
Inset * InsetWrap::clone() const
|
2002-09-10 10:18:58 +00:00
|
|
|
|
{
|
2007-08-30 18:03:17 +00:00
|
|
|
|
return new InsetWrap(*this);
|
2002-09-10 10:18:58 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-09-09 18:52:00 +00:00
|
|
|
|
docstring const 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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-10-19 16:51:30 +00:00
|
|
|
|
int InsetWrap::latex(Buffer const & buf, odocstream & os,
|
2007-05-28 22:27:45 +00:00
|
|
|
|
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";
|
2004-03-25 09:16:36 +00:00
|
|
|
|
int const i = InsetText::latex(buf, 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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-02-16 08:15:16 +00:00
|
|
|
|
int InsetWrap::plaintext(Buffer const & buf, odocstream & os,
|
2007-05-28 22:27:45 +00:00
|
|
|
|
OutputParams const & runparams) const
|
2007-02-16 08:15:16 +00:00
|
|
|
|
{
|
2007-05-01 08:26:40 +00:00
|
|
|
|
os << '[' << buf.B_("wrap") << ' ' << floatName(params_.type, buf.params()) << ":\n";
|
2007-02-16 08:15:16 +00:00
|
|
|
|
InsetText::plaintext(buf, os, runparams);
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-10-19 21:00:33 +00:00
|
|
|
|
int InsetWrap::docbook(Buffer const & buf, odocstream & os,
|
2007-05-28 22:27:45 +00:00
|
|
|
|
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) << '>';
|
2004-03-25 09:16:36 +00:00
|
|
|
|
int const i = InsetText::docbook(buf, 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))
|
2003-12-01 13:35:49 +00:00
|
|
|
|
InsetWrapMailer(const_cast<InsetWrap &>(*this)).showDialog(bv);
|
2002-09-10 10:18:58 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
2003-03-05 23:19:45 +00:00
|
|
|
|
|
|
|
|
|
|
2003-03-07 14:08:10 +00:00
|
|
|
|
string const InsetWrapMailer::name_("wrap");
|
|
|
|
|
|
2003-03-05 23:19:45 +00:00
|
|
|
|
InsetWrapMailer::InsetWrapMailer(InsetWrap & inset)
|
2003-03-07 14:08:10 +00:00
|
|
|
|
: inset_(inset)
|
2003-03-05 23:19:45 +00:00
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
2003-07-23 09:54:21 +00:00
|
|
|
|
string const InsetWrapMailer::inset2string(Buffer const &) const
|
2003-03-05 23:19:45 +00:00
|
|
|
|
{
|
2003-03-07 14:08:10 +00:00
|
|
|
|
return params2string(inset_.params());
|
2003-03-05 23:19:45 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-11-10 09:06:48 +00:00
|
|
|
|
void InsetWrapMailer::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);
|
2007-04-26 11:30:54 +00:00
|
|
|
|
Lexer lex(0,0);
|
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;
|
|
|
|
|
if (!lex || name != name_)
|
|
|
|
|
return print_mailer_error("InsetWrapMailer", in, 1, name_);
|
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;
|
|
|
|
|
if (!lex || id != "Wrap")
|
|
|
|
|
return print_mailer_error("InsetBoxMailer", in, 2, "Wrap");
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-05-13 16:24:49 +00:00
|
|
|
|
string const InsetWrapMailer::params2string(InsetWrapParams const & params)
|
2003-03-05 23:19:45 +00:00
|
|
|
|
{
|
|
|
|
|
ostringstream data;
|
2003-03-07 14:08:10 +00:00
|
|
|
|
data << name_ << ' ';
|
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
|