2002-09-25 14:26:13 +00:00
|
|
|
|
/**
|
|
|
|
|
* \file insetfloat.C
|
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
|
* Licence details can be found in the file COPYING.
|
2002-03-21 17:09:55 +00:00
|
|
|
|
*
|
2002-09-25 14:26:13 +00:00
|
|
|
|
* \author J<EFBFBD>rgen Vigna
|
|
|
|
|
* \author Lars Gullik Bj<EFBFBD>nnes
|
2002-03-21 17:09:55 +00:00
|
|
|
|
*
|
2003-08-23 00:17:00 +00:00
|
|
|
|
* Full author contact details are available in file CREDITS.
|
2002-09-25 14:26:13 +00:00
|
|
|
|
*/
|
2000-06-28 13:35:52 +00:00
|
|
|
|
|
2003-05-13 09:48:57 +00:00
|
|
|
|
#include <config.h>
|
2000-06-28 13:35:52 +00:00
|
|
|
|
|
|
|
|
|
#include "insetfloat.h"
|
2003-03-05 19:46:08 +00:00
|
|
|
|
|
|
|
|
|
#include "buffer.h"
|
2003-09-09 11:24:33 +00:00
|
|
|
|
#include "bufferparams.h"
|
2003-03-05 19:46:08 +00:00
|
|
|
|
#include "BufferView.h"
|
2004-01-20 14:25:24 +00:00
|
|
|
|
#include "cursor.h"
|
2003-03-05 19:46:08 +00:00
|
|
|
|
#include "debug.h"
|
2003-10-29 10:47:21 +00:00
|
|
|
|
#include "dispatchresult.h"
|
2003-03-05 19:46:08 +00:00
|
|
|
|
#include "Floating.h"
|
|
|
|
|
#include "FloatList.h"
|
|
|
|
|
#include "funcrequest.h"
|
2000-06-28 13:35:52 +00:00
|
|
|
|
#include "gettext.h"
|
2003-03-05 19:46:08 +00:00
|
|
|
|
#include "iterators.h"
|
|
|
|
|
#include "LaTeXFeatures.h"
|
2003-09-16 10:54:23 +00:00
|
|
|
|
#include "LColor.h"
|
2003-03-05 19:46:08 +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 19:46:08 +00:00
|
|
|
|
|
2001-07-30 11:56:00 +00:00
|
|
|
|
#include "support/lstrings.h"
|
2003-05-13 14:36:24 +00:00
|
|
|
|
#include "support/tostr.h"
|
2003-09-05 17:23:11 +00:00
|
|
|
|
#include "support/std_sstream.h"
|
2000-06-28 13:35:52 +00:00
|
|
|
|
|
2003-09-09 22:13:45 +00:00
|
|
|
|
using lyx::support::contains;
|
2003-06-30 23:56:22 +00:00
|
|
|
|
|
2000-06-28 13:35:52 +00:00
|
|
|
|
using std::endl;
|
2003-10-06 15:43:21 +00:00
|
|
|
|
using std::string;
|
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;
|
2000-06-28 13:35:52 +00:00
|
|
|
|
|
2003-05-13 16:24:49 +00:00
|
|
|
|
|
2000-06-28 13:35:52 +00:00
|
|
|
|
// With this inset it will be possible to support the latex package
|
|
|
|
|
// float.sty, and I am sure that with this and some additional support
|
|
|
|
|
// classes we can support similar functionality in other formats
|
|
|
|
|
// (read DocBook).
|
|
|
|
|
// By using float.sty we will have the same handling for all floats, both
|
|
|
|
|
// for those already in existance (table and figure) and all user created
|
|
|
|
|
// ones<65>. So suddenly we give the users the possibility of creating new
|
|
|
|
|
// kinds of floats on the fly. (and with a uniform look)
|
|
|
|
|
//
|
|
|
|
|
// API to float.sty:
|
|
|
|
|
// \newfloat{type}{placement}{ext}[within]
|
|
|
|
|
// type - The "type" of the new class of floats, like program or
|
|
|
|
|
// algorithm. After the appropriate \newfloat, commands
|
|
|
|
|
// such as \begin{program} or \end{algorithm*} will be
|
|
|
|
|
// available.
|
|
|
|
|
// placement - The default placement for the given class of floats.
|
|
|
|
|
// They are like in standard LaTeX: t, b, p and h for top,
|
|
|
|
|
// bottom, page, and here, respectively. On top of that
|
|
|
|
|
// there is a new type, H, which does not really correspond
|
|
|
|
|
// to a float, since it means: put it "here" and nowhere else.
|
|
|
|
|
// Note, however that the H specifier is special and, because
|
|
|
|
|
// of implementation details cannot be used in the second
|
|
|
|
|
// argument of \newfloat.
|
|
|
|
|
// ext - The file name extension of an auxiliary file for the list
|
|
|
|
|
// of figures (or whatever). LaTeX writes the captions to
|
|
|
|
|
// this file.
|
|
|
|
|
// within - This (optional) argument determines whether floats of this
|
|
|
|
|
// class will be numbered within some sectional unit of the
|
|
|
|
|
// document. For example, if within is equal to chapter, the
|
2002-03-21 17:09:55 +00:00
|
|
|
|
// floats will be numbered within chapters.
|
2000-06-28 13:35:52 +00:00
|
|
|
|
// \floatstyle{style}
|
|
|
|
|
// style - plain, boxed, ruled
|
|
|
|
|
// \floatname{float}{floatname}
|
|
|
|
|
// float -
|
|
|
|
|
// floatname -
|
|
|
|
|
// \floatplacement{float}{placement}
|
|
|
|
|
// float -
|
|
|
|
|
// placement -
|
|
|
|
|
// \restylefloat{float}
|
|
|
|
|
// float -
|
|
|
|
|
// \listof{type}{title}
|
|
|
|
|
// title -
|
|
|
|
|
|
|
|
|
|
// <20> the algorithm float is defined using the float.sty package. Like this
|
|
|
|
|
// \floatstyle{ruled}
|
|
|
|
|
// \newfloat{algorithm}{htbp}{loa}[<sect>]
|
|
|
|
|
// \floatname{algorithm}{Algorithm}
|
|
|
|
|
//
|
2001-03-11 03:20:44 +00:00
|
|
|
|
// The intention is that floats should be definable from two places:
|
|
|
|
|
// - layout files
|
|
|
|
|
// - the "gui" (i.e. by the user)
|
|
|
|
|
//
|
|
|
|
|
// From layout files.
|
|
|
|
|
// This should only be done for floats defined in a documentclass and that
|
|
|
|
|
// does not need any additional packages. The two most known floats in this
|
|
|
|
|
// category is "table" and "figure". Floats defined in layout files are only
|
|
|
|
|
// stored in lyx files if the user modifies them.
|
|
|
|
|
//
|
|
|
|
|
// By the user.
|
|
|
|
|
// There should be a gui dialog (and also a collection of lyxfuncs) where
|
|
|
|
|
// the user can modify existing floats and/or create new ones.
|
|
|
|
|
//
|
|
|
|
|
// The individual floats will also have some settable
|
|
|
|
|
// variables: wide and placement.
|
|
|
|
|
//
|
2000-06-28 13:35:52 +00:00
|
|
|
|
// Lgb
|
|
|
|
|
|
2002-04-26 15:38:15 +00:00
|
|
|
|
namespace {
|
|
|
|
|
|
2002-07-21 21:21:06 +00:00
|
|
|
|
// this should not be hardcoded, but be part of the definition
|
|
|
|
|
// of the float (JMarc)
|
|
|
|
|
string const caplayout("Caption");
|
|
|
|
|
|
2002-08-27 15:51:19 +00:00
|
|
|
|
string floatname(string const & type, BufferParams const & bp)
|
2002-04-26 15:38:15 +00:00
|
|
|
|
{
|
2002-08-27 15:51:19 +00:00
|
|
|
|
FloatList const & floats = bp.getLyXTextClass().floats();
|
|
|
|
|
FloatList::const_iterator it = floats[type];
|
|
|
|
|
if (it == floats.end())
|
2002-04-26 15:38:15 +00:00
|
|
|
|
return type;
|
|
|
|
|
|
|
|
|
|
return _(it->second.name());
|
|
|
|
|
}
|
2002-05-01 22:17:09 +00:00
|
|
|
|
|
2002-04-26 15:38:15 +00:00
|
|
|
|
} // namespace anon
|
|
|
|
|
|
|
|
|
|
|
2002-03-03 20:25:07 +00:00
|
|
|
|
InsetFloat::InsetFloat(BufferParams const & bp, string const & type)
|
2003-03-05 17:56:47 +00:00
|
|
|
|
: InsetCollapsable(bp)
|
2000-06-28 13:35:52 +00:00
|
|
|
|
{
|
2002-04-26 15:38:15 +00:00
|
|
|
|
string lab(_("float: "));
|
2002-08-27 15:51:19 +00:00
|
|
|
|
lab += floatname(type, bp);
|
2000-07-15 23:51:46 +00:00
|
|
|
|
setLabel(lab);
|
2000-07-04 19:16:35 +00:00
|
|
|
|
LyXFont font(LyXFont::ALL_SANE);
|
|
|
|
|
font.decSize();
|
|
|
|
|
font.decSize();
|
2001-06-05 17:05:51 +00:00
|
|
|
|
font.setColor(LColor::collapsable);
|
2000-07-04 19:16:35 +00:00
|
|
|
|
setLabelFont(font);
|
2003-03-05 17:56:47 +00:00
|
|
|
|
params_.type = type;
|
2000-09-26 13:54:57 +00:00
|
|
|
|
setInsetName(type);
|
2002-07-21 21:21:06 +00:00
|
|
|
|
LyXTextClass const & tclass = bp.getLyXTextClass();
|
|
|
|
|
if (tclass.hasLayout(caplayout))
|
2003-12-01 13:35:49 +00:00
|
|
|
|
inset.paragraphs().begin()->layout(tclass[caplayout]);
|
2000-06-28 13:35:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-07-30 11:56:00 +00:00
|
|
|
|
InsetFloat::~InsetFloat()
|
|
|
|
|
{
|
2003-11-28 17:13:41 +00:00
|
|
|
|
InsetFloatMailer(*this).hideDialog();
|
2001-07-30 11:56:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-10-29 10:47:21 +00:00
|
|
|
|
DispatchResult
|
2004-01-20 14:25:24 +00:00
|
|
|
|
InsetFloat::priv_dispatch(LCursor & cur, FuncRequest const & cmd)
|
2000-06-28 13:35:52 +00:00
|
|
|
|
{
|
2003-03-05 19:46:08 +00:00
|
|
|
|
switch (cmd.action) {
|
2003-08-05 08:07:07 +00:00
|
|
|
|
|
2003-03-05 19:46:08 +00:00
|
|
|
|
case LFUN_INSET_MODIFY: {
|
|
|
|
|
InsetFloatParams params;
|
|
|
|
|
InsetFloatMailer::string2params(cmd.argument, params);
|
|
|
|
|
params_.placement = params.placement;
|
|
|
|
|
params_.wide = params.wide;
|
2004-01-20 14:25:24 +00:00
|
|
|
|
wide(params_.wide, cur.bv().buffer()->params());
|
|
|
|
|
cur.bv().update();
|
2003-11-03 19:52:47 +00:00
|
|
|
|
return DispatchResult(true, true);
|
2000-07-17 18:27:53 +00:00
|
|
|
|
}
|
2003-03-07 15:58:02 +00:00
|
|
|
|
|
|
|
|
|
case LFUN_INSET_DIALOG_UPDATE: {
|
2004-01-20 14:25:24 +00:00
|
|
|
|
InsetFloatMailer(*this).updateDialog(&cur.bv());
|
2003-11-03 19:52:47 +00:00
|
|
|
|
return DispatchResult(true, true);
|
2003-03-07 15:58:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
2003-03-05 19:46:08 +00:00
|
|
|
|
default:
|
2004-01-20 14:25:24 +00:00
|
|
|
|
return InsetCollapsable::priv_dispatch(cur, cmd);
|
2001-05-31 16:48:26 +00:00
|
|
|
|
}
|
2003-03-05 17:56:47 +00:00
|
|
|
|
}
|
|
|
|
|
|
2002-03-21 17:09:55 +00:00
|
|
|
|
|
2003-03-05 19:46:08 +00:00
|
|
|
|
void InsetFloatParams::write(ostream & os) const
|
2003-03-05 17:56:47 +00:00
|
|
|
|
{
|
2003-03-05 19:46:08 +00:00
|
|
|
|
os << "Float " // getInsetName()
|
|
|
|
|
<< type << '\n';
|
|
|
|
|
|
2003-08-05 08:07:07 +00:00
|
|
|
|
if (!placement.empty())
|
2003-03-05 19:46:08 +00:00
|
|
|
|
os << "placement " << placement << "\n";
|
2003-08-05 08:07:07 +00:00
|
|
|
|
|
|
|
|
|
if (wide)
|
2003-03-05 19:46:08 +00:00
|
|
|
|
os << "wide true\n";
|
2003-08-05 08:07:07 +00:00
|
|
|
|
else
|
2003-03-05 19:46:08 +00:00
|
|
|
|
os << "wide false\n";
|
2000-06-28 13:35:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-03-05 19:46:08 +00:00
|
|
|
|
void InsetFloatParams::read(LyXLex & lex)
|
2000-06-28 13:35:52 +00:00
|
|
|
|
{
|
2001-08-06 19:13:25 +00:00
|
|
|
|
if (lex.isOK()) {
|
2000-06-28 13:35:52 +00:00
|
|
|
|
lex.next();
|
2001-08-06 19:13:25 +00:00
|
|
|
|
string token = lex.getString();
|
2000-06-28 13:35:52 +00:00
|
|
|
|
if (token == "placement") {
|
|
|
|
|
lex.next();
|
2003-03-05 19:46:08 +00:00
|
|
|
|
placement = lex.getString();
|
2000-07-17 18:27:53 +00:00
|
|
|
|
} else {
|
2001-07-25 20:41:22 +00:00
|
|
|
|
// take countermeasures
|
|
|
|
|
lex.pushToken(token);
|
2000-06-28 13:35:52 +00:00
|
|
|
|
}
|
2001-05-31 16:48:26 +00:00
|
|
|
|
lex.next();
|
2001-08-06 19:13:25 +00:00
|
|
|
|
token = lex.getString();
|
2001-05-31 16:48:26 +00:00
|
|
|
|
if (token == "wide") {
|
|
|
|
|
lex.next();
|
2001-08-06 19:13:25 +00:00
|
|
|
|
string const tmptoken = lex.getString();
|
2003-03-05 19:46:08 +00:00
|
|
|
|
wide = (tmptoken == "true");
|
2001-05-31 16:48:26 +00:00
|
|
|
|
} else {
|
|
|
|
|
lyxerr << "InsetFloat::Read:: Missing wide!"
|
|
|
|
|
<< endl;
|
2001-07-25 20:41:22 +00:00
|
|
|
|
// take countermeasures
|
|
|
|
|
lex.pushToken(token);
|
2001-05-31 16:48:26 +00:00
|
|
|
|
}
|
2000-06-28 13:35:52 +00:00
|
|
|
|
}
|
2003-03-05 17:56:47 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-08-28 07:41:31 +00:00
|
|
|
|
void InsetFloat::write(Buffer const & buf, ostream & os) const
|
2003-03-05 19:46:08 +00:00
|
|
|
|
{
|
|
|
|
|
params_.write(os);
|
|
|
|
|
InsetCollapsable::write(buf, os);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-08-28 07:41:31 +00:00
|
|
|
|
void InsetFloat::read(Buffer const & buf, LyXLex & lex)
|
2003-03-05 17:56:47 +00:00
|
|
|
|
{
|
2003-03-05 19:46:08 +00:00
|
|
|
|
params_.read(lex);
|
2003-09-09 09:47:59 +00:00
|
|
|
|
wide(params_.wide, buf.params());
|
2001-06-28 10:25:20 +00:00
|
|
|
|
InsetCollapsable::read(buf, lex);
|
2000-06-28 13:35:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-06-28 10:25:20 +00:00
|
|
|
|
void InsetFloat::validate(LaTeXFeatures & features) const
|
2000-06-28 13:35:52 +00:00
|
|
|
|
{
|
2004-02-01 12:46:14 +00:00
|
|
|
|
if (contains(params_.placement, 'H')) {
|
2002-01-10 10:05:45 +00:00
|
|
|
|
features.require("float");
|
2001-07-30 11:56:00 +00:00
|
|
|
|
}
|
2002-03-21 17:09:55 +00:00
|
|
|
|
|
2003-03-05 17:56:47 +00:00
|
|
|
|
features.useFloat(params_.type);
|
2001-06-28 10:25:20 +00:00
|
|
|
|
InsetCollapsable::validate(features);
|
2000-06-28 13:35:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-07-25 17:11:25 +00:00
|
|
|
|
auto_ptr<InsetBase> InsetFloat::clone() const
|
2000-06-28 13:35:52 +00:00
|
|
|
|
{
|
2003-07-25 17:11:25 +00:00
|
|
|
|
return auto_ptr<InsetBase>(new InsetFloat(*this));
|
2000-06-28 13:35:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-06-28 10:25:20 +00:00
|
|
|
|
string const InsetFloat::editMessage() const
|
2000-06-28 13:35:52 +00:00
|
|
|
|
{
|
2000-07-04 19:16:35 +00:00
|
|
|
|
return _("Opened Float Inset");
|
2000-06-28 13:35:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-08-28 07:41:31 +00:00
|
|
|
|
int InsetFloat::latex(Buffer const & buf, ostream & os,
|
2003-11-05 12:06:20 +00:00
|
|
|
|
OutputParams const & runparams) const
|
2000-06-28 13:35:52 +00:00
|
|
|
|
{
|
2003-09-09 09:47:59 +00:00
|
|
|
|
FloatList const & floats = buf.params().getLyXTextClass().floats();
|
2003-03-05 17:56:47 +00:00
|
|
|
|
string const tmptype = (params_.wide ? params_.type + "*" : params_.type);
|
2001-07-04 07:44:27 +00:00
|
|
|
|
// Figure out the float placement to use.
|
|
|
|
|
// From lowest to highest:
|
|
|
|
|
// - float default placement
|
|
|
|
|
// - document wide default placement
|
|
|
|
|
// - specific float placement
|
|
|
|
|
string placement;
|
2003-09-09 09:47:59 +00:00
|
|
|
|
string const buf_placement = buf.params().float_placement;
|
2003-03-05 17:56:47 +00:00
|
|
|
|
string const def_placement = floats.defaultPlacement(params_.type);
|
|
|
|
|
if (!params_.placement.empty()
|
|
|
|
|
&& params_.placement != def_placement) {
|
|
|
|
|
placement = params_.placement;
|
|
|
|
|
} else if (params_.placement.empty()
|
2002-09-26 08:59:34 +00:00
|
|
|
|
&& !buf_placement.empty()
|
2001-07-04 07:44:27 +00:00
|
|
|
|
&& buf_placement != def_placement) {
|
|
|
|
|
placement = buf_placement;
|
|
|
|
|
}
|
2002-03-21 17:09:55 +00:00
|
|
|
|
|
2002-05-05 15:15:51 +00:00
|
|
|
|
// The \n is used to force \begin{<floatname>} to appear in a new line.
|
|
|
|
|
// The % is needed to prevent two consecutive \n chars in the case
|
|
|
|
|
// when the current output line is empty.
|
2002-11-27 10:30:28 +00:00
|
|
|
|
os << "%\n\\begin{" << tmptype << '}';
|
2001-07-04 07:44:27 +00:00
|
|
|
|
// We only output placement if different from the def_placement.
|
|
|
|
|
if (!placement.empty()) {
|
2002-11-27 10:30:28 +00:00
|
|
|
|
os << '[' << placement << ']';
|
2001-07-04 07:44:27 +00:00
|
|
|
|
}
|
2002-11-27 10:30:28 +00:00
|
|
|
|
os << '\n';
|
2002-03-21 17:09:55 +00:00
|
|
|
|
|
2003-05-23 08:59:47 +00:00
|
|
|
|
int const i = inset.latex(buf, os, runparams);
|
2002-05-05 15:15:51 +00:00
|
|
|
|
|
|
|
|
|
// The \n is used to force \end{<floatname>} to appear in a new line.
|
|
|
|
|
// In this case, we do not case if the current output line is empty.
|
|
|
|
|
os << "\n\\end{" << tmptype << "}\n";
|
2002-03-21 17:09:55 +00:00
|
|
|
|
|
2002-05-09 13:36:45 +00:00
|
|
|
|
return i + 4;
|
2000-06-28 13:35:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-10-31 18:45:43 +00:00
|
|
|
|
int InsetFloat::linuxdoc(Buffer const & buf, ostream & os,
|
2003-11-05 12:06:20 +00:00
|
|
|
|
OutputParams const & runparams) const
|
2003-07-26 21:53:54 +00:00
|
|
|
|
{
|
2003-09-09 09:47:59 +00:00
|
|
|
|
FloatList const & floats = buf.params().getLyXTextClass().floats();
|
2003-07-26 21:53:54 +00:00
|
|
|
|
string const tmptype = params_.type;
|
|
|
|
|
// Figure out the float placement to use.
|
|
|
|
|
// From lowest to highest:
|
|
|
|
|
// - float default placement
|
|
|
|
|
// - document wide default placement
|
|
|
|
|
// - specific float placement
|
|
|
|
|
// This is the same as latex, as linuxdoc is modeled after latex.
|
|
|
|
|
|
|
|
|
|
string placement;
|
2003-09-09 09:47:59 +00:00
|
|
|
|
string const buf_placement = buf.params().float_placement;
|
2003-07-26 21:53:54 +00:00
|
|
|
|
string const def_placement = floats.defaultPlacement(params_.type);
|
|
|
|
|
if (!params_.placement.empty()
|
|
|
|
|
&& params_.placement != def_placement) {
|
|
|
|
|
placement = params_.placement;
|
|
|
|
|
} else if (params_.placement.empty()
|
|
|
|
|
&& !buf_placement.empty()
|
|
|
|
|
&& buf_placement != def_placement) {
|
|
|
|
|
placement = buf_placement;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
os << "\n<" << tmptype ;
|
|
|
|
|
// We only output placement if different from the def_placement.
|
|
|
|
|
if (!placement.empty()) {
|
|
|
|
|
os << " loc=\"" << placement << '"';
|
|
|
|
|
}
|
|
|
|
|
os << ">";
|
|
|
|
|
|
2003-10-31 18:45:43 +00:00
|
|
|
|
int const i = inset.linuxdoc(buf, os, runparams);
|
2003-07-26 21:53:54 +00:00
|
|
|
|
os << "</" << tmptype << ">\n";
|
|
|
|
|
|
|
|
|
|
return i;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-10-31 18:45:43 +00:00
|
|
|
|
int InsetFloat::docbook(Buffer const & buf, ostream & os,
|
2003-11-05 12:06:20 +00:00
|
|
|
|
OutputParams const & runparams) const
|
2001-03-23 08:37:44 +00:00
|
|
|
|
{
|
2003-03-05 17:56:47 +00:00
|
|
|
|
os << '<' << params_.type << '>';
|
2003-10-31 18:45:43 +00:00
|
|
|
|
int const i = inset.docbook(buf, os, runparams);
|
2003-03-05 17:56:47 +00:00
|
|
|
|
os << "</" << params_.type << '>';
|
2001-03-23 08:37:44 +00:00
|
|
|
|
|
|
|
|
|
return i;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-07-25 21:20:24 +00:00
|
|
|
|
bool InsetFloat::insetAllowed(InsetOld::Code code) const
|
2001-07-12 14:35:38 +00:00
|
|
|
|
{
|
2003-12-01 13:35:49 +00:00
|
|
|
|
return code != InsetOld::FLOAT_CODE
|
2004-02-01 12:46:14 +00:00
|
|
|
|
&& code != InsetOld::FOOT_CODE
|
2003-12-01 13:35:49 +00:00
|
|
|
|
&& code != InsetOld::MARGIN_CODE;
|
2000-06-28 13:35:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-07-04 19:16:35 +00:00
|
|
|
|
|
2001-07-30 11:56:00 +00:00
|
|
|
|
bool InsetFloat::showInsetDialog(BufferView * bv) const
|
|
|
|
|
{
|
2003-11-10 09:06:48 +00:00
|
|
|
|
if (!inset.showInsetDialog(bv))
|
|
|
|
|
InsetFloatMailer(const_cast<InsetFloat &>(*this)).showDialog(bv);
|
2001-07-30 11:56:00 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-08-27 15:51:19 +00:00
|
|
|
|
void InsetFloat::wide(bool w, BufferParams const & bp)
|
2000-07-15 23:51:46 +00:00
|
|
|
|
{
|
2003-03-05 17:56:47 +00:00
|
|
|
|
params_.wide = w;
|
2003-11-10 09:06:48 +00:00
|
|
|
|
string lab = _("float: ") + floatname(params_.type, bp);
|
2003-03-05 17:56:47 +00:00
|
|
|
|
if (params_.wide)
|
2002-11-27 10:30:28 +00:00
|
|
|
|
lab += '*';
|
2002-04-26 15:38:15 +00:00
|
|
|
|
setLabel(lab);
|
2000-07-15 23:51:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-08-28 07:41:31 +00:00
|
|
|
|
void InsetFloat::addToToc(lyx::toc::TocList & toclist, Buffer const & buf) const
|
2002-07-21 21:21:06 +00:00
|
|
|
|
{
|
2003-12-01 13:35:49 +00:00
|
|
|
|
ParIterator pit(inset.paragraphs().begin(), inset.paragraphs());
|
|
|
|
|
ParIterator end(inset.paragraphs().end(), inset.paragraphs());
|
2002-10-30 15:09:55 +00:00
|
|
|
|
|
2003-05-22 11:19:31 +00:00
|
|
|
|
// Find a caption layout in one of the (child inset's) pars
|
2002-10-30 15:09:55 +00:00
|
|
|
|
for (; pit != end; ++pit) {
|
2003-05-22 10:47:31 +00:00
|
|
|
|
if (pit->layout()->name() == caplayout) {
|
2003-09-09 09:47:59 +00:00
|
|
|
|
string const name = floatname(params_.type, buf.params());
|
2002-07-21 21:21:06 +00:00
|
|
|
|
string const str =
|
2002-12-08 22:33:55 +00:00
|
|
|
|
tostr(toclist[name].size() + 1)
|
2003-05-22 10:47:31 +00:00
|
|
|
|
+ ". " + pit->asString(buf, false);
|
2003-07-27 13:18:55 +00:00
|
|
|
|
lyx::toc::TocItem const item(pit->id(), 0 , str);
|
2002-12-08 22:33:55 +00:00
|
|
|
|
toclist[name].push_back(item);
|
2002-07-21 21:21:06 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2003-03-05 19:46:08 +00:00
|
|
|
|
|
|
|
|
|
|
2003-03-07 14:08:10 +00:00
|
|
|
|
string const InsetFloatMailer::name_("float");
|
|
|
|
|
|
2003-03-05 19:46:08 +00:00
|
|
|
|
InsetFloatMailer::InsetFloatMailer(InsetFloat & inset)
|
2003-03-07 14:08:10 +00:00
|
|
|
|
: inset_(inset)
|
2003-03-05 19:46:08 +00:00
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
2003-07-23 09:54:21 +00:00
|
|
|
|
string const InsetFloatMailer::inset2string(Buffer const &) const
|
2003-03-05 19:46:08 +00:00
|
|
|
|
{
|
2003-03-07 14:08:10 +00:00
|
|
|
|
return params2string(inset_.params());
|
2003-03-05 19:46:08 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void InsetFloatMailer::string2params(string const & in,
|
|
|
|
|
InsetFloatParams & params)
|
|
|
|
|
{
|
|
|
|
|
params = InsetFloatParams();
|
2003-04-24 20:02:49 +00:00
|
|
|
|
if (in.empty())
|
|
|
|
|
return;
|
2003-05-21 21:20:50 +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 19:46:08 +00:00
|
|
|
|
|
2003-12-11 15:23:15 +00:00
|
|
|
|
string name;
|
|
|
|
|
lex >> name;
|
|
|
|
|
if (!lex || name != name_)
|
|
|
|
|
return print_mailer_error("InsetFloatMailer", in, 1, name_);
|
2003-03-05 19:46:08 +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 != "Float")
|
|
|
|
|
return print_mailer_error("InsetBoxMailer", in, 2, "Float");
|
2003-03-05 19:46:08 +00:00
|
|
|
|
|
2003-12-11 15:23:15 +00:00
|
|
|
|
params.read(lex);
|
2003-03-05 19:46:08 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-05-13 16:24:49 +00:00
|
|
|
|
string const InsetFloatMailer::params2string(InsetFloatParams const & params)
|
2003-03-05 19:46:08 +00:00
|
|
|
|
{
|
|
|
|
|
ostringstream data;
|
2003-03-07 14:08:10 +00:00
|
|
|
|
data << name_ << ' ';
|
2003-03-05 19:46:08 +00:00
|
|
|
|
params.write(data);
|
2003-09-15 11:00:00 +00:00
|
|
|
|
return data.str();
|
2003-03-05 19:46:08 +00:00
|
|
|
|
}
|