2000-06-28 13:35:52 +00:00
|
|
|
|
/* This file is part of
|
|
|
|
|
* ======================================================
|
|
|
|
|
*
|
|
|
|
|
* LyX, The Document Processor
|
|
|
|
|
*
|
|
|
|
|
* Copyright 1998 The LyX Team.
|
|
|
|
|
*
|
|
|
|
|
*======================================================*/
|
|
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
|
|
#ifdef __GNUG__
|
|
|
|
|
#pragma implementation
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#include "insetfloat.h"
|
|
|
|
|
#include "gettext.h"
|
|
|
|
|
#include "lyxfont.h"
|
|
|
|
|
#include "BufferView.h"
|
|
|
|
|
#include "Painter.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"
|
|
|
|
|
|
|
|
|
|
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}
|
|
|
|
|
//
|
|
|
|
|
// Lgb
|
|
|
|
|
|
|
|
|
|
InsetFloat::InsetFloat() : InsetCollapsable()
|
|
|
|
|
{
|
2000-07-04 19:16:35 +00:00
|
|
|
|
setLabel(_("float"));
|
|
|
|
|
LyXFont font(LyXFont::ALL_SANE);
|
|
|
|
|
font.decSize();
|
|
|
|
|
font.decSize();
|
|
|
|
|
font.setColor(LColor::footnote);
|
|
|
|
|
setLabelFont(font);
|
|
|
|
|
setAutoCollapse(false);
|
|
|
|
|
setInsetName("Float");
|
|
|
|
|
floatType = "table";
|
|
|
|
|
floatPlacement = "H";
|
2000-06-28 13:35:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void InsetFloat::Write(Buffer const * buf, ostream & os) const
|
|
|
|
|
{
|
|
|
|
|
os << getInsetName()
|
|
|
|
|
<< "\ntype " << floatType
|
|
|
|
|
<< "\nplacement " << floatPlacement << "\n";
|
|
|
|
|
InsetCollapsable::Write(buf, os);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void InsetFloat::Read(Buffer const * buf, LyXLex & lex)
|
|
|
|
|
{
|
|
|
|
|
if (lex.IsOK()) {
|
|
|
|
|
lex.next();
|
|
|
|
|
string token = lex.GetString();
|
|
|
|
|
if (token == "type") {
|
|
|
|
|
lex.next();
|
|
|
|
|
floatType = lex.GetString();
|
|
|
|
|
}
|
|
|
|
|
lex.next();
|
|
|
|
|
token = lex.GetString();
|
|
|
|
|
if (token == "placement") {
|
|
|
|
|
lex.next();
|
|
|
|
|
floatPlacement = lex.GetString();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
InsetCollapsable::Read(buf, lex);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void InsetFloat::Validate(LaTeXFeatures & features) const
|
|
|
|
|
{
|
|
|
|
|
features.usedFloats.insert(floatType);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Inset * InsetFloat::Clone() const
|
|
|
|
|
{
|
2000-07-04 19:16:35 +00:00
|
|
|
|
InsetFloat * result = new InsetFloat;
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
char const * InsetFloat::EditMessage() const
|
|
|
|
|
{
|
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
|
|
|
|
|
{
|
|
|
|
|
os << "\\begin{" << floatType << "}";
|
|
|
|
|
if (!floatPlacement.empty()
|
|
|
|
|
&& floatPlacement != floatList.defaultPlacement(floatType))
|
|
|
|
|
os << "[" << floatPlacement << "]";
|
|
|
|
|
os << "%\n";
|
|
|
|
|
|
2000-07-04 19:16:35 +00:00
|
|
|
|
int i = inset->Latex(buf, os, fragile, fp);
|
|
|
|
|
os << "\\end{" << floatType << "}%\n";
|
|
|
|
|
|
|
|
|
|
return i + 2;
|
2000-06-28 13:35:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
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-07-04 11:30:07 +00:00
|
|
|
|
#if 0
|
2000-06-28 13:35:52 +00:00
|
|
|
|
LyXFont InsetFloat::GetDrawFont(BufferView * bv,
|
|
|
|
|
LyXParagraph * p, int pos) const
|
|
|
|
|
{
|
2000-07-04 19:16:35 +00:00
|
|
|
|
LyXFont fn = getLyXText(bv)->GetFont(bv->buffer(), p, pos);
|
|
|
|
|
fn.decSize().decSize();
|
|
|
|
|
return fn;
|
2000-06-28 13:35:52 +00:00
|
|
|
|
}
|
2000-07-04 11:30:07 +00:00
|
|
|
|
#endif
|
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
|
|
|
|
|