1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 1998-2000 The LyX Team.
8 * ====================================================== */
13 #pragma implementation
16 #include "insetfloat.h"
19 #include "BufferView.h"
21 #include "insets/insettext.h"
22 #include "support/LOstream.h"
23 #include "FloatList.h"
24 #include "LaTeXFeatures.h"
31 // With this inset it will be possible to support the latex package
32 // float.sty, and I am sure that with this and some additional support
33 // classes we can support similar functionality in other formats
35 // By using float.sty we will have the same handling for all floats, both
36 // for those already in existance (table and figure) and all user created
37 // ones¹. So suddenly we give the users the possibility of creating new
38 // kinds of floats on the fly. (and with a uniform look)
41 // \newfloat{type}{placement}{ext}[within]
42 // type - The "type" of the new class of floats, like program or
43 // algorithm. After the appropriate \newfloat, commands
44 // such as \begin{program} or \end{algorithm*} will be
46 // placement - The default placement for the given class of floats.
47 // They are like in standard LaTeX: t, b, p and h for top,
48 // bottom, page, and here, respectively. On top of that
49 // there is a new type, H, which does not really correspond
50 // to a float, since it means: put it "here" and nowhere else.
51 // Note, however that the H specifier is special and, because
52 // of implementation details cannot be used in the second
53 // argument of \newfloat.
54 // ext - The file name extension of an auxiliary file for the list
55 // of figures (or whatever). LaTeX writes the captions to
57 // within - This (optional) argument determines whether floats of this
58 // class will be numbered within some sectional unit of the
59 // document. For example, if within is equal to chapter, the
60 // floats will be numbered within chapters.
62 // style - plain, boxed, ruled
63 // \floatname{float}{floatname}
66 // \floatplacement{float}{placement}
69 // \restylefloat{float}
71 // \listof{type}{title}
74 // ¹ the algorithm float is defined using the float.sty package. Like this
76 // \newfloat{algorithm}{htbp}{loa}[<sect>]
77 // \floatname{algorithm}{Algorithm}
79 // The intention is that floats should be definable from two places:
81 // - the "gui" (i.e. by the user)
84 // This should only be done for floats defined in a documentclass and that
85 // does not need any additional packages. The two most known floats in this
86 // category is "table" and "figure". Floats defined in layout files are only
87 // stored in lyx files if the user modifies them.
90 // There should be a gui dialog (and also a collection of lyxfuncs) where
91 // the user can modify existing floats and/or create new ones.
93 // The individual floats will also have some settable
94 // variables: wide and placement.
98 InsetFloat::InsetFloat(string const & type)
99 : InsetCollapsable(), wide_(false)
101 string lab(_("float:"));
104 LyXFont font(LyXFont::ALL_SANE);
107 font.setColor(LColor::footnote);
109 setAutoCollapse(false);
115 void InsetFloat::Write(Buffer const * buf, ostream & os) const
117 os << "Float " // getInsetName()
118 << floatType_ << '\n';
120 if (floatPlacement_.empty()) {
122 << floatList.getType(floatType_).placement() << "\n";
124 os << "placement " << floatPlacement_ << "\n";
127 InsetCollapsable::Write(buf, os);
131 void InsetFloat::Read(Buffer const * buf, LyXLex & lex)
135 string const token = lex.GetString();
136 if (token == "placement") {
138 floatPlacement_ = lex.GetString();
140 lyxerr << "InsetFloat::Read: Missing placement!"
144 InsetCollapsable::Read(buf, lex);
148 void InsetFloat::Validate(LaTeXFeatures & features) const
150 features.usedFloats.insert(floatType_);
154 Inset * InsetFloat::Clone(Buffer const &) const
156 InsetFloat * result = new InsetFloat(floatType_);
157 result->inset.init(&inset);
159 result->collapsed = collapsed;
164 string const InsetFloat::EditMessage() const
166 return _("Opened Float Inset");
170 int InsetFloat::Latex(Buffer const * buf,
171 ostream & os, bool fragile, bool fp) const
173 os << "\\begin{" << floatType_ << "}";
174 if (!floatPlacement_.empty()
175 && floatPlacement_ != floatList.defaultPlacement(floatType_))
176 os << "[" << floatPlacement_ << "]";
179 int const i = inset.Latex(buf, os, fragile, fp);
180 os << "\\end{" << floatType_ << "}%\n";
186 int InsetFloat::DocBook(Buffer const * buf, ostream & os) const
188 os << "<" << floatType_ << ">";
189 int const i = inset.DocBook(buf, os);
190 os << "</" << floatType_ << ">";
196 bool InsetFloat::InsertInsetAllowed(Inset * in) const
198 if ((in->LyxCode() == Inset::FOOT_CODE) ||
199 (in->LyxCode() == Inset::MARGIN_CODE)) {
206 void InsetFloat::InsetButtonRelease(BufferView * bv, int x, int y, int button)
211 && y < button_bottom_y
213 // This obviously need to change.
214 lyxerr << "InsetFloat: Let's edit this floats parameters!"
217 InsetCollapsable::InsetButtonRelease(bv, x, y, button);
222 string const & InsetFloat::type() const
228 void InsetFloat::placement(string const & p)
230 // Here we should only allow the placement to be set
237 string const & InsetFloat::placement() const
239 return floatPlacement_;
243 void InsetFloat::wide(bool w)
247 string lab(_("float:"));
252 string lab(_("float:"));
259 bool InsetFloat::wide() const