1 /* This file is part of
2 * ======================================================
4 * LyX, The Document Processor
6 * Copyright 1998 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}
81 InsetFloat::InsetFloat(string const & type)
84 string lab(_("float:"));
87 LyXFont font(LyXFont::ALL_SANE);
90 font.setColor(LColor::footnote);
92 setAutoCollapse(false);
95 //floatPlacement = "H";
99 void InsetFloat::Write(Buffer const * buf, ostream & os) const
101 os << "Float " // getInsetName()
102 << floatType << '\n';
104 if (floatPlacement.empty()) {
106 << floatList.getType(floatType).placement << "\n";
108 os << "placement " << floatPlacement << "\n";
111 InsetCollapsable::Write(buf, os);
115 void InsetFloat::Read(Buffer const * buf, LyXLex & lex)
119 string token = lex.GetString();
120 if (token == "placement") {
122 floatPlacement = lex.GetString();
124 lyxerr << "InsetFloat::Read: Missing placement!"
128 InsetCollapsable::Read(buf, lex);
132 void InsetFloat::Validate(LaTeXFeatures & features) const
134 features.usedFloats.insert(floatType);
138 Inset * InsetFloat::Clone() const
140 InsetFloat * result = new InsetFloat(floatType);
141 result->inset->init(inset);
143 result->collapsed = collapsed;
148 string const InsetFloat::EditMessage() const
150 return _("Opened Float Inset");
154 int InsetFloat::Latex(Buffer const * buf,
155 ostream & os, bool fragile, bool fp) const
157 os << "\\begin{" << floatType << "}";
158 if (!floatPlacement.empty()
159 && floatPlacement != floatList.defaultPlacement(floatType))
160 os << "[" << floatPlacement << "]";
163 int i = inset->Latex(buf, os, fragile, fp);
164 os << "\\end{" << floatType << "}%\n";
170 bool InsetFloat::InsertInsetAllowed(Inset * in) const
172 if ((in->LyxCode() == Inset::FOOT_CODE) ||
173 (in->LyxCode() == Inset::MARGIN_CODE)) {
180 void InsetFloat::InsetButtonRelease(BufferView * bv, int x, int y, int button)
185 && y < button_bottom_y
187 // This obviously need to change.
188 lyxerr << "InsetFloat: Let's edit this floats parameters!"
191 InsetCollapsable::InsetButtonRelease(bv, x, y, button);
196 string const & InsetFloat::type() const
202 void InsetFloat::wide(bool w)
206 string lab(_("float:"));
211 string lab(_("float:"));
218 bool InsetFloat::wide() const