]> 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 4f59cbc4c650287e3599d5e86453d0e63a203137..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;
        }
 
@@ -174,17 +168,41 @@ void InsetFloat::priv_dispatch(LCursor & cur, FuncRequest & cmd)
                break;
        }
 
+       case LFUN_MOUSE_RELEASE: {
+               if (cmd.button() == mouse_button::button3 && hitButton(cmd)) {
+                       InsetFloatMailer(*this).showDialog(&cur.bv());
+                       break;
+               }
+               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 " // getInsetName()
-          << type << '\n';
+       os << "Float " << type << '\n';
 
        if (!placement.empty())
                os << "placement " << placement << "\n";
@@ -193,7 +211,7 @@ void InsetFloatParams::write(ostream & os) const
                os << "wide true\n";
        else
                os << "wide false\n";
-               
+
        if (sideways)
                os << "sideways true\n";
        else
@@ -203,40 +221,31 @@ void InsetFloatParams::write(ostream & os) const
 
 void InsetFloatParams::read(LyXLex & lex)
 {
-       if (lex.isOK()) {
-               lex.next();
-               string token = lex.getString();
-               if (token == "placement") {
-                       lex.next();
-                       placement = lex.getString();
-               } else {
-                       // take countermeasures
-                       lex.pushToken(token);
-               }
-               lex.next();
-               token = lex.getString();
-               if (token == "wide") {
-                       lex.next();
-                       string const tmptoken = lex.getString();
-                       wide = (tmptoken == "true");
-               } else {
-                       lyxerr << "InsetFloat::Read:: Missing wide!"
-                              << endl;
-                       // take countermeasures
-                       lex.pushToken(token);
-               }
-               lex.next();
-               token = lex.getString();
-               if (token == "sideways") {
-                       lex.next();
-                       string const tmptoken = lex.getString();
-                       sideways = (tmptoken == "true");
-               } else {
-                       lyxerr << "InsetFloat::Read:: Missing sideways!"
-                              << endl;
-                       // take countermeasures
-                       lex.pushToken(token);
-               }
+       string token;
+       lex >> token;
+       if (token == "placement") {
+               lex >> placement;
+       } else {
+               // take countermeasures
+               lex.pushToken(token);
+       }
+       lex >> token;
+       if (token == "wide") {
+               lex >> wide;
+       } else {
+               lyxerr << "InsetFloat::Read:: Missing wide!"
+               << endl;
+               // take countermeasures
+               lex.pushToken(token);
+       }
+       lex >> token;
+       if (token == "sideways") {
+               lex >> sideways;
+       } else {
+               lyxerr << "InsetFloat::Read:: Missing sideways!"
+               << endl;
+               // take countermeasures
+               lex.pushToken(token);
        }
 }
 
@@ -262,7 +271,7 @@ void InsetFloat::validate(LaTeXFeatures & features) const
        if (contains(params_.placement, 'H')) {
                features.require("float");
        }
-       
+
        if (params_.sideways)
                features.require("rotating");
 
@@ -271,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));
 }
@@ -381,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;
 }
 
 
@@ -419,18 +428,18 @@ void InsetFloat::sideways(bool s, BufferParams const & bp)
 
 void InsetFloat::addToToc(lyx::toc::TocList & toclist, Buffer const & buf) const
 {
-       ParConstIterator pit(*this, 0);
-       ParConstIterator end = ParConstIterator(DocumentIterator());
+       ParConstIterator pit = par_const_iterator_begin(*this);
+       ParConstIterator end = par_const_iterator_end(*this);
 
        // 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);
                }
        }
 }
@@ -472,6 +481,8 @@ void InsetFloatMailer::string2params(string const & in,
        if (!lex || id != "Float")
                return print_mailer_error("InsetBoxMailer", in, 2, "Float");
 
+       // We have to read the type here!
+       lex >> params.type;
        params.read(lex);
 }