*
* \author Dekel Tsur
*
- * Full author contact details are available in file CREDITS
+ * Full author contact details are available in file CREDITS.
*/
#include <config.h>
-#ifdef __GNUG__
-#pragma implementation
-#endif
-
#include "insetwrap.h"
-#include "gettext.h"
-#include "lyxfont.h"
+
+#include "buffer.h"
+#include "bufferparams.h"
#include "BufferView.h"
-#include "lyxtext.h"
-#include "insets/insettext.h"
-#include "support/LOstream.h"
-#include "support/lstrings.h"
-#include "LaTeXFeatures.h"
+#include "cursor.h"
#include "debug.h"
-#include "buffer.h"
-#include "frontends/LyXView.h"
-#include "frontends/Dialogs.h"
-#include "lyxlex.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 "outputparams.h"
+#include "paragraph.h"
+#include "TocBackend.h"
-using std::ostream;
-using std::endl;
-
-namespace {
+#include "support/convert.h"
-// 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();
- FloatList::const_iterator it = floats[type];
- if (it == floats.end())
- return type;
- return _(it->second.name());
-}
+namespace lyx {
-} // namespace anon
+using std::string;
+using std::endl;
+using std::auto_ptr;
+using std::istringstream;
+using std::ostream;
+using std::ostringstream;
InsetWrap::InsetWrap(BufferParams const & bp, string const & type)
- : InsetCollapsable(bp), width_(50, LyXLength::PCW)
+ : InsetCollapsable(bp)
{
- string lab(_("wrap: "));
- lab += floatname(type, bp);
- setLabel(lab);
+ setLabel(_("wrap: ") + floatName(type, bp));
LyXFont font(LyXFont::ALL_SANE);
font.decSize();
font.decSize();
font.setColor(LColor::collapsable);
setLabelFont(font);
- Type_ = type;
- setInsetName(type);
- LyXTextClass const & tclass = bp.getLyXTextClass();
- if (tclass.hasLayout(caplayout))
- inset.paragraph()->layout(tclass[caplayout]);
+ params_.type = type;
+ params_.width = LyXLength(50, LyXLength::PCW);
+ setInsetName(from_utf8(type));
}
-InsetWrap::InsetWrap(InsetWrap const & in, bool same_id)
- : InsetCollapsable(in, same_id), Type_(in.Type_),
- Placement_(in.Placement_), width_(in.width_)
-{}
+InsetWrap::~InsetWrap()
+{
+ InsetWrapMailer(*this).hideDialog();
+}
-InsetWrap::~InsetWrap()
+void InsetWrap::doDispatch(LCursor & cur, FuncRequest & cmd)
{
- hideDialog();
+ switch (cmd.action) {
+ case LFUN_INSET_MODIFY: {
+ InsetWrapParams params;
+ InsetWrapMailer::string2params(to_utf8(cmd.argument()), params);
+ params_.placement = params.placement;
+ params_.width = params.width;
+ break;
+ }
+
+ case LFUN_INSET_DIALOG_UPDATE:
+ InsetWrapMailer(*this).updateDialog(&cur.bv());
+ break;
+
+ case LFUN_MOUSE_RELEASE: {
+ if (cmd.button() == mouse_button::button3 && hitButton(cmd)) {
+ InsetWrapMailer(*this).showDialog(&cur.bv());
+ break;
+ }
+ InsetCollapsable::doDispatch(cur, cmd);
+ break;
+ }
+
+ default:
+ InsetCollapsable::doDispatch(cur, cmd);
+ break;
+ }
}
-void InsetWrap::write(Buffer const * buf, ostream & os) const
+bool InsetWrap::getStatus(LCursor & cur, FuncRequest const & cmd,
+ FuncStatus & flag) const
{
- os << "Wrap " // getInsetName()
- << Type_ << '\n';
+ switch (cmd.action) {
+ case LFUN_INSET_MODIFY:
+ case LFUN_INSET_DIALOG_UPDATE:
+ flag.enabled(true);
+ return true;
- if (!Placement_.empty()) {
- os << "placement " << Placement_ << "\n";
+ default:
+ return InsetCollapsable::getStatus(cur, cmd, flag);
}
- os << "width \"" << width_.asString() << "\"\n";
+}
- InsetCollapsable::write(buf, os);
+
+void InsetWrapParams::write(ostream & os) const
+{
+ os << "Wrap " << type << '\n';
+
+ if (!placement.empty())
+ os << "placement " << placement << "\n";
+
+ os << "width \"" << width.asString() << "\"\n";
}
-void InsetWrap::read(Buffer const * buf, LyXLex & lex)
+void InsetWrapParams::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);
- }
+ string token;
+ lex >> token;
+ if (token == "placement")
+ lex >> placement;
+ else {
+ // take countermeasures
+ lex.pushToken(token);
}
- if (lex.isOK()) {
+ if (!lex)
+ return;
+ lex >> token;
+ if (token == "width") {
lex.next();
- string token = lex.getString();
- if (token == "width") {
- lex.next();
- width_ = LyXLength(lex.getString());
- } else {
- lyxerr << "InsetWrap::Read:: Missing 'width'-tag!"
- << endl;
- // take countermeasures
- lex.pushToken(token);
- }
+ width = LyXLength(lex.getString());
+ } else {
+ lyxerr << "InsetWrap::Read:: Missing 'width'-tag!"
+ << endl;
+ // take countermeasures
+ lex.pushToken(token);
}
+}
+
+
+void InsetWrap::write(Buffer const & buf, ostream & os) const
+{
+ params_.write(os);
+ InsetCollapsable::write(buf, os);
+}
+
+
+void InsetWrap::read(Buffer const & buf, LyXLex & lex)
+{
+ params_.read(lex);
InsetCollapsable::read(buf, lex);
}
}
-Inset * InsetWrap::clone(Buffer const &, bool same_id) const
+auto_ptr<InsetBase> InsetWrap::doClone() const
{
- return new InsetWrap(*const_cast<InsetWrap *>(this), same_id);
+ return auto_ptr<InsetBase>(new InsetWrap(*this));
}
-string const InsetWrap::editMessage() const
+docstring const InsetWrap::editMessage() const
{
return _("Opened Wrap Inset");
}
-int InsetWrap::latex(Buffer const * buf,
- ostream & os, bool fragile, bool fp) const
+int InsetWrap::latex(Buffer const & buf, odocstream & os,
+ OutputParams const & runparams) const
{
- os << "\\begin{floating" << Type_ << "}";
- if (!Placement_.empty()) {
- os << "[" << Placement_ << "]";
- }
- os << "{" << width_.asLatexString() << "}%\n";
-
- int const i = inset.latex(buf, os, fragile, fp);
-
- os << "\\end{floating" << Type_ << "}%\n";
+ os << "\\begin{floating" << from_ascii(params_.type) << '}';
+ if (!params_.placement.empty())
+ os << '[' << from_ascii(params_.placement) << ']';
+ os << '{' << from_ascii(params_.width.asLatexString()) << "}%\n";
+ int const i = InsetText::latex(buf, os, runparams);
+ os << "\\end{floating" << from_ascii(params_.type) << "}%\n";
return i + 2;
}
-int InsetWrap::docbook(Buffer const * buf, ostream & os, bool mixcont) const
+int InsetWrap::docbook(Buffer const & buf, odocstream & os,
+ OutputParams const & runparams) const
{
- os << "<" << Type_ << ">";
- int const i = inset.docbook(buf, os, mixcont);
- os << "</" << Type_ << ">";
-
+ // FIXME UNICODE
+ os << '<' << from_ascii(params_.type) << '>';
+ int const i = InsetText::docbook(buf, os, runparams);
+ os << "</" << from_ascii(params_.type) << '>';
return i;
}
-bool InsetWrap::insetAllowed(Inset::Code code) const
+bool InsetWrap::insetAllowed(InsetBase::Code code) const
{
switch(code) {
case FLOAT_CODE:
case FOOT_CODE:
case MARGIN_CODE:
- return false;
+ return false;
default:
return InsetCollapsable::insetAllowed(code);
}
}
-int InsetWrap::getMaxWidth(BufferView * bv, UpdatableInset const * inset)
- const
-{
- if (owner() &&
- static_cast<UpdatableInset*>(owner())->getMaxWidth(bv, inset) < 0) {
- return -1;
- }
- if (!width_.zero()) {
- int ww1 = latexTextWidth(bv);
- int ww2 = InsetCollapsable::getMaxWidth(bv, inset);
- if (ww2 > 0 && ww2 < ww1) {
- return ww2;
- }
- return ww1;
- }
- // this should not happen!
- return InsetCollapsable::getMaxWidth(bv, inset);
-}
-
-int InsetWrap::latexTextWidth(BufferView * bv) const
+bool InsetWrap::showInsetDialog(BufferView * bv) const
{
- return width_.inPixels(InsetCollapsable::latexTextWidth(bv),
- bv->text->defaultHeight());
+ if (!InsetText::showInsetDialog(bv))
+ InsetWrapMailer(const_cast<InsetWrap &>(*this)).showDialog(bv);
+ return true;
}
-string const & InsetWrap::type() const
+void InsetWrap::addToToc(TocList & toclist, Buffer const & buf) const
{
- return Type_;
+ 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<docstring>(toc.size() + 1)
+ + ". " + pit->asString(buf, false);
+ toc.push_back(TocItem(pit, 0, str));
+ }
+ }
}
-LyXLength const & InsetWrap::pageWidth() const
-{
- return width_;
-}
-
+string const InsetWrapMailer::name_("wrap");
-void InsetWrap::pageWidth(LyXLength const & ll)
-{
- if (ll != width_) {
- width_ = ll;
- need_update = FULL;
- }
-}
+InsetWrapMailer::InsetWrapMailer(InsetWrap & inset)
+ : inset_(inset)
+{}
-void InsetWrap::placement(string const & p)
+string const InsetWrapMailer::inset2string(Buffer const &) const
{
- Placement_ = p;
+ return params2string(inset_.params());
}
-string const & InsetWrap::placement() const
+void InsetWrapMailer::string2params(string const & in, InsetWrapParams & params)
{
- return Placement_;
+ params = InsetWrapParams();
+ if (in.empty())
+ return;
+
+ istringstream data(in);
+ LyXLex lex(0,0);
+ lex.setStream(data);
+
+ string name;
+ lex >> name;
+ if (!lex || name != name_)
+ return print_mailer_error("InsetWrapMailer", in, 1, name_);
+
+ // This is part of the inset proper that is usually swallowed
+ // by LyXText::readInset
+ string id;
+ lex >> id;
+ if (!lex || id != "Wrap")
+ return print_mailer_error("InsetBoxMailer", in, 2, "Wrap");
+
+ // We have to read the type here!
+ lex >> params.type;
+ params.read(lex);
}
-bool InsetWrap::showInsetDialog(BufferView * bv) const
+string const InsetWrapMailer::params2string(InsetWrapParams const & params)
{
- if (!inset.showInsetDialog(bv)) {
- bv->owner()->getDialogs().showWrap(const_cast<InsetWrap *>(this));
- }
- return true;
+ ostringstream data;
+ data << name_ << ' ';
+ params.write(data);
+ return data.str();
}
-void InsetWrap::addToToc(toc::TocList & toclist, Buffer const * buf) const
-{
- // Now find the caption in the float...
- // We now tranverse the paragraphs of
- // the inset...
- Paragraph * tmp = inset.paragraph();
- while (tmp) {
- if (tmp->layout()->name() == caplayout) {
- string const str =
- tostr(toclist[type()].size() + 1)
- + ". " + tmp->asString(buf, false);
- toc::TocItem const item(tmp, 0 , str);
- toclist[type()].push_back(item);
- }
- tmp = tmp->next();
- }
-}
+} // namespace lyx