X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Finsets%2FInsetFloat.cpp;h=e966bb5d6c7b9a0c1f2720cc7e163a1d19e2cdda;hb=2c357c1d23b7b83839a9beb8225d4f1ae4f793b4;hp=6d123615e7b8b5f4723c0f189d01b51605ecfd37;hpb=00e305c9d9bd8b0ff54b6c58adb6192d5934ed60;p=lyx.git diff --git a/src/insets/InsetFloat.cpp b/src/insets/InsetFloat.cpp index 6d123615e7..e966bb5d6c 100644 --- a/src/insets/InsetFloat.cpp +++ b/src/insets/InsetFloat.cpp @@ -16,36 +16,28 @@ #include "Buffer.h" #include "BufferParams.h" #include "BufferView.h" -#include "LCursor.h" -#include "debug.h" +#include "Counters.h" +#include "Cursor.h" #include "DispatchResult.h" #include "Floating.h" #include "FloatList.h" #include "FuncRequest.h" #include "FuncStatus.h" -#include "gettext.h" #include "LaTeXFeatures.h" -#include "LColor.h" -#include "LyXLex.h" +#include "Lexer.h" #include "OutputParams.h" -#include "Paragraph.h" -#include "TocBackend.h" +#include "TextClass.h" +#include "support/debug.h" +#include "support/gettext.h" #include "support/lstrings.h" +#include "support/docstream.h" #include "support/convert.h" +using namespace std; namespace lyx { -using support::contains; - -using std::endl; -using std::string; -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 // float.sty, and I am sure that with this and some additional support @@ -116,16 +108,10 @@ using std::ostringstream; InsetFloat::InsetFloat(BufferParams const & bp, string const & type) - : InsetCollapsable(bp) + : InsetCollapsable(bp), name_(from_utf8(type)) { setLabel(_("float: ") + floatName(type, bp)); - LyXFont font(LyXFont::ALL_SANE); - font.decSize(); - font.decSize(); - font.setColor(LColor::collapsable); - setLabelFont(font); params_.type = type; - setInsetName(from_utf8(type)); } @@ -135,7 +121,7 @@ InsetFloat::~InsetFloat() } -void InsetFloat::doDispatch(LCursor & cur, FuncRequest & cmd) +void InsetFloat::doDispatch(Cursor & cur, FuncRequest & cmd) { switch (cmd.action) { @@ -171,7 +157,7 @@ void InsetFloat::doDispatch(LCursor & cur, FuncRequest & cmd) } -bool InsetFloat::getStatus(LCursor & cur, FuncRequest const & cmd, +bool InsetFloat::getStatus(Cursor & cur, FuncRequest const & cmd, FuncStatus & flag) const { switch (cmd.action) { @@ -187,6 +173,21 @@ bool InsetFloat::getStatus(LCursor & cur, FuncRequest const & cmd, } +void InsetFloat::updateLabels(Buffer const & buf, ParIterator const & it) +{ + Counters & cnts = buf.params().getTextClass().counters(); + string const saveflt = cnts.current_float(); + + // Tell to captions what the current float is + cnts.current_float(params().type); + + InsetCollapsable::updateLabels(buf, it); + + //reset afterwards + cnts.current_float(saveflt); +} + + void InsetFloatParams::write(ostream & os) const { os << "Float " << type << '\n'; @@ -206,7 +207,7 @@ void InsetFloatParams::write(ostream & os) const } -void InsetFloatParams::read(LyXLex & lex) +void InsetFloatParams::read(Lexer & lex) { string token; lex >> token; @@ -244,7 +245,7 @@ void InsetFloat::write(Buffer const & buf, ostream & os) const } -void InsetFloat::read(Buffer const & buf, LyXLex & lex) +void InsetFloat::read(Buffer const & buf, Lexer & lex) { params_.read(lex); wide(params_.wide, buf.params()); @@ -255,21 +256,21 @@ void InsetFloat::read(Buffer const & buf, LyXLex & lex) void InsetFloat::validate(LaTeXFeatures & features) const { - if (contains(params_.placement, 'H')) { + if (support::contains(params_.placement, 'H')) { features.require("float"); } if (params_.sideways) - features.require("rotating"); + features.require("rotfloat"); features.useFloat(params_.type); InsetCollapsable::validate(features); } -auto_ptr InsetFloat::doClone() const +Inset * InsetFloat::clone() const { - return auto_ptr(new InsetFloat(*this)); + return new InsetFloat(*this); } @@ -280,16 +281,16 @@ docstring const InsetFloat::editMessage() const int InsetFloat::latex(Buffer const & buf, odocstream & os, - OutputParams const & runparams) const + OutputParams const & runparams) const { - FloatList const & floats = buf.params().getLyXTextClass().floats(); - string tmptype = (params_.wide ? params_.type + "*" : params_.type); - if (params_.sideways) { - if (params_.type == "table") - tmptype = "sidewaystable"; - else if (params_.type == "figure") - tmptype = "sidewaysfigure"; - } + FloatList const & floats = buf.params().getTextClass().floats(); + string tmptype = params_.type; + if (params_.sideways) + tmptype = "sideways" + params_.type; + if (params_.wide && (!params_.sideways || + params_.type == "figure" || + params_.type == "table")) + tmptype += "*"; // Figure out the float placement to use. // From lowest to highest: // - float default placement @@ -329,9 +330,9 @@ int InsetFloat::latex(Buffer const & buf, odocstream & os, int InsetFloat::plaintext(Buffer const & buf, odocstream & os, - OutputParams const & runparams) const + OutputParams const & runparams) const { - os << '[' << _("float") << ' ' << floatName(params_.type, buf.params()) << ":\n"; + os << '[' << buf.B_("float") << ' ' << floatName(params_.type, buf.params()) << ":\n"; InsetText::plaintext(buf, os, runparams); os << "\n]"; @@ -340,10 +341,10 @@ int InsetFloat::plaintext(Buffer const & buf, odocstream & os, int InsetFloat::docbook(Buffer const & buf, odocstream & os, - OutputParams const & runparams) const + OutputParams const & runparams) const { - // FIXME UNICODE - os << '<' << from_ascii(params_.type) << '>'; + // FIXME UNICODE + os << '<' << from_ascii(params_.type) << '>'; int const i = InsetText::docbook(buf, os, runparams); os << "'; @@ -351,11 +352,11 @@ int InsetFloat::docbook(Buffer const & buf, odocstream & os, } -bool InsetFloat::insetAllowed(InsetBase::Code code) const +bool InsetFloat::insetAllowed(InsetCode code) const { - return code != InsetBase::FLOAT_CODE - && code != InsetBase::FOOT_CODE - && code != InsetBase::MARGIN_CODE; + return code != FLOAT_CODE + && code != FOOT_CODE + && code != MARGIN_CODE; } @@ -387,31 +388,6 @@ void InsetFloat::sideways(bool s, BufferParams const & bp) } -void InsetFloat::addToToc(TocList & toclist, Buffer const & buf) const -{ - // Is there a need to provide a list of float insets? - return; - - // Abdel (01/02/2006): I'll let this code for reference in case - // there's a need to do something similar for another kind of - // inset. - 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()->labeltype == LABEL_SENSITIVE) { - Toc & toc = toclist[params_.type]; - docstring const str = - convert(toc.size() + 1) - + ". " + pit->asString(buf, false); - toc.push_back(TocItem(pit, 0, str)); - return; - } - } -} - - string const InsetFloatMailer::name_("float"); InsetFloatMailer::InsetFloatMailer(InsetFloat & inset) @@ -433,7 +409,7 @@ void InsetFloatMailer::string2params(string const & in, return; istringstream data(in); - LyXLex lex(0,0); + Lexer lex(0,0); lex.setStream(data); string name; @@ -442,7 +418,7 @@ void InsetFloatMailer::string2params(string const & in, return print_mailer_error("InsetFloatMailer", in, 1, name_); // This is part of the inset proper that is usually swallowed - // by LyXText::readInset + // by Text::readInset string id; lex >> id; if (!lex || id != "Float")