#include "Floating.h"
#include "FloatList.h"
#include "funcrequest.h"
+#include "FuncStatus.h"
#include "gettext.h"
#include "LaTeXFeatures.h"
#include "LColor.h"
#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;
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();
setLabelFont(font);
params_.type = type;
setInsetName(type);
- LyXTextClass const & tclass = bp.getLyXTextClass();
- if (tclass.hasLayout(caplayout))
- paragraphs().begin()->layout(tclass[caplayout]);
}
}
-void InsetFloat::priv_dispatch(LCursor & cur, FuncRequest & cmd)
+void InsetFloat::doDispatch(LCursor & cur, FuncRequest & cmd)
{
switch (cmd.action) {
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;
}
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";
os << "wide true\n";
else
os << "wide false\n";
-
+
if (sideways)
os << "sideways true\n";
else
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);
}
}
if (contains(params_.placement, 'H')) {
features.require("float");
}
-
+
if (params_.sideways)
features.require("rotating");
}
-auto_ptr<InsetBase> InsetFloat::clone() const
+auto_ptr<InsetBase> InsetFloat::doClone() const
{
return auto_ptr<InsetBase>(new InsetFloat(*this));
}
}
-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;
}
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);
}
}
}
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);
}