]> git.lyx.org Git - lyx.git/blobdiff - src/insets/insetfloat.C
Make buffer's member variables private; use accessor functions.
[lyx.git] / src / insets / insetfloat.C
index 7e08132ef416488a7ec596051242dbd1e6440b19..4640c0578417fc48b5ae48b0cdcb0061c08fae58 100644 (file)
@@ -6,13 +6,12 @@
  * \author Jürgen Vigna
  * \author Lars Gullik Bjønnes
  *
- * Full author contact details are available in file CREDITS
+ * Full author contact details are available in file CREDITS.
  */
 
 #include <config.h>
 
 #include "insetfloat.h"
-#include "insettext.h"
 
 #include "buffer.h"
 #include "BufferView.h"
 #include "gettext.h"
 #include "iterators.h"
 #include "LaTeXFeatures.h"
-#include "Lsstream.h"
-#include "lyxfont.h"
 #include "lyxlex.h"
-#include "lyxtext.h"
-#include "Lsstream.h"
+#include "paragraph.h"
 
-#include "support/LOstream.h"
 #include "support/lstrings.h"
 #include "support/tostr.h"
 
-#include "frontends/LyXView.h"
-#include "frontends/Dialogs.h"
+#include "support/std_sstream.h"
+
+using namespace lyx::support;
 
-using std::ostream;
 using std::endl;
+using std::auto_ptr;
+using std::istringstream;
+using std::ostream;
+using std::ostringstream;
 
 
 // With this inset it will be possible to support the latex package
@@ -159,9 +158,8 @@ InsetFloat::~InsetFloat()
 
 dispatch_result InsetFloat::localDispatch(FuncRequest const & cmd)
 {
-       Inset::RESULT result = UNDISPATCHED;
-
        switch (cmd.action) {
+
        case LFUN_INSET_MODIFY: {
                InsetFloatParams params;
                InsetFloatMailer::string2params(cmd.argument, params);
@@ -169,23 +167,19 @@ dispatch_result InsetFloat::localDispatch(FuncRequest const & cmd)
                params_.placement = params.placement;
                params_.wide      = params.wide;
 
-               wide(params_.wide, cmd.view()->buffer()->params);
+               wide(params_.wide, cmd.view()->buffer()->params());
                cmd.view()->updateInset(this);
-               result = DISPATCHED;
+               return DISPATCHED;
        }
-       break;
 
        case LFUN_INSET_DIALOG_UPDATE: {
-               InsetFloatMailer mailer(*this);
-               mailer.updateDialog(cmd.view());
+               InsetFloatMailer(*this).updateDialog(cmd.view());
+               return DISPATCHED;
        }
-       break;
 
        default:
-               result = InsetCollapsable::localDispatch(cmd);
+               return InsetCollapsable::localDispatch(cmd);
        }
-
-       return result;
 }
 
 
@@ -194,14 +188,13 @@ void InsetFloatParams::write(ostream & os) const
        os << "Float " // getInsetName()
           << type << '\n';
 
-       if (!placement.empty()) {
+       if (!placement.empty())
                os << "placement " << placement << "\n";
-       }
-       if (wide) {
+
+       if (wide)
                os << "wide true\n";
-       } else {
+       else
                os << "wide false\n";
-       }
 }
 
 
@@ -233,17 +226,17 @@ void InsetFloatParams::read(LyXLex & lex)
 }
 
 
-void InsetFloat::write(Buffer const * buf, ostream & os) const
+void InsetFloat::write(Buffer const & buf, ostream & os) const
 {
        params_.write(os);
        InsetCollapsable::write(buf, os);
 }
 
 
-void InsetFloat::read(Buffer const * buf, LyXLex & lex)
+void InsetFloat::read(Buffer const & buf, LyXLex & lex)
 {
        params_.read(lex);
-       wide(params_.wide, buf->params);
+       wide(params_.wide, buf.params());
        InsetCollapsable::read(buf, lex);
 }
 
@@ -259,9 +252,9 @@ void InsetFloat::validate(LaTeXFeatures & features) const
 }
 
 
-Inset * InsetFloat::clone(Buffer const &) const
+auto_ptr<InsetBase> InsetFloat::clone() const
 {
-       return new InsetFloat(*this);
+       return auto_ptr<InsetBase>(new InsetFloat(*this));
 }
 
 
@@ -271,10 +264,10 @@ string const InsetFloat::editMessage() const
 }
 
 
