]> git.lyx.org Git - lyx.git/blobdiff - src/insets/insetfloat.C
use more specific smart_ptr headers
[lyx.git] / src / insets / insetfloat.C
index 1d4c3614cb81a9fbc0dc6b67415468138b08ec09..c458a9560a70f0ea04ba05cd0012f1e1c122f9bb 100644 (file)
@@ -1,8 +1,8 @@
 /* This file is part of
  * ======================================================
- * 
+ *
  *           LyX, The Document Processor
- *      
+ *
  *          Copyright 1998-2001 The LyX Team.
  *
  * ====================================================== */
@@ -61,7 +61,7 @@ using std::endl;
 //     within    - This (optional) argument determines whether floats of this
 //                 class will be numbered within some sectional unit of the
 //                 document. For example, if within is equal to chapter, the
-//                 floats will be numbered within chapters. 
+//                 floats will be numbered within chapters.
 //   \floatstyle{style}
 //     style -  plain, boxed, ruled
 //   \floatname{float}{floatname}
@@ -99,11 +99,25 @@ using std::endl;
 //
 // Lgb
 
-InsetFloat::InsetFloat(string const & type)
-       : InsetCollapsable(), wide_(false)
+namespace {
+
+string floatname(string const & type)
 {
-       string lab(_("float:"));
-       lab += type;
+       FloatList::const_iterator it = floatList[type];
+       if (it == floatList.end())
+               return type;
+
+       return _(it->second.name());
+}
+
+} // namespace anon
+
+
+InsetFloat::InsetFloat(BufferParams const & bp, string const & type)
+       : InsetCollapsable(bp), wide_(false)
+{
+       string lab(_("float: "));
+       lab += floatname(type);
        setLabel(lab);
        LyXFont font(LyXFont::ALL_SANE);
        font.decSize();
@@ -143,7 +157,7 @@ void InsetFloat::write(Buffer const * buf, ostream & os) const
        } else {
                os << "wide false\n";
        }
-       
+
        InsetCollapsable::write(buf, os);
 }
 
@@ -185,9 +199,9 @@ void InsetFloat::read(Buffer const * buf, LyXLex & lex)
 void InsetFloat::validate(LaTeXFeatures & features) const
 {
        if (contains(placement(), "H")) {
-               features.require("floats");
+               features.require("float");
        }
-       
+
        features.useFloat(floatType_);
        InsetCollapsable::validate(features);
 }
@@ -224,19 +238,24 @@ int InsetFloat::latex(Buffer const * buf,
                   && buf_placement != def_placement) {
                placement = buf_placement;
        }
-       
-       os << "\\begin{" << tmptype << "}";
+
+       // The \n is used to force \begin{<floatname>} to appear in a new line.
+       // The % is needed to prevent two consecutive \n chars in the case
+       // when the current output line is empty.
+       os << "%\n\\begin{" << tmptype << "}";
        // We only output placement if different from the def_placement.
        if (!placement.empty()) {
                os << "[" << placement << "]";
        }
-       
-       os << "%\n";
-    
+       os << "\n";
+
        int const i = inset.latex(buf, os, fragile, fp);
-       os << "\\end{" << tmptype << "}%\n";
-       
-       return i + 2;
+
+       // The \n is used to force \end{<floatname>} to appear in a new line.
+       // In this case, we do not case if the current output line is empty.
+       os << "\n\\end{" << tmptype << "}\n";
+
+       return i + 4;
 }
 
 
@@ -265,13 +284,13 @@ bool InsetFloat::insetAllowed(Inset::Code code) const
 bool InsetFloat::showInsetDialog(BufferView * bv) const
 {
        if (!inset.showInsetDialog(bv)) {
-               bv->owner()->getDialogs()->showFloat(const_cast<InsetFloat *>(this)); 
+               bv->owner()->getDialogs()->showFloat(const_cast<InsetFloat *>(this));
        }
        return true;
 }
 
 
-string const & InsetFloat::type() const 
+string const & InsetFloat::type() const
 {
        return floatType_;
 }
@@ -294,16 +313,14 @@ string const & InsetFloat::placement() const
 void InsetFloat::wide(bool w)
 {
        wide_ = w;
-       if (wide_) {
-               string lab(_("float:"));
-               lab += floatType_;
+
+       string lab(_("float:"));
+       lab += floatname(floatType_);
+
+       if (wide_)
                lab += "*";
-               setLabel(lab);
-       } else {
-               string lab(_("float:"));
-               lab += floatType_;
-               setLabel(lab);
-       }
+
+       setLabel(lab);
 }