X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Finsets%2Finsetcommand.C;h=6d5248844b923d5650941ffb563ea74feb0313ae;hb=e28331ed63062dea10d0a21b9ec12034b4b17b9a;hp=ff815add1f2b39e8a2fa6849190332b0cdc559c5;hpb=71b4a6798be7a056aceca295a28c99ea98ee31fd;p=lyx.git diff --git a/src/insets/insetcommand.C b/src/insets/insetcommand.C index ff815add1f..6d5248844b 100644 --- a/src/insets/insetcommand.C +++ b/src/insets/insetcommand.C @@ -23,6 +23,8 @@ #include +namespace lyx { + using std::string; using std::istringstream; using std::ostream; @@ -31,8 +33,9 @@ using std::ostringstream; InsetCommand::InsetCommand(InsetCommandParams const & p, string const & mailer_name) - : p_(p.getCmdName(), p.getContents(), p.getOptions(), p.getSecOptions()), + : p_(p), mailer_name_(mailer_name), + mouse_hover_(false), updateButtonLabel_(true) {} @@ -44,21 +47,31 @@ InsetCommand::~InsetCommand() } -void InsetCommand::metrics(MetricsInfo & mi, Dimension & dim) const +bool InsetCommand::metrics(MetricsInfo & mi, Dimension & dim) const { - if (updateButtonLabel_) { + if (updateButtonLabel_) { updateButtonLabel_ = false; button_.update(getScreenLabel(*mi.base.bv->buffer()), editable() != NOT_EDITABLE); } button_.metrics(mi, dim); + bool const changed = dim_ != dim; dim_ = dim; + return changed; +} + + +bool InsetCommand::setMouseHover(bool mouse_hover) +{ + mouse_hover_ = mouse_hover; + return true; } void InsetCommand::draw(PainterInfo & pi, int x, int y) const { setPosCache(pi, x, y); + button_.setRenderState(mouse_hover_); button_.draw(pi, x, y); } @@ -70,7 +83,7 @@ void InsetCommand::setParams(InsetCommandParams const & p) } -int InsetCommand::latex(Buffer const &, ostream & os, +int InsetCommand::latex(Buffer const &, odocstream & os, OutputParams const &) const { os << getCommand(); @@ -78,21 +91,14 @@ int InsetCommand::latex(Buffer const &, ostream & os, } -int InsetCommand::plaintext(Buffer const &, ostream &, +int InsetCommand::plaintext(Buffer const &, odocstream &, OutputParams const &) const { return 0; } -int InsetCommand::linuxdoc(Buffer const &, ostream &, - OutputParams const &) const -{ - return 0; -} - - -int InsetCommand::docbook(Buffer const &, ostream &, +int InsetCommand::docbook(Buffer const &, odocstream &, OutputParams const &) const { return 0; @@ -107,8 +113,8 @@ void InsetCommand::doDispatch(LCursor & cur, FuncRequest & cmd) break; case LFUN_INSET_MODIFY: { - InsetCommandParams p; - InsetCommandMailer::string2params(mailer_name_, cmd.argument, p); + InsetCommandParams p(p_.getCmdName()); + InsetCommandMailer::string2params(mailer_name_, to_utf8(cmd.argument()), p); if (p.getCmdName().empty()) cur.noUpdate(); else @@ -116,11 +122,12 @@ void InsetCommand::doDispatch(LCursor & cur, FuncRequest & cmd) break; } - case LFUN_INSET_DIALOG_UPDATE: - InsetCommandMailer(cmd.argument, *this).updateDialog(&cur.bv()); + case LFUN_INSET_DIALOG_UPDATE: { + string const name = to_utf8(cmd.argument()); + InsetCommandMailer(name, *this).updateDialog(&cur.bv()); break; + } - case LFUN_INSET_DIALOG_SHOW: case LFUN_MOUSE_RELEASE: { if (!mailer_name_.empty()) InsetCommandMailer(mailer_name_, *this).showDialog(&cur.bv()); @@ -140,14 +147,13 @@ bool InsetCommand::getStatus(LCursor & cur, FuncRequest const & cmd, { switch (cmd.action) { // suppress these - case LFUN_INSET_ERT: + case LFUN_ERT_INSERT: status.enabled(false); return true; // we handle these case LFUN_INSET_REFRESH: case LFUN_INSET_MODIFY: case LFUN_INSET_DIALOG_UPDATE: - case LFUN_INSET_DIALOG_SHOW: status.enabled(true); return true; default: @@ -156,6 +162,13 @@ bool InsetCommand::getStatus(LCursor & cur, FuncRequest const & cmd, } +void InsetCommand::replaceContents(std::string const & from, string const & to) +{ + if (getContents() == from) + setContents(to); +} + + InsetCommandMailer::InsetCommandMailer(string const & name, InsetCommand & inset) : name_(name), inset_(inset) @@ -172,7 +185,7 @@ void InsetCommandMailer::string2params(string const & name, string const & in, InsetCommandParams & params) { - params = InsetCommandParams(); + params.clear(); if (in.empty()) return; @@ -206,3 +219,6 @@ InsetCommandMailer::params2string(string const & name, data << "\\end_inset\n"; return data.str(); } + + +} // namespace lyx