-int InsetFloat::latex(Buffer const * buf, ostream & os,
+int InsetFloat::latex(Buffer const & buf, ostream & os,
                      LatexRunParams const & runparams) const
 {
-       FloatList const & floats = buf->params.getLyXTextClass().floats();
+       FloatList const & floats = buf.params().getLyXTextClass().floats();
        string const tmptype = (params_.wide ? params_.type + "*" : params_.type);
        // Figure out the float placement to use.
        // From lowest to highest:
@@ -282,7 +275,7 @@ int InsetFloat::latex(Buffer const * buf, ostream & os,
        // - document wide default placement
        // - specific float placement
        string placement;
-       string const buf_placement = buf->params.float_placement;
+       string const buf_placement = buf.params().float_placement;
        string const def_placement = floats.defaultPlacement(params_.type);
        if (!params_.placement.empty()
            && params_.placement != def_placement) {
@@ -313,7 +306,44 @@ int InsetFloat::latex(Buffer const * buf, ostream & os,
 }
 
 
-int InsetFloat::docbook(Buffer const * buf, ostream & os, bool mixcont) const
+int InsetFloat::linuxdoc(Buffer const & buf, ostream & os) const
+{
+       FloatList const & floats = buf.params().getLyXTextClass().floats();
+       string const tmptype =  params_.type;
+       // Figure out the float placement to use.
+       // From lowest to highest:
+       // - float default placement
+       // - document wide default placement
+       // - specific float placement
+       // This is the same as latex, as linuxdoc is modeled after latex.
+
+       string placement;
+       string const buf_placement = buf.params().float_placement;
+       string const def_placement = floats.defaultPlacement(params_.type);
+       if (!params_.placement.empty()
+           && params_.placement != def_placement) {
+               placement = params_.placement;
+       } else if (params_.placement.empty()
+                  && !buf_placement.empty()
+                  && buf_placement != def_placement) {
+               placement = buf_placement;
+       }
+
+       os << "\n<" << tmptype ;
+       // We only output placement if different from the def_placement.
+       if (!placement.empty()) {
+               os << " loc=\"" << placement << '"';
+       }
+       os << ">";
+
+       int const i = inset.linuxdoc(buf, os);
+       os << "</" << tmptype << ">\n";
+
+       return i;
+}
+
+
+int InsetFloat::docbook(Buffer const & buf, ostream & os, bool mixcont) const
 {
        os << '<' << params_.type << '>';
        int const i = inset.docbook(buf, os, mixcont);
@@ -323,13 +353,13 @@ int InsetFloat::docbook(Buffer const * buf, ostream & os, bool mixcont) const
 }
 
 
-bool InsetFloat::insetAllowed(Inset::Code code) const
+bool InsetFloat::insetAllowed(InsetOld::Code code) const
 {
-       if (code == Inset::FLOAT_CODE)
+       if (code == InsetOld::FLOAT_CODE)
                return false;
        if (inset.getLockingInset() != const_cast<InsetFloat *>(this))
                return inset.insetAllowed(code);
-       if ((code == Inset::FOOT_CODE) || (code == Inset::MARGIN_CODE))
+       if ((code == InsetOld::FOOT_CODE) || (code == InsetOld::MARGIN_CODE))
                return false;
        return true;
 }
@@ -350,7 +380,7 @@ void InsetFloat::wide(bool w, BufferParams const & bp)
 {
        params_.wide = w;
 
-       string lab(_("float:"));
+       string lab(_("float: "));
        lab += floatname(params_.type, bp);
 
        if (params_.wide)
@@ -360,7 +390,7 @@ void InsetFloat::wide(bool w, BufferParams const & bp)
 }
 
 
-void InsetFloat::addToToc(toc::TocList & toclist, Buffer const * buf) const
+void InsetFloat::addToToc(lyx::toc::TocList & toclist, Buffer const & buf) const
 {
        ParIterator pit(inset.paragraphs.begin(), inset.paragraphs);
        ParIterator end(inset.paragraphs.end(), inset.paragraphs);
@@ -368,11 +398,11 @@ void InsetFloat::addToToc(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);
+                       string const name = floatname(params_.type, buf.params());
                        string const str =
                                tostr(toclist[name].size() + 1)
                                + ". " + pit->asString(buf, false);
-                       toc::TocItem const item(pit->id(), 0 , str);
+                       lyx::toc::TocItem const item(pit->id(), 0 , str);
                        toclist[name].push_back(item);
                }
        }
@@ -386,7 +416,7 @@ InsetFloatMailer::InsetFloatMailer(InsetFloat & inset)
 {}
 
 
-string const InsetFloatMailer::inset2string() const
+string const InsetFloatMailer::inset2string(Buffer const &) const
 {
        return params2string(inset_.params());
 }