]> git.lyx.org Git - lyx.git/blobdiff - src/insets/InsetFloat.cpp
This optional argument to the InsetCollapsable constructor
[lyx.git] / src / insets / InsetFloat.cpp
index d201a29194fb240f947202cbe722b37b5cf2cdad..0a537598697556e6d393cdc038aed8aaafefb1e0 100644 (file)
@@ -34,9 +34,9 @@
 
 #include "support/convert.h"
 #include "support/debug.h"
+#include "support/docstream.h"
 #include "support/gettext.h"
 #include "support/lstrings.h"
-#include "support/docstream.h"
 
 #include "frontends/Application.h"
 
@@ -127,6 +127,16 @@ InsetFloat::~InsetFloat()
 }
 
 
+docstring InsetFloat::toolTip(BufferView const & bv, int x, int y) const
+{
+       if (InsetCollapsable::toolTip(bv, x, y).empty() || isOpen())
+               return docstring();
+
+       OutputParams rp(&buffer().params().encoding());
+       return getCaptionText(rp);
+}
+
+
 void InsetFloat::doDispatch(Cursor & cur, FuncRequest & cmd)
 {
        switch (cmd.action) {
@@ -134,12 +144,17 @@ void InsetFloat::doDispatch(Cursor & cur, FuncRequest & cmd)
        case LFUN_INSET_MODIFY: {
                InsetFloatParams params;
                string2params(to_utf8(cmd.argument()), params);
-               params_.placement = params.placement;
-               params_.wide      = params.wide;
-               params_.sideways  = params.sideways;
-               params_.subfloat  = params.subfloat;
-               setWide(params_.wide, cur.buffer().params());
-               setSideways(params_.sideways, cur.buffer().params());
+
+               // placement, wide and sideways are not used for subfloats
+               if (!params_.subfloat) {
+                       params_.placement = params.placement;
+                       params_.wide      = params.wide;
+                       params_.sideways  = params.sideways;
+                       setWide(params_.wide, cur.buffer().params(), false);
+                       setSideways(params_.sideways, cur.buffer().params(), false);
+               }
+
+               setNewLabel(cur.buffer().params());
                break;
        }
 
@@ -162,7 +177,7 @@ bool InsetFloat::getStatus(Cursor & cur, FuncRequest const & cmd,
 
        case LFUN_INSET_MODIFY:
        case LFUN_INSET_DIALOG_UPDATE:
-               flag.enabled(true);
+               flag.setEnabled(true);
                return true;
 
        default:
@@ -173,11 +188,12 @@ bool InsetFloat::getStatus(Cursor & cur, FuncRequest const & cmd,
 
 void InsetFloat::updateLabels(ParIterator const & it)
 {
-       Counters & cnts = buffer().params().documentClass().counters();
+       Counters & cnts = buffer().masterBuffer()->params().documentClass().counters();
        string const saveflt = cnts.current_float();
        bool const savesubflt = cnts.isSubfloat();
 
-       bool const subflt = it.innerInsetOfType(FLOAT_CODE);
+       bool const subflt = (it.innerInsetOfType(FLOAT_CODE)
+                            || it.innerInsetOfType(WRAP_CODE));
        // floats can only embed subfloats of their own kind
        if (subflt)
                params_.type = saveflt;
@@ -216,32 +232,11 @@ void InsetFloatParams::write(ostream & os) const
 
 void InsetFloatParams::read(Lexer & lex)
 {
-       string token;
-       lex >> token;
-       if (token == "placement") {
+       lex.setContext("InsetFloatParams::read");
+       if (lex.checkFor("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);
-       }
+       lex >> "wide" >> wide;
+       lex >> "sideways" >> sideways;
 }
 
 
@@ -389,32 +384,45 @@ bool InsetFloat::showInsetDialog(BufferView * bv) const
 }
 
 
-void InsetFloat::setWide(bool w, BufferParams const & bp)
+void InsetFloat::setWide(bool w, BufferParams const & bp, bool update_label)
 {
        params_.wide = w;
-       docstring lab = _("float: ") + floatName(params_.type, bp);
-       if (params_.wide)
-               lab += '*';
-       setLabel(lab);
+       if (update_label)
+               setNewLabel(bp);
 }
 
 
-void InsetFloat::setSideways(bool s, BufferParams const & bp)
+void InsetFloat::setSideways(bool s, BufferParams const & bp, bool update_label)
 {
        params_.sideways = s;
-       docstring lab = _("float: ") + floatName(params_.type, bp);
-       if (params_.sideways)
-               lab += _(" (sideways)");
-       setLabel(lab);
+       if (update_label)
+               setNewLabel(bp);
 }
 
 
-void InsetFloat::setSubfloat(bool s, BufferParams const & bp)
+void InsetFloat::setSubfloat(bool s, BufferParams const & bp, bool update_label)
 {
        params_.subfloat = s;
-       docstring lab = _("float: ") + floatName(params_.type, bp);
-       if (s)
-               lab = _("subfloat: ") + floatName(params_.type, bp);
+       if (update_label)
+               setNewLabel(bp);
+}
+
+
+void InsetFloat::setNewLabel(BufferParams const & bp)
+{
+       docstring lab = _("float: ");
+
+       if( params_.subfloat )
+               lab = _("subfloat: ");
+
+       lab += floatName(params_.type, bp);
+
+       if (params_.wide)
+               lab += '*';
+
+       if (params_.sideways)
+               lab += _(" (sideways)");
+
        setLabel(lab);
 }
 
@@ -445,6 +453,29 @@ docstring InsetFloat::getCaption(OutputParams const & runparams) const
 }
 
 
+docstring InsetFloat::getCaptionText(OutputParams const & runparams) const
+{
+       if (paragraphs().empty())
+               return docstring();
+
+       ParagraphList::const_iterator pit = paragraphs().begin();
+       for (; pit != paragraphs().end(); ++pit) {
+               InsetList::const_iterator it = pit->insetList().begin();
+               for (; it != pit->insetList().end(); ++it) {
+                       Inset & inset = *it->inset;
+                       if (inset.lyxCode() == CAPTION_CODE) {
+                               odocstringstream ods;
+                               InsetCaption * ins =
+                                       static_cast<InsetCaption *>(it->inset);
+                               ins->getCaptionText(ods, runparams);
+                               return ods.str();
+                       }
+               }
+       }
+       return docstring();
+}
+
+
 void InsetFloat::string2params(string const & in, InsetFloatParams & params)
 {
        params = InsetFloatParams();
@@ -452,27 +483,11 @@ void InsetFloat::string2params(string const & in, InsetFloatParams & params)
                return;
 
        istringstream data(in);
-       Lexer lex(0,0);
+       Lexer lex;
        lex.setStream(data);
-
-       string name;
-       lex >> name;
-       if (!lex || name != "float") {
-               LYXERR0("InsetFloat::string2params(" << in << ")\n"
-                                         "Expected arg 1 to be \"float\"\n");
-       }
-
-       // This is part of the inset proper that is usually swallowed
-       // by Text::readInset
-       string id;
-       lex >> id;
-       if (!lex || id != "Float") {
-               LYXERR0("InsetFloat::string2params(" << in << ")\n"
-                                         "Expected arg 1 to be \"Float\"\n");
-       }
-
-       // We have to read the type here!
-       lex >> params.type;
+       lex.setContext("InsetFloat::string2params");
+       lex >> "float" >> "Float";
+       lex >> params.type; // We have to read the type here!
        params.read(lex);
 }