2002-09-10 10:18:58 +00:00
|
|
|
/**
|
|
|
|
* \file insetwrap.C
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
*
|
|
|
|
* \author Dekel Tsur
|
|
|
|
*
|
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>
|
|
|
|
|
|
|
|
#include "insetwrap.h"
|
2003-03-05 23:19:45 +00:00
|
|
|
|
|
|
|
#include "buffer.h"
|
2003-09-09 11:24:33 +00:00
|
|
|
#include "bufferparams.h"
|
2003-03-05 23:19:45 +00:00
|
|
|
#include "BufferView.h"
|
2004-01-20 14:25:24 +00:00
|
|
|
#include "cursor.h"
|
2003-03-05 23:19:45 +00:00
|
|
|
#include "debug.h"
|
2003-10-29 10:47:21 +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"
|
2003-09-05 09:01:27 +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"
|
2003-09-16 10:54:23 +00:00
|
|
|
#include "LColor.h"
|
2003-03-05 23:19:45 +00:00
|
|
|
#include "lyxlex.h"
|
2003-11-05 12:06:20 +00:00
|
|
|
#include "outputparams.h"
|
2003-09-06 17:23:08 +00:00
|
|
|
#include "paragraph.h"
|
2005-04-19 08:55:19 +00:00
|
|
|
#include "pariterator.h"
|
2003-03-05 23:19:45 +00:00
|
|
|
|
2005-01-06 16:39:35 +00:00
|
|
|
#include "support/convert.h"
|
2003-09-05 09:01:27 +00:00
|
|
|
|
2004-07-24 10:55:30 +00:00
|
|
|
#include <sstream>
|
2003-10-06 15:43:21 +00:00
|
|
|
|
2006-09-09 18:52:00 +00:00
|
|
|
using lyx::docstring;
|
|
|
|
|
2003-10-06 15:43:21 +00:00
|
|
|
using std::string;
|
2002-09-10 10:18:58 +00:00
|
|
|
using std::endl;
|
2003-07-25 17:11:25 +00:00
|
|
|
using std::auto_ptr;
|
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-24 18:36:20 +00:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
string floatname(string const & type, BufferParams const & bp)
|
|
|
|
{
|
|
|
|
FloatList const & floats = bp.getLyXTextClass().floats();
|
|
|
|
FloatList::const_iterator it = floats[type];
|
2006-09-09 15:27:44 +00:00
|
|
|
// FIXME UNICODE
|
|
|
|
return (it == floats.end()) ? type : lyx::to_utf8(_(it->second.name()));
|
2002-09-24 18:36:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace anon
|
|
|
|
|
2002-09-10 10:18:58 +00:00
|
|
|
|
|
|
|
InsetWrap::InsetWrap(BufferParams const & bp, string const & type)
|
2003-03-05 23:19:45 +00:00
|
|
|
: InsetCollapsable(bp)
|
2002-09-10 10:18:58 +00:00
|
|
|
{
|
2006-09-09 15:27:44 +00:00
|
|
|
// FIXME UNICODE
|
|
|
|
setLabel(lyx::to_utf8(_("wrap: ")) + floatname(type, bp));
|
2002-09-10 10:18:58 +00:00
|
|
|
LyXFont font(LyXFont::ALL_SANE);
|
|
|
|
font.decSize();
|
|
|
|
font.decSize();
|
|
|
|
font.setColor(LColor::collapsable);
|
|
|
|
setLabelFont(font);
|
2003-03-05 23:19:45 +00:00
|
|
|
params_.type = type;
|
|
|
|
params_.width = LyXLength(50, LyXLength::PCW);
|
2002-09-10 10:18:58 +00:00
|
|
|
setInsetName(type);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
InsetWrap::~InsetWrap()
|
|
|
|
{
|
2003-06-06 16:07:07 +00:00
|
|
|
InsetWrapMailer(*this).hideDialog();
|
2002-09-10 10:18:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-11-24 21:58:42 +00:00
|
|
|
void InsetWrap::doDispatch(LCursor & 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-09-01 15:41:38 +00:00
|
|
|
InsetWrapMailer::string2params(lyx::to_utf8(cmd.argument()), params);
|
2003-03-05 23:19:45 +00:00
|
|
|
params_.placement = params.placement;
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-04-22 08:57:22 +00:00
|
|
|
bool InsetWrap::getStatus(LCursor & cur, FuncRequest const & cmd,
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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';
|
2003-03-05 23:19:45 +00:00
|
|
|
|
2003-08-05 08:07:07 +00:00
|
|
|
if (!placement.empty())
|
2003-03-05 23:19:45 +00:00
|
|
|
os << "placement " << placement << "\n";
|
2003-08-05 08:07:07 +00:00
|
|
|
|
2003-03-05 23:19:45 +00:00
|
|
|
os << "width \"" << width.asString() << "\"\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void InsetWrapParams::read(LyXLex & lex)
|
2002-09-10 10:18:58 +00:00
|
|
|
{
|
2004-04-02 08:54:37 +00:00
|
|
|
string token;
|
|
|
|
lex >> token;
|
|
|
|
if (token == "placement")
|
|
|
|
lex >> placement;
|
|
|
|
else {
|
|
|
|
// take countermeasures
|
|
|
|
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();
|
2004-04-02 08:54:37 +00:00
|
|
|
width = LyXLength(lex.getString());
|
|
|
|
} else {
|
|
|
|
lyxerr << "InsetWrap::Read:: Missing 'width'-tag!"
|
|
|
|
<< endl;
|
|
|
|
// take countermeasures
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-08-28 07:41:31 +00:00
|
|
|
void InsetWrap::read(Buffer const & buf, LyXLex & 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
|
|
|
|
{
|
|
|
|
features.require("floatflt");
|
|
|
|
InsetCollapsable::validate(features);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-11-23 23:04:52 +00:00
|
|
|
auto_ptr<InsetBase> InsetWrap::doClone() const
|
2002-09-10 10:18:58 +00:00
|
|
|
{
|
2003-07-25 17:11:25 +00:00
|
|
|
return auto_ptr<InsetBase>(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
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-08-28 07:41:31 +00:00
|
|
|
int InsetWrap::latex(Buffer const & buf, ostream & os,
|
2003-11-05 12:06:20 +00:00
|
|
|
OutputParams const & runparams) const
|
2002-09-10 10:18:58 +00:00
|
|
|
{
|
2003-03-05 23:19:45 +00:00
|
|
|
os << "\\begin{floating" << params_.type << '}';
|
2004-03-25 09:16:36 +00:00
|
|
|
if (!params_.placement.empty())
|
2003-03-05 23:19:45 +00:00
|
|
|
os << '[' << params_.placement << ']';
|
2004-03-25 09:16:36 +00:00
|
|
|
os << '{' << params_.width.asLatexString() << "}%\n";
|
|
|
|
int const i = InsetText::latex(buf, os, runparams);
|
2003-03-05 23:19:45 +00:00
|
|
|
os << "\\end{floating" << params_.type << "}%\n";
|
2002-09-10 10:18:58 +00:00
|
|
|
return i + 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-10-31 18:45:43 +00:00
|
|
|
int InsetWrap::docbook(Buffer const & buf, ostream & os,
|
2003-11-05 12:06:20 +00:00
|
|
|
OutputParams const & runparams) const
|
2002-09-10 10:18:58 +00:00
|
|
|
{
|
2003-03-05 23:19:45 +00:00
|
|
|
os << '<' << params_.type << '>';
|
2004-03-25 09:16:36 +00:00
|
|
|
int const i = InsetText::docbook(buf, os, runparams);
|
2003-03-05 23:19:45 +00:00
|
|
|
os << "</" << params_.type << '>';
|
2002-09-10 10:18:58 +00:00
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-11-25 19:13:07 +00:00
|
|
|
bool InsetWrap::insetAllowed(InsetBase::Code 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;
|
|
|
|
}
|
2002-09-24 18:36:20 +00:00
|
|
|
|
|
|
|
|
2003-08-28 07:41:31 +00:00
|
|
|
void InsetWrap::addToToc(lyx::toc::TocList & toclist, Buffer const & buf) const
|
2002-09-24 18:36:20 +00:00
|
|
|
{
|
2005-04-19 08:55:19 +00:00
|
|
|
ParConstIterator pit = par_const_iterator_begin(*this);
|
|
|
|
ParConstIterator end = par_const_iterator_end(*this);
|
2003-04-02 17:11:38 +00:00
|
|
|
|
2005-04-19 08:55:19 +00:00
|
|
|
// Find a caption layout in one of the (child inset's) pars
|
|
|
|
for (; pit != end; ++pit) {
|
|
|
|
if (pit->layout()->labeltype == LABEL_SENSITIVE) {
|
2005-07-27 15:22:08 +00:00
|
|
|
string const type = params_.type;
|
2002-09-24 18:36:20 +00:00
|
|
|
string const str =
|
2005-07-27 15:22:08 +00:00
|
|
|
convert<string>(toclist[type].size() + 1)
|
2005-04-19 08:55:19 +00:00
|
|
|
+ ". " + pit->asString(buf, false);
|
2006-04-22 18:48:28 +00:00
|
|
|
lyx::toc::TocItem const item(pit, 0 , str);
|
2005-07-27 15:22:08 +00:00
|
|
|
toclist[type].push_back(item);
|
2002-09-24 18:36:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
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);
|
2003-03-07 14:08:10 +00:00
|
|
|
LyXLex lex(0,0);
|
|
|
|
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
|
2003-12-11 15:23:15 +00:00
|
|
|
// by LyXText::readInset
|
|
|
|
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
|
|
|
}
|