*
* LyX, The Document Processor
*
- * Copyright 1998 The LyX Team.
+ * Copyright 1998-2000 The LyX Team.
*
- *======================================================*/
+ * ====================================================== */
#include <config.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"
+#include "Floating.h"
using std::ostream;
using std::endl;
// \newfloat{algorithm}{htbp}{loa}[<sect>]
// \floatname{algorithm}{Algorithm}
//
+// 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.
+//
// Lgb
-InsetFloat::InsetFloat() : InsetCollapsable()
+InsetFloat::InsetFloat(string const & type)
+ : InsetCollapsable(), wide_(false)
{
- setLabel(_("float"));
+ string lab(_("float:"));
+ lab += type;
+ setLabel(lab);
LyXFont font(LyXFont::ALL_SANE);
font.decSize();
font.decSize();
font.setColor(LColor::footnote);
setLabelFont(font);
setAutoCollapse(false);
- setInsetName("Float");
- floatType = "table";
- floatPlacement = "H";
+ floatType_ = type;
+ setInsetName(type);
}
void InsetFloat::Write(Buffer const * buf, ostream & os) const
{
- os << getInsetName()
- << "\ntype " << floatType
- << "\nplacement " << floatPlacement << "\n";
+ os << "Float " // getInsetName()
+ << floatType_ << '\n';
+
+ if (floatPlacement_.empty()) {
+ os << "placement "
+ << floatList.getType(floatType_).placement() << "\n";
+ } else {
+ os << "placement " << floatPlacement_ << "\n";
+ }
+
InsetCollapsable::Write(buf, os);
}
{
if (lex.IsOK()) {
lex.next();
- string token = lex.GetString();
- if (token == "type") {
- lex.next();
- floatType = lex.GetString();
- }
- lex.next();
- token = lex.GetString();
+ string const token = lex.GetString();
if (token == "placement") {
lex.next();
- floatPlacement = lex.GetString();
+ floatPlacement_ = lex.GetString();
+ } else {
+ lyxerr << "InsetFloat::Read: Missing placement!"
+ << endl;
}
}
InsetCollapsable::Read(buf, lex);
void InsetFloat::Validate(LaTeXFeatures & features) const
{
- features.usedFloats.insert(floatType);
+ features.usedFloats.insert(floatType_);
}
-Inset * InsetFloat::Clone() const
+Inset * InsetFloat::Clone(Buffer const &) const
{
- InsetFloat * result = new InsetFloat;
- result->inset->init(inset);
+ InsetFloat * result = new InsetFloat(floatType_);
+ result->inset.init(&inset);
result->collapsed = collapsed;
return result;
}
-char const * InsetFloat::EditMessage() const
+string 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 << "\\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";
+ int const i = inset.Latex(buf, os, fragile, fp);
+ os << "\\end{" << floatType_ << "}%\n";
return i + 2;
}
+int InsetFloat::DocBook(Buffer const * buf, ostream & os) const
+{
+ os << "<" << floatType_ << ">";
+ int const i = inset.DocBook(buf, os);
+ os << "</" << floatType_ << ">";
+
+ return i;
+}
+
+
bool InsetFloat::InsertInsetAllowed(Inset * in) const
{
if ((in->LyxCode() == Inset::FOOT_CODE) ||
}
-#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
+ if (x >= top_x
&& x < button_length
&& y >= button_top_y
&& y < button_bottom_y
// This obviously need to change.
lyxerr << "InsetFloat: Let's edit this floats parameters!"
<< endl;
+ //bv->owner()->getDialogs()->showFloat(this);
} else {
InsetCollapsable::InsetButtonRelease(bv, x, y, button);
}
}
+
+string const & InsetFloat::type() const
+{
+ return floatType_;
+}
+
+
+void InsetFloat::placement(string const & p)
+{
+ // Here we should only allow the placement to be set
+ // if a valid value.
+#ifdef WITH_WARNINGS
+#warning FIX!
+#endif
+ floatPlacement_ = p;
+}
+
+
+string const & InsetFloat::placement() const
+{
+ return floatPlacement_;
+}
+
+
+void InsetFloat::wide(bool w)
+{
+ wide_ = w;
+ if (wide_) {
+ string lab(_("float:"));
+ lab += floatType_;
+ lab += "*";
+ setLabel(lab);
+ } else {
+ string lab(_("float:"));
+ lab += floatType_;
+ setLabel(lab);
+ }
+}
+
+
+bool InsetFloat::wide() const
+{
+ return wide_;
+}