2000-06-28 13:35:52 +00:00
|
|
|
|
/* This file is part of
|
|
|
|
|
* ======================================================
|
|
|
|
|
*
|
|
|
|
|
* LyX, The Document Processor
|
|
|
|
|
*
|
2000-12-29 12:48:02 +00:00
|
|
|
|
* Copyright 1998-2000 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"
|
|
|
|
|
#include "FloatList.h"
|
|
|
|
|
#include "LaTeXFeatures.h"
|
|
|
|
|
#include "debug.h"
|
2000-07-15 23:51:46 +00:00
|
|
|
|
#include "Floating.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
|
|
|
|
|
// floats will be numbered within chapters.
|
|
|
|
|
// \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
|
|
|
|
|
|
2000-07-15 23:51:46 +00:00
|
|
|
|
InsetFloat::InsetFloat(string const & type)
|
2001-03-11 03:20:44 +00:00
|
|
|
|
: InsetCollapsable(), wide_(false)
|
2000-06-28 13:35:52 +00:00
|
|
|
|
{
|
2000-07-15 23:51:46 +00:00
|
|
|
|
string lab(_("float:"));
|
|
|
|
|
lab += type;
|
|
|
|
|
setLabel(lab);
|
2000-07-04 19:16:35 +00:00
|
|
|
|
LyXFont font(LyXFont::ALL_SANE);
|
|
|
|
|
font.decSize();
|
|
|
|
|
font.decSize();
|
|
|
|
|
font.setColor(LColor::footnote);
|
|
|
|
|
setLabelFont(font);
|
|
|
|
|
setAutoCollapse(false);
|
2000-12-29 12:48:02 +00:00
|
|
|
|
floatType_ = type;
|
2000-09-26 13:54:57 +00:00
|
|
|
|
setInsetName(type);
|
2000-06-28 13:35:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void InsetFloat::Write(Buffer const * buf, ostream & os) const
|
|
|
|
|
{
|
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
|
|
|
|
|
2000-12-29 12:48:02 +00:00
|
|
|
|
if (floatPlacement_.empty()) {
|
2000-07-17 18:27:53 +00:00
|
|
|
|
os << "placement "
|
2000-12-29 12:48:02 +00:00
|
|
|
|
<< floatList.getType(floatType_).placement() << "\n";
|
2000-07-17 18:27:53 +00:00
|
|
|
|
} else {
|
2000-12-29 12:48:02 +00:00
|
|
|
|
os << "placement " << floatPlacement_ << "\n";
|
2000-07-17 18:27:53 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-06-28 13:35:52 +00:00
|
|
|
|
InsetCollapsable::Write(buf, os);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void InsetFloat::Read(Buffer const * buf, LyXLex & lex)
|
|
|
|
|
{
|
|
|
|
|
if (lex.IsOK()) {
|
|
|
|
|
lex.next();
|
2001-03-20 01:22:46 +00:00
|
|
|
|
string const token = lex.GetString();
|
2000-06-28 13:35:52 +00:00
|
|
|
|
if (token == "placement") {
|
|
|
|
|
lex.next();
|
2000-12-29 12:48:02 +00:00
|
|
|
|
floatPlacement_ = lex.GetString();
|
2000-07-17 18:27:53 +00:00
|
|
|
|
} else {
|
|
|
|
|
lyxerr << "InsetFloat::Read: Missing placement!"
|
|
|
|
|
<< endl;
|
2000-06-28 13:35:52 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
InsetCollapsable::Read(buf, lex);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void InsetFloat::Validate(LaTeXFeatures & features) const
|
|
|
|
|
{
|
2000-12-29 12:48:02 +00:00
|
|
|
|
features.usedFloats.insert(floatType_);
|
2000-06-28 13:35:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2000-10-10 11:50:43 +00:00
|
|
|
|
Inset * InsetFloat::Clone(Buffer const &) const
|
2000-06-28 13:35:52 +00:00
|
|
|
|
{
|
2000-12-29 12:48:02 +00:00
|
|
|
|
InsetFloat * result = new InsetFloat(floatType_);
|
2000-07-04 19:16:35 +00:00
|
|
|
|
result->inset->init(inset);
|
2000-06-28 13:35:52 +00:00
|
|
|
|
|
2000-07-04 19:16:35 +00:00
|
|
|
|
result->collapsed = collapsed;
|
|
|
|
|
return result;
|
2000-06-28 13:35:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2000-09-14 17:53:12 +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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int InsetFloat::Latex(Buffer const * buf,
|
|
|
|
|
ostream & os, bool fragile, bool fp) const
|
|
|
|
|
{
|
2000-12-29 12:48:02 +00:00
|
|
|
|
os << "\\begin{" << floatType_ << "}";
|
|
|
|
|
if (!floatPlacement_.empty()
|
|
|
|
|
&& floatPlacement_ != floatList.defaultPlacement(floatType_))
|
|
|
|
|
os << "[" << floatPlacement_ << "]";
|
2000-06-28 13:35:52 +00:00
|
|
|
|
os << "%\n";
|
|
|
|
|
|
2000-12-29 12:48:02 +00:00
|
|
|
|
int const i = inset->Latex(buf, os, fragile, fp);
|
|
|
|
|
os << "\\end{" << floatType_ << "}%\n";
|
2000-07-04 19:16:35 +00:00
|
|
|
|
|
|
|
|
|
return i + 2;
|
2000-06-28 13:35:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-03-23 08:37:44 +00:00
|
|
|
|
int InsetFloat::DocBook(Buffer const * buf, ostream & os) const
|
|
|
|
|
{
|
|
|
|
|
os << "<" << floatType_ << ">";
|
|
|
|
|
int const i = inset->DocBook(buf, os);
|
|
|
|
|
os << "</" << floatType_ << ">";
|
|
|
|
|
|
|
|
|
|
return i;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2000-07-04 11:30:07 +00:00
|
|
|
|
bool InsetFloat::InsertInsetAllowed(Inset * in) const
|
2000-06-28 13:35:52 +00:00
|
|
|
|
{
|
2000-07-04 19:16:35 +00:00
|
|
|
|
if ((in->LyxCode() == Inset::FOOT_CODE) ||
|
|
|
|
|
(in->LyxCode() == Inset::MARGIN_CODE)) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
2000-06-28 13:35:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-07-04 19:16:35 +00:00
|
|
|
|
|
2000-06-28 13:35:52 +00:00
|
|
|
|
void InsetFloat::InsetButtonRelease(BufferView * bv, int x, int y, int button)
|
|
|
|
|
{
|
|
|
|
|
if (x >= 0
|
|
|
|
|
&& x < button_length
|
|
|
|
|
&& y >= button_top_y
|
|
|
|
|
&& y < button_bottom_y
|
|
|
|
|
&& button == 3) {
|
|
|
|
|
// This obviously need to change.
|
|
|
|
|
lyxerr << "InsetFloat: Let's edit this floats parameters!"
|
|
|
|
|
<< endl;
|
|
|
|
|
} else {
|
|
|
|
|
InsetCollapsable::InsetButtonRelease(bv, x, y, button);
|
|
|
|
|
}
|
|
|
|
|
}
|
2000-07-04 19:16:35 +00:00
|
|
|
|
|
2000-07-15 23:51:46 +00:00
|
|
|
|
|
2000-07-18 17:45:27 +00:00
|
|
|
|
string const & InsetFloat::type() const
|
|
|
|
|
{
|
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)
|
|
|
|
|
{
|
|
|
|
|
// Here we should only allow the placement to be set
|
|
|
|
|
// if a valid value.
|
|
|
|
|
#warning FIX!
|
|
|
|
|
floatPlacement_ = p;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
string const & InsetFloat::placement() const
|
|
|
|
|
{
|
|
|
|
|
return floatPlacement_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2000-07-15 23:51:46 +00:00
|
|
|
|
void InsetFloat::wide(bool w)
|
|
|
|
|
{
|
|
|
|
|
wide_ = w;
|
|
|
|
|
if (wide_) {
|
|
|
|
|
string lab(_("float:"));
|
2000-12-29 12:48:02 +00:00
|
|
|
|
lab += floatType_;
|
2000-07-15 23:51:46 +00:00
|
|
|
|
lab += "*";
|
|
|
|
|
setLabel(lab);
|
|
|
|
|
} else {
|
|
|
|
|
string lab(_("float:"));
|
2000-12-29 12:48:02 +00:00
|
|
|
|
lab += floatType_;
|
2000-07-15 23:51:46 +00:00
|
|
|
|
setLabel(lab);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool InsetFloat::wide() const
|
|
|
|
|
{
|
|
|
|
|
return wide_;
|
|
|
|
|
}
|