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"
|
|
|
|
#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"
|
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"
|
2003-03-05 23:19:45 +00:00
|
|
|
|
2003-09-05 17:23:11 +00:00
|
|
|
#include "support/std_sstream.h"
|
2003-11-10 09:06:48 +00:00
|
|
|
#include "support/tostr.h"
|
2003-09-05 09:01:27 +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-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 {
|
|
|
|
|
|
|
|
// this should not be hardcoded, but be part of the definition
|
|
|
|
// of the float (JMarc)
|
|
|
|
string const caplayout("Caption");
|
2003-05-13 16:24:49 +00:00
|
|
|
|
2002-09-24 18:36:20 +00:00
|
|
|
string floatname(string const & type, BufferParams const & bp)
|
|
|
|
{
|
|
|
|
FloatList const & floats = bp.getLyXTextClass().floats();
|
|
|
|
FloatList::const_iterator it = floats[type];
|
2003-11-10 09:06:48 +00:00
|
|
|
return (it == floats.end()) ? type : _(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
|
|
|
{
|
2003-11-10 09:06:48 +00:00
|
|
|
setLabel(_("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);
|
2002-09-24 18:36:20 +00:00
|
|
|
LyXTextClass const & tclass = bp.getLyXTextClass();
|
|
|
|
if (tclass.hasLayout(caplayout))
|
2003-04-02 17:11:38 +00:00
|
|
|
inset.paragraphs.begin()->layout(tclass[caplayout]);
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-10-29 10:47:21 +00:00
|
|
|
DispatchResult
|
2003-10-17 18:01:15 +00:00
|
|
|
InsetWrap::priv_dispatch(FuncRequest const & cmd,
|
|
|
|
idx_type & idx, pos_type & pos)
|
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;
|
|
|
|
InsetWrapMailer::string2params(cmd.argument, params);
|
|
|
|
|
|
|
|
params_.placement = params.placement;
|
|
|
|
params_.width = params.width;
|
|
|
|
|
2003-11-10 13:23:14 +00:00
|
|
|
cmd.view()->update();
|
2003-11-03 19:52:47 +00:00
|
|
|
return DispatchResult(true, true);
|
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:
|
2003-06-06 16:07:07 +00:00
|
|
|
InsetWrapMailer(*this).updateDialog(cmd.view());
|
2003-11-03 19:52:47 +00:00
|
|
|
return DispatchResult(true, true);
|
2003-03-07 15:58:02 +00:00
|
|
|
|
2003-03-05 23:19:45 +00:00
|
|
|
default:
|
2003-10-17 18:01:15 +00:00
|
|
|
return InsetCollapsable::priv_dispatch(cmd, idx, pos);
|
2002-09-10 10:18: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';
|
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
|
|
|
{
|
|
|
|
if (lex.isOK()) {
|
|
|
|
lex.next();
|
|
|
|
string token = lex.getString();
|
|
|
|
if (token == "placement") {
|
|
|
|
lex.next();
|
2003-03-05 23:19:45 +00:00
|
|
|
placement = lex.getString();
|
2002-09-10 10:18:58 +00:00
|
|
|
} else {
|
|
|
|
// take countermeasures
|
|
|
|
lex.pushToken(token);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (lex.isOK()) {
|
|
|
|
lex.next();
|
|
|
|
string token = lex.getString();
|
|
|
|
if (token == "width") {
|
|
|
|
lex.next();
|
2003-03-05 23:19:45 +00:00
|
|
|
width = LyXLength(lex.getString());
|
2002-09-10 10:18:58 +00:00
|
|
|
} else {
|
|
|
|
lyxerr << "InsetWrap::Read:: Missing 'width'-tag!"
|
|
|
|
<< endl;
|
|
|
|
// take countermeasures
|
|
|
|
lex.pushToken(token);
|
|
|
|
}
|
|
|
|
}
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-07-25 17:11:25 +00:00
|
|
|
auto_ptr<InsetBase> InsetWrap::clone() 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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
string const InsetWrap::editMessage() const
|
|
|
|
{
|
|
|
|
return _("Opened Wrap Inset");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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 << '}';
|
|
|
|
if (!params_.placement.empty()) {
|
|
|
|
os << '[' << params_.placement << ']';
|
2002-09-10 10:18:58 +00:00
|
|
|
}
|
2003-03-05 23:19:45 +00:00
|
|
|
os << '{' << params_.width.asLatexString() << "}%\n";
|
2002-09-10 10:18:58 +00:00
|
|
|
|
2003-05-23 08:59:47 +00:00
|
|
|
int const i = inset.latex(buf, os, runparams);
|
2002-09-10 10:18:58 +00:00
|
|
|
|
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 << '>';
|
2003-10-31 18:45:43 +00:00
|
|
|
int const i = inset.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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-07-25 21:20:24 +00:00
|
|
|
bool InsetWrap::insetAllowed(InsetOld::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
|
|
|
int InsetWrap::latexTextWidth(BufferView * bv) const
|
|
|
|
{
|
2003-03-05 23:19:45 +00:00
|
|
|
return params_.width.inPixels(InsetCollapsable::latexTextWidth(bv));
|
2002-09-10 10:18:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool InsetWrap::showInsetDialog(BufferView * bv) const
|
|
|
|
{
|
|
|
|
if (!inset.showInsetDialog(bv)) {
|
2003-03-05 23:19:45 +00:00
|
|
|
InsetWrap * tmp = const_cast<InsetWrap *>(this);
|
2003-06-06 16:07:07 +00:00
|
|
|
InsetWrapMailer(*tmp).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
|
|
|
{
|
|
|
|
// Now find the caption in the float...
|
2003-04-02 17:11:38 +00:00
|
|
|
ParagraphList::iterator tmp = inset.paragraphs.begin();
|
|
|
|
ParagraphList::iterator end = inset.paragraphs.end();
|
|
|
|
|
|
|
|
for (; tmp != end; ++tmp) {
|
2002-09-24 18:36:20 +00:00
|
|
|
if (tmp->layout()->name() == caplayout) {
|
2003-09-09 09:47:59 +00:00
|
|
|
string const name = floatname(params_.type, buf.params());
|
2002-09-24 18:36:20 +00:00
|
|
|
string const str =
|
2002-12-08 22:33:55 +00:00
|
|
|
tostr(toclist[name].size() + 1)
|
2002-09-24 18:36:20 +00:00
|
|
|
+ ". " + tmp->asString(buf, false);
|
2003-07-27 13:18:55 +00:00
|
|
|
lyx::toc::TocItem const item(tmp->id(), 0 , str);
|
2002-12-08 22:33:55 +00:00
|
|
|
toclist[name].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-03-07 14:08:10 +00:00
|
|
|
if (lex.isOK()) {
|
|
|
|
lex.next();
|
|
|
|
string const token = lex.getString();
|
|
|
|
if (token != name_)
|
|
|
|
return;
|
|
|
|
}
|
2003-03-05 23:19:45 +00:00
|
|
|
|
|
|
|
// This is part of the inset proper that is usually swallowed
|
|
|
|
// by Buffer::readInset
|
2003-03-07 14:08:10 +00:00
|
|
|
if (lex.isOK()) {
|
|
|
|
lex.next();
|
|
|
|
string const token = lex.getString();
|
|
|
|
if (token != "Wrap" || !lex.eatLine())
|
|
|
|
return;
|
|
|
|
}
|
2003-03-05 23:19:45 +00:00
|
|
|
|
2003-03-10 03:11:54 +00:00
|
|
|
if (lex.isOK()) {
|
|
|
|
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
|
|
|
}
|