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 "insets/insettext.h"
23 #include "support/LOstream.h"
24 #include "FloatList.h"
25 #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() : InsetCollapsable()
84 LyXFont font(LyXFont::ALL_SANE);
87 font.setColor(LColor::footnote);
89 setAutoCollapse(false);
90 setInsetName("Float");
96 void InsetFloat::Write(Buffer const * buf, ostream & os) const
99 << "\ntype " << floatType
100 << "\nplacement " << floatPlacement << "\n";
101 InsetCollapsable::Write(buf, os);
105 void InsetFloat::Read(Buffer const * buf, LyXLex & lex)
109 string token = lex.GetString();
110 if (token == "type") {
112 floatType = lex.GetString();
115 token = lex.GetString();
116 if (token == "placement") {
118 floatPlacement = lex.GetString();
121 InsetCollapsable::Read(buf, lex);
125 void InsetFloat::Validate(LaTeXFeatures & features) const
127 features.usedFloats.insert(floatType);
131 Inset * InsetFloat::Clone() const
133 InsetFloat * result = new InsetFloat;
134 result->inset->init(inset);
136 result->collapsed = collapsed;
141 char const * InsetFloat::EditMessage() const
143 return _("Opened Float Inset");
147 int InsetFloat::Latex(Buffer const * buf,
148 ostream & os, bool fragile, bool fp) const
150 os << "\\begin{" << floatType << "}";
151 if (!floatPlacement.empty()
152 && floatPlacement != floatList.defaultPlacement(floatType))
153 os << "[" << floatPlacement << "]";
156 int i = inset->Latex(buf, os, fragile, fp);
157 os << "\\end{" << floatType << "}%\n";
163 bool InsetFloat::InsertInset(BufferView * bv, Inset * in)
165 if (!InsertInsetAllowed(in))
168 return inset->InsertInset(bv, in);
172 bool InsetFloat::InsertInsetAllowed(Inset * in) const
174 if ((in->LyxCode() == Inset::FOOT_CODE) ||
175 (in->LyxCode() == Inset::MARGIN_CODE)) {
182 LyXFont InsetFloat::GetDrawFont(BufferView * bv,
183 LyXParagraph * p, int pos) const
185 LyXFont fn = getLyXText(bv)->GetFont(bv->buffer(), p, pos);
186 fn.decSize().decSize();
191 void InsetFloat::InsetButtonRelease(BufferView * bv, int x, int y, int button)
196 && y < button_bottom_y
198 // This obviously need to change.
199 lyxerr << "InsetFloat: Let's edit this floats parameters!"
202 InsetCollapsable::InsetButtonRelease(bv, x, y, button);