2000-06-28 13:35:52 +00:00
|
|
|
|
/* This file is part of
|
|
|
|
|
* ======================================================
|
2002-03-21 17:09:55 +00:00
|
|
|
|
*
|
2000-06-28 13:35:52 +00:00
|
|
|
|
* LyX, The Document Processor
|
2002-03-21 17:09:55 +00:00
|
|
|
|
*
|
2001-05-30 13:53:44 +00:00
|
|
|
|
* Copyright 1998-2001 The LyX Team.
|
2000-06-28 13:35:52 +00:00
|
|
|
|
*
|
2000-12-29 12:48:02 +00:00
|
|
|
|
* ====================================================== */
|
2000-06-28 13:35:52 +00:00
|
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
|
|
#ifdef __GNUG__
|
|
|
|
|
#pragma implementation
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#include "insetfloat.h"
|
|
|
|
|
#include "gettext.h"
|
|
|
|
|
#include "lyxfont.h"
|
|
|
|
|
#include "BufferView.h"
|
|
|
|
|
#include "lyxtext.h"
|
2000-07-04 11:30:07 +00:00
|
|
|
|
#include "insets/insettext.h"
|
2000-06-28 13:35:52 +00:00
|
|
|
|
#include "support/LOstream.h"
|
2001-07-30 11:56:00 +00:00
|
|
|
|
#include "support/lstrings.h"
|
2000-06-28 13:35:52 +00:00
|
|
|
|
#include "FloatList.h"
|
|
|
|
|
#include "LaTeXFeatures.h"
|
|
|
|
|
#include "debug.h"
|
2000-07-15 23:51:46 +00:00
|
|
|
|
#include "Floating.h"
|
2001-07-04 07:44:27 +00:00
|
|
|
|
#include "buffer.h"
|
2002-05-23 12:08:47 +00:00
|
|
|
|
#include "frontends/LyXView.h"
|
2001-07-30 11:56:00 +00:00
|
|
|
|
#include "frontends/Dialogs.h"
|
2002-07-21 21:21:06 +00:00
|
|
|
|
#include "lyxlex.h"
|
2000-06-28 13:35:52 +00:00
|
|
|
|
|
|
|
|
|
using std::ostream;
|
|
|
|
|
using std::endl;
|
|
|
|
|
|
|
|
|
|
// 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-04-26 15:38:15 +00:00
|
|
|
|
string floatname(string const & type)
|
|
|
|
|
{
|
|
|
|
|
FloatList::const_iterator it = floatList[type];
|
|
|
|
|
if (it == floatList.end())
|
|
|
|
|
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)
|
|
|
|
|
: InsetCollapsable(bp), wide_(false)
|
2000-06-28 13:35:52 +00:00
|
|
|
|
{
|
2002-04-26 15:38:15 +00:00
|
|
|
|
string lab(_("float: "));
|
|
|
|
|
lab += floatname(type);
|
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);
|
2000-12-29 12:48:02 +00:00
|
|
|
|
floatType_ = 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))
|
|
|
|
|
inset.paragraph()->layout(tclass[caplayout]);
|
2000-06-28 13:35:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-07-24 15:07:09 +00:00
|
|
|
|
InsetFloat::InsetFloat(InsetFloat const & in, bool same_id)
|
|
|
|
|
: InsetCollapsable(in, same_id), floatType_(in.floatType_),
|
|
|
|
|
floatPlacement_(in.floatPlacement_), wide_(in.wide_)
|
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
2001-07-30 11:56:00 +00:00
|
|
|
|
InsetFloat::~InsetFloat()
|
|
|
|
|
{
|
|
|
|
|
hideDialog();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-06-28 10:25:20 +00:00
|
|
|
|
void InsetFloat::write(Buffer const * buf, ostream & os) const
|
2000-06-28 13:35:52 +00:00
|
|
|
|
{
|
2000-07-19 08:37:26 +00:00
|
|
|
|
os << "Float " // getInsetName()
|
2000-12-29 12:48:02 +00:00
|
|
|
|
<< floatType_ << '\n';
|
2000-07-17 18:27:53 +00:00
|
|
|
|
|
2002-07-25 11:06:25 +00:00
|
|
|
|
if (!floatPlacement_.empty()) {
|
2000-12-29 12:48:02 +00:00
|
|
|
|
os << "placement " << floatPlacement_ << "\n";
|
2000-07-17 18:27:53 +00:00
|
|
|
|
}
|
2001-05-31 16:48:26 +00:00
|
|
|
|
if (wide_) {
|
|
|
|
|
os << "wide true\n";
|
|
|
|
|
} else {
|
|
|
|
|
os << "wide false\n";
|
|
|
|
|
}
|
2002-03-21 17:09:55 +00:00
|
|
|
|
|
2001-06-28 10:25:20 +00:00
|
|
|
|
InsetCollapsable::write(buf, os);
|
2000-06-28 13:35:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-06-28 10:25:20 +00:00
|
|
|
|
void InsetFloat::read(Buffer const * buf, 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();
|
2001-08-06 19:13:25 +00:00
|
|
|
|
floatPlacement_ = 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();
|
2001-05-31 16:48:26 +00:00
|
|
|
|
if (tmptoken == "true")
|
|
|
|
|
wide(true);
|
|
|
|
|
else
|
|
|
|
|
wide(false);
|
|
|
|
|
} 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
|
|
|
|
}
|
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
|
|
|
|
{
|
2001-07-30 11:56:00 +00:00
|
|
|
|
if (contains(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
|
|
|
|
|
2001-11-19 15:34:11 +00:00
|
|
|
|
features.useFloat(floatType_);
|
2001-06-28 10:25:20 +00:00
|
|
|
|
InsetCollapsable::validate(features);
|
2000-06-28 13:35:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-07-06 15:57:54 +00:00
|
|
|
|
Inset * InsetFloat::clone(Buffer const &, bool same_id) const
|
2000-06-28 13:35:52 +00:00
|
|
|
|
{
|
2001-07-24 15:07:09 +00:00
|
|
|
|
return new InsetFloat(*const_cast<InsetFloat *>(this), same_id);
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-06-28 10:25:20 +00:00
|
|
|
|
int InsetFloat::latex(Buffer const * buf,
|
2000-06-28 13:35:52 +00:00
|
|
|
|
ostream & os, bool fragile, bool fp) const
|
|
|
|
|
{
|
2001-05-31 16:48:26 +00:00
|
|
|
|
string const tmptype = (wide_ ? floatType_ + "*" : floatType_);
|
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;
|
|
|
|
|
string const buf_placement = buf->params.float_placement;
|
|
|
|
|
string const def_placement = floatList.defaultPlacement(floatType_);
|
|
|
|
|
if (!floatPlacement_.empty()
|
|
|
|
|
&& floatPlacement_ != def_placement) {
|
|
|
|
|
placement = floatPlacement_;
|
|
|
|
|
} else if (!buf_placement.empty()
|
|
|
|
|
&& 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.
|
|
|
|
|
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()) {
|
|
|
|
|
os << "[" << placement << "]";
|
|
|
|
|
}
|
2002-05-05 15:15:51 +00:00
|
|
|
|
os << "\n";
|
2002-03-21 17:09:55 +00:00
|
|
|
|
|
2001-06-28 10:25:20 +00:00
|
|
|
|
int const i = inset.latex(buf, os, fragile, fp);
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-06-18 15:44:30 +00:00
|
|
|
|
int InsetFloat::docbook(Buffer const * buf, ostream & os, bool mixcont) const
|
2001-03-23 08:37:44 +00:00
|
|
|
|
{
|
|
|
|
|
os << "<" << floatType_ << ">";
|
2002-06-18 15:44:30 +00:00
|
|
|
|
int const i = inset.docbook(buf, os, mixcont);
|
2001-03-23 08:37:44 +00:00
|
|
|
|
os << "</" << floatType_ << ">";
|
|
|
|
|
|
|
|
|
|
return i;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-07-19 08:52:59 +00:00
|
|
|
|
bool InsetFloat::insetAllowed(Inset::Code code) const
|
2001-07-12 14:35:38 +00:00
|
|
|
|
{
|
|
|
|
|
if (code == Inset::FLOAT_CODE)
|
2001-07-12 12:26:06 +00:00
|
|
|
|
return false;
|
2001-07-13 10:26:31 +00:00
|
|
|
|
if (inset.getLockingInset() != const_cast<InsetFloat *>(this))
|
2001-07-19 08:52:59 +00:00
|
|
|
|
return inset.insetAllowed(code);
|
2001-07-12 14:35:38 +00:00
|
|
|
|
if ((code == Inset::FOOT_CODE) || (code == Inset::MARGIN_CODE))
|
2000-07-04 19:16:35 +00:00
|
|
|
|
return false;
|
|
|
|
|
return true;
|
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
|
|
|
|
|
{
|
|
|
|
|
if (!inset.showInsetDialog(bv)) {
|
2002-03-21 17:09:55 +00:00
|
|
|
|
bv->owner()->getDialogs()->showFloat(const_cast<InsetFloat *>(this));
|
2001-07-30 11:56:00 +00:00
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2002-03-21 17:09:55 +00:00
|
|
|
|
string const & InsetFloat::type() const
|
2000-07-18 17:45:27 +00:00
|
|
|
|
{
|
2000-12-29 12:48:02 +00:00
|
|
|
|
return floatType_;
|
2000-07-18 17:45:27 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-03-11 03:20:44 +00:00
|
|
|
|
void InsetFloat::placement(string const & p)
|
|
|
|
|
{
|
2001-08-19 13:13:47 +00:00
|
|
|
|
// FIX: Here we should only allow the placement to be set
|
2001-03-11 03:20:44 +00:00
|
|
|
|
// if a valid value.
|
|
|
|
|
floatPlacement_ = p;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
string const & InsetFloat::placement() const
|
|
|
|
|
{
|
|
|
|
|
return floatPlacement_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2000-07-15 23:51:46 +00:00
|
|
|
|
void InsetFloat::wide(bool w)
|
|
|
|
|
{
|
|
|
|
|
wide_ = w;
|
2002-04-26 15:38:15 +00:00
|
|
|
|
|
|
|
|
|
string lab(_("float:"));
|
|
|
|
|
lab += floatname(floatType_);
|
|
|
|
|
|
|
|
|
|
if (wide_)
|
2000-07-15 23:51:46 +00:00
|
|
|
|
lab += "*";
|
2002-04-26 15:38:15 +00:00
|
|
|
|
|
|
|
|
|
setLabel(lab);
|
2000-07-15 23:51:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool InsetFloat::wide() const
|
|
|
|
|
{
|
|
|
|
|
return wide_;
|
|
|
|
|
}
|
2002-07-21 21:21:06 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void InsetFloat::addToToc(toc::TocList & toclist, Buffer const * buf) const
|
|
|
|
|
{
|
|
|
|
|
// Now find the caption in the float...
|
|
|
|
|
// We now tranverse the paragraphs of
|
|
|
|
|
// the inset...
|
|
|
|
|
Paragraph * tmp = inset.paragraph();
|
|
|
|
|
while (tmp) {
|
|
|
|
|
if (tmp->layout()->name() == caplayout) {
|
|
|
|
|
string const str =
|
|
|
|
|
tostr(toclist[type()].size() + 1)
|
|
|
|
|
+ ". " + tmp->asString(buf, false);
|
|
|
|
|
toc::TocItem const item(tmp, 0 , str);
|
|
|
|
|
toclist[type()].push_back(item);
|
|
|
|
|
}
|
|
|
|
|
tmp = tmp->next();
|
|
|
|
|
}
|
|
|
|
|
}
|