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"
22 #include "support/LOstream.h"
23 #include "FloatList.h"
24 #include "LaTeXFeatures.h"
30 // With this inset it will be possible to support the latex package
31 // float.sty, and I am sure that with this and some additional support
32 // classes we can support similar functionality in other formats
34 // By using float.sty we will have the same handling for all floats, both
35 // for those already in existance (table and figure) and all user created
36 // ones¹. So suddenly we give the users the possibility of creating new
37 // kinds of floats on the fly. (and with a uniform look)
40 // \newfloat{type}{placement}{ext}[within]
41 // type - The "type" of the new class of floats, like program or
42 // algorithm. After the appropriate \newfloat, commands
43 // such as \begin{program} or \end{algorithm*} will be
45 // placement - The default placement for the given class of floats.
46 // They are like in standard LaTeX: t, b, p and h for top,
47 // bottom, page, and here, respectively. On top of that
48 // there is a new type, H, which does not really correspond
49 // to a float, since it means: put it "here" and nowhere else.
50 // Note, however that the H specifier is special and, because
51 // of implementation details cannot be used in the second
52 // argument of \newfloat.
53 // ext - The file name extension of an auxiliary file for the list
54 // of figures (or whatever). LaTeX writes the captions to
56 // within - This (optional) argument determines whether floats of this
57 // class will be numbered within some sectional unit of the
58 // document. For example, if within is equal to chapter, the
59 // floats will be numbered within chapters.
61 // style - plain, boxed, ruled
62 // \floatname{float}{floatname}
65 // \floatplacement{float}{placement}
68 // \restylefloat{float}
70 // \listof{type}{title}
73 // ¹ the algorithm float is defined using the float.sty package. Like this
75 // \newfloat{algorithm}{htbp}{loa}[<sect>]
76 // \floatname{algorithm}{Algorithm}
80 InsetFloat::InsetFloat() : InsetCollapsable()
83 LyXFont font(LyXFont::ALL_SANE);
86 font.setColor(LColor::footnote);
88 setAutoCollapse(false);
89 setInsetName("Float");
95 void InsetFloat::Write(Buffer const * buf, ostream & os) const
98 << "\ntype " << floatType
99 << "\nplacement " << floatPlacement << "\n";
100 InsetCollapsable::Write(buf, os);
104 void InsetFloat::Read(Buffer const * buf, LyXLex & lex)
108 string token = lex.GetString();
109 if (token == "type") {
111 floatType = lex.GetString();
114 token = lex.GetString();
115 if (token == "placement") {
117 floatPlacement = lex.GetString();
120 InsetCollapsable::Read(buf, lex);
124 void InsetFloat::Validate(LaTeXFeatures & features) const
126 features.usedFloats.insert(floatType);
130 Inset * InsetFloat::Clone() const
132 InsetFloat * result = new InsetFloat;
135 result->collapsed = collapsed;
140 char const * InsetFloat::EditMessage() const
142 return _("Opened Float Inset");
146 int InsetFloat::Latex(Buffer const * buf,
147 ostream & os, bool fragile, bool fp) const
149 os << "\\begin{" << floatType << "}";
150 if (!floatPlacement.empty()
151 && floatPlacement != floatList.defaultPlacement(floatType))
152 os << "[" << floatPlacement << "]";
155 int i = InsetText::Latex(buf, os, fragile, fp);
156 os << "\\end{" << floatType << "}%\n";
162 bool InsetFloat::InsertInset(BufferView * bv, Inset * inset)
164 if (!InsertInsetAllowed(inset))
167 return InsetText::InsertInset(bv, inset);
171 bool InsetFloat::InsertInsetAllowed(Inset * inset) const
173 if ((inset->LyxCode() == Inset::FOOT_CODE) ||
174 (inset->LyxCode() == Inset::MARGIN_CODE)) {
181 LyXFont InsetFloat::GetDrawFont(BufferView * bv,
182 LyXParagraph * p, int pos) const
184 LyXFont fn = getLyXText(bv)->GetFont(bv->buffer(), p, pos);
185 fn.decSize().decSize();
190 void InsetFloat::InsetButtonRelease(BufferView * bv, int x, int y, int button)
195 && y < button_bottom_y
197 // This obviously need to change.
198 lyxerr << "InsetFloat: Let's edit this floats parameters!"
201 InsetCollapsable::InsetButtonRelease(bv, x, y, button);