lyx_mirror/src/insets/insetfloat.C
Jürgen Vigna eb7220abe6 Lots of changes for update of TextInsets, still some problems!
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@854 a592a061-630c-0410-9148-cb99ea01b6c8
2000-07-04 11:30:07 +00:00

205 lines
5.4 KiB
C

/* 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"
#include "insets/insettext.h"
#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¹. 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 -
// ¹ 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()
{
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";
}
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
{
InsetFloat * result = new InsetFloat;
result->inset->init(inset);
result->collapsed = collapsed;
return result;
}
char const * InsetFloat::EditMessage() const
{
return _("Opened Float Inset");
}
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";
int i = inset->Latex(buf, os, fragile, fp);
os << "\\end{" << floatType << "}%\n";
return i + 2;
}
bool InsetFloat::InsertInset(BufferView * bv, Inset * in)
{
if (!InsertInsetAllowed(in))
return false;
return inset->InsertInset(bv, in);
}
bool InsetFloat::InsertInsetAllowed(Inset * in) const
{
if ((in->LyxCode() == Inset::FOOT_CODE) ||
(in->LyxCode() == Inset::MARGIN_CODE)) {
return false;
}
return true;
}
#if 0
LyXFont InsetFloat::GetDrawFont(BufferView * bv,
LyXParagraph * p, int pos) const
{
LyXFont fn = getLyXText(bv)->GetFont(bv->buffer(), p, pos);
fn.decSize().decSize();
return fn;
}
#endif
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);
}
}