]> git.lyx.org Git - lyx.git/blobdiff - src/insets/insetfloat.C
The speed patch: redraw only rows that have changed
[lyx.git] / src / insets / insetfloat.C
index 9f2aa8d9fd0b198798f6bb30ef65f17c61389350..e2121a34024bffaf674cd8f6aa47d6dbddfbb012 100644 (file)
@@ -22,6 +22,7 @@
 #include "Floating.h"
 #include "FloatList.h"
 #include "funcrequest.h"
+#include "FuncStatus.h"
 #include "gettext.h"
 #include "LaTeXFeatures.h"
 #include "LColor.h"
@@ -31,8 +32,9 @@
 #include "pariterator.h"
 
 #include "support/lstrings.h"
-#include "support/tostr.h"
-#include "support/std_sstream.h"
+#include "support/convert.h"
+
+#include <sstream>
 
 using lyx::support::contains;
 
@@ -113,10 +115,6 @@ using std::ostringstream;
 
 namespace {
 
-// this should not be hardcoded, but be part of the definition
-// of the float (JMarc)
-string const caplayout("Caption");
-
 string floatname(string const & type, BufferParams const & bp)
 {
        FloatList const & floats = bp.getLyXTextClass().floats();
@@ -141,9 +139,6 @@ InsetFloat::InsetFloat(BufferParams const & bp, string const & type)
        setLabelFont(font);
        params_.type = type;
        setInsetName(type);
-       LyXTextClass const & tclass = bp.getLyXTextClass();
-       if (tclass.hasLayout(caplayout))
-               paragraphs().begin()->layout(tclass[caplayout]);
 }
 
 
@@ -153,7 +148,7 @@ InsetFloat::~InsetFloat()
 }
 
 
-void InsetFloat::priv_dispatch(LCursor & cur, FuncRequest & cmd)
+void InsetFloat::doDispatch(LCursor & cur, FuncRequest & cmd)
 {
        switch (cmd.action) {
 
@@ -163,9 +158,8 @@ void InsetFloat::priv_dispatch(LCursor & cur, FuncRequest & cmd)
                params_.placement = params.placement;
                params_.wide      = params.wide;
                params_.sideways  = params.sideways;
-               wide(params_.wide, cur.bv().buffer()->params());
-               sideways(params_.sideways, cur.bv().buffer()->params());
-               cur.bv().update();
+               wide(params_.wide, cur.buffer().params());
+               sideways(params_.sideways, cur.buffer().params());
                break;
        }
 
@@ -179,17 +173,33 @@ void InsetFloat::priv_dispatch(LCursor & cur, FuncRequest & cmd)
                        InsetFloatMailer(*this).showDialog(&cur.bv());
                        break;
                }
-               InsetCollapsable::priv_dispatch(cur, cmd);
+               InsetCollapsable::doDispatch(cur, cmd);
                break;
        }
 
        default:
-               InsetCollapsable::priv_dispatch(cur, cmd);
+               InsetCollapsable::doDispatch(cur, cmd);
                break;
        }
 }
 
 
+bool InsetFloat::getStatus(LCursor & cur, FuncRequest const & cmd,
+               FuncStatus & flag) const
+{
+       switch (cmd.action) {
+
+       case LFUN_INSET_MODIFY:
+       case LFUN_INSET_DIALOG_UPDATE:
+               flag.enabled(true);
+               return true;
+
+       default:
+               return InsetCollapsable::getStatus(cur, cmd, flag);
+       }
+}
+
+
 void InsetFloatParams::write(ostream & os) const
 {
        os << "Float " << type << '\n';
@@ -270,7 +280,7 @@ void InsetFloat::validate(LaTeXFeatures & features) const
 }
 
 
-auto_ptr<InsetBase> InsetFloat::clone() const
+auto_ptr<InsetBase> InsetFloat::doClone() const
 {
        return auto_ptr<InsetBase>(new InsetFloat(*this));
 }
@@ -380,11 +390,11 @@ int InsetFloat::docbook(Buffer const & buf, ostream & os,
 }
 
 
-bool InsetFloat::insetAllowed(InsetOld::Code code) const
+bool InsetFloat::insetAllowed(InsetBase::Code code) const
 {
-       return code != InsetOld::FLOAT_CODE
-           && code != InsetOld::FOOT_CODE
-           && code != InsetOld::MARGIN_CODE;
+       return code != InsetBase::FLOAT_CODE
+           && code != InsetBase::FOOT_CODE
+           && code != InsetBase::MARGIN_CODE;
 }
 
 
@@ -423,13 +433,13 @@ void InsetFloat::addToToc(lyx::toc::TocList & toclist, Buffer const & buf) const
 
        // Find a caption layout in one of the (child inset's) pars
        for (; pit != end; ++pit) {
-               if (pit->layout()->name() == caplayout) {
-                       string const name = floatname(params_.type, buf.params());
+               if (pit->layout()->labeltype == LABEL_SENSITIVE) {
+                       string const type = params_.type;
                        string const str =
-                               tostr(toclist[name].size() + 1)
+                               convert<string>(toclist[type].size() + 1)
                                + ". " + pit->asString(buf, false);
                        lyx::toc::TocItem const item(pit->id(), 0 , str);
-                       toclist[name].push_back(item);
+                       toclist[type].push_back(item);
                }
        }
 }