]> git.lyx.org Git - features.git/blobdiff - src/insets/insetfloat.C
read the Changelog
[features.git] / src / insets / insetfloat.C
index 8d8c8c6a2f795671be1ed086c10f040d1691e110..e0809a3b374a40530852d730b3d892ffebf17cff 100644 (file)
 #include "gettext.h"
 #include "lyxfont.h"
 #include "BufferView.h"
-#include "Painter.h"
 #include "lyxtext.h"
+#include "insets/insettext.h"
 #include "support/LOstream.h"
 #include "FloatList.h"
 #include "LaTeXFeatures.h"
 #include "debug.h"
+#include "Floating.h"
 
 using std::ostream;
 using std::endl;
@@ -77,26 +78,33 @@ using std::endl;
 //
 // Lgb
 
-InsetFloat::InsetFloat() : InsetCollapsable()
+InsetFloat::InsetFloat(string const & type)
+       : InsetCollapsable()
 {
-    setLabel(_("float"));
-    LyXFont font(LyXFont::ALL_SANE);
-    font.decSize();
-    font.decSize();
-    font.setColor(LColor::footnote);
-    setLabelFont(font);
-    setAutoCollapse(false);
-    setInsetName("Float");
-    floatType = "table";
-    floatPlacement = "H";
+       string lab(_("float:"));
+       lab += type;
+       setLabel(lab);
+       LyXFont font(LyXFont::ALL_SANE);
+       font.decSize();
+       font.decSize();
+       font.setColor(LColor::footnote);
+       setLabelFont(font);
+       setAutoCollapse(false);
+       setInsetName("Float");
+       floatType = type;
+       //floatPlacement = "H";
 }
 
 
 void InsetFloat::Write(Buffer const * buf, ostream & os) const
 {
        os << getInsetName()
-          << "\ntype " << floatType
-          << "\nplacement " << floatPlacement << "\n";
+          << " " << floatType
+          << "\nplacement ";
+       if (floatPlacement.empty())
+               os << floatList.getType(floatType).placement << "\n";
+       else
+               os << floatPlacement << "\n";
        InsetCollapsable::Write(buf, os);
 }
 
@@ -106,12 +114,6 @@ void InsetFloat::Read(Buffer const * buf, LyXLex & lex)
        if (lex.IsOK()) {
                lex.next();
                string token = lex.GetString();
-               if (token == "type") {
-                       lex.next();
-                       floatType = lex.GetString();
-               }
-               lex.next();
-               token = lex.GetString();
                if (token == "placement") {
                        lex.next();
                        floatPlacement = lex.GetString();
@@ -129,17 +131,17 @@ void InsetFloat::Validate(LaTeXFeatures & features) const
 
 Inset * InsetFloat::Clone() const
 {
-    InsetFloat * result = new InsetFloat;
-    result->init(this);
+       InsetFloat * result = new InsetFloat(floatType);
+       result->inset->init(inset);
 
-    result->collapsed = collapsed;
-    return result;
+       result->collapsed = collapsed;
+       return result;
 }
 
 
 char const * InsetFloat::EditMessage() const
 {
-    return _("Opened Float Inset");
+       return _("Opened Float Inset");
 }
 
 
@@ -152,38 +154,20 @@ int InsetFloat::Latex(Buffer const * buf,
                os << "[" << floatPlacement << "]";
        os << "%\n";
     
-    int i = InsetText::Latex(buf, os, fragile, fp);
-    os << "\\end{" << floatType << "}%\n";
-    
-    return i + 2;
-}
-
-
-bool InsetFloat::InsertInset(BufferView * bv, Inset * inset)
-{
-    if (!InsertInsetAllowed(inset))
-       return false;
-
-    return InsetText::InsertInset(bv, inset);
-}
-
-
-bool InsetFloat::InsertInsetAllowed(Inset * inset) const
-{
-    if ((inset->LyxCode() == Inset::FOOT_CODE) ||
-       (inset->LyxCode() == Inset::MARGIN_CODE)) {
-       return false;
-    }
-    return true;
+       int i = inset->Latex(buf, os, fragile, fp);
+       os << "\\end{" << floatType << "}%\n";
+       
+       return i + 2;
 }
 
 
-LyXFont InsetFloat::GetDrawFont(BufferView * bv,
-                               LyXParagraph * p, int pos) const
+bool InsetFloat::InsertInsetAllowed(Inset * in) const
 {
-    LyXFont fn = getLyXText(bv)->GetFont(bv->buffer(), p, pos);
-    fn.decSize().decSize();
-    return fn;
+       if ((in->LyxCode() == Inset::FOOT_CODE) ||
+           (in->LyxCode() == Inset::MARGIN_CODE)) {
+               return false;
+       }
+       return true;
 }
 
 
@@ -201,3 +185,25 @@ void InsetFloat::InsetButtonRelease(BufferView * bv, int x, int y, int button)
                InsetCollapsable::InsetButtonRelease(bv, x, y, button);
        }
 }
+
+
+void InsetFloat::wide(bool w)
+{
+       wide_ = w;
+       if (wide_) {
+               string lab(_("float:"));
+               lab += floatType;
+               lab += "*";
+               setLabel(lab);
+       } else {
+               string lab(_("float:"));
+               lab += floatType;
+               setLabel(lab);
+       }
+}
+
+
+bool InsetFloat::wide() const
+{
+       return wide_;
+}