X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Finsets%2Finsetbox.C;h=4f8124fff5579fdd78c07bd616787fb684de7ebc;hb=5603df4a5b7e511b31026c9a4f8f55b2b10fde57;hp=c1902b32bf30a2785f04660eaceadbe895bad425;hpb=de49e029348c639be64ec77cc9d292c0da6ddc3b;p=lyx.git diff --git a/src/insets/insetbox.C b/src/insets/insetbox.C index c1902b32bf..4f8124fff5 100644 --- a/src/insets/insetbox.C +++ b/src/insets/insetbox.C @@ -14,7 +14,7 @@ #include "insetbox.h" -#include "BufferView.h" +#include "cursor.h" #include "dispatchresult.h" #include "debug.h" #include "funcrequest.h" @@ -26,6 +26,7 @@ #include "paragraph.h" #include "support/std_sstream.h" +#include "support/translator.h" using std::auto_ptr; using std::string; @@ -37,6 +38,8 @@ using std::endl; namespace { +typedef Translator BoxTranslator; + BoxTranslator const init_boxtranslator() { BoxTranslator translator("Boxed", InsetBox::Boxed); translator.addPair("Frameless", InsetBox::Frameless); @@ -96,8 +99,7 @@ InsetBox::InsetBox(InsetBox const & in) InsetBox::~InsetBox() { - InsetBoxMailer mailer(*this); - mailer.hideDialog(); + InsetBoxMailer(*this).hideDialog(); } @@ -137,11 +139,11 @@ void InsetBox::setButtonLabel() BoxType btype = boxtranslator().find(params_.type); if (btype == Frameless) { if (params_.use_parbox) - setLabel(_("Parbox")); + setLabel(_("Box") + " (" + _("Parbox") + ")"); else - setLabel(_("Minipage")); + setLabel(_("Box") + " (" + _("Minipage") + ")"); } else - setLabel(boxtranslator_loc().find(btype)); + setLabel(_("Box") + " (" + boxtranslator_loc().find(btype) + ")"); font.setColor(LColor::foreground); setBackgroundColor(LColor::background); @@ -152,7 +154,7 @@ void InsetBox::setButtonLabel() void InsetBox::metrics(MetricsInfo & m, Dimension & dim) const { MetricsInfo mi = m; - mi.base.textwidth = params_.width.inPixels(m.base.textwidth); + mi.base.textwidth = params_.width.inPixels(m.base.textwidth); InsetCollapsable::metrics(mi, dim); //if (params_.inner_box && isOpen()) // dim.wid = mi.base.textwidth; @@ -167,38 +169,32 @@ bool InsetBox::showInsetDialog(BufferView * bv) const } -DispatchResult -InsetBox::priv_dispatch(FuncRequest const & cmd, - idx_type & idx, pos_type & pos) +void InsetBox::priv_dispatch(LCursor & cur, FuncRequest & cmd) { - DispatchResult result(false); - BufferView * bv = cmd.view(); - switch (cmd.action) { case LFUN_INSET_MODIFY: { lyxerr << "InsetBox::dispatch MODIFY" << endl; InsetBoxMailer::string2params(cmd.argument, params_); setButtonLabel(); - result.dispatched(true); - result.update(true); - return result; + break; } case LFUN_INSET_DIALOG_UPDATE: - InsetBoxMailer(*this).updateDialog(bv); - result.dispatched(true); - return result; + InsetBoxMailer(*this).updateDialog(&cur.bv()); + break; case LFUN_MOUSE_RELEASE: if (cmd.button() == mouse_button::button3 && hitButton(cmd)) { - InsetBoxMailer(*this).showDialog(bv); - return DispatchResult(true); + InsetBoxMailer(*this).showDialog(&cur.bv()); + break; } - return InsetCollapsable::priv_dispatch(cmd, idx, pos); + InsetCollapsable::priv_dispatch(cur, cmd); + break; default: - return InsetCollapsable::priv_dispatch(cmd, idx, pos); + InsetCollapsable::priv_dispatch(cur, cmd); + break; } } @@ -300,7 +296,7 @@ int InsetBox::latex(Buffer const & buf, ostream & os, i += 1; } - i += inset.latex(buf, os, runparams); + i += InsetText::latex(buf, os, runparams); if (params_.inner_box) { if (params_.use_parbox) @@ -335,14 +331,14 @@ int InsetBox::latex(Buffer const & buf, ostream & os, int InsetBox::linuxdoc(Buffer const & buf, std::ostream & os, OutputParams const & runparams) const { - return inset.linuxdoc(buf, os, runparams); + return InsetText::linuxdoc(buf, os, runparams); } int InsetBox::docbook(Buffer const & buf, std::ostream & os, OutputParams const & runparams) const { - return inset.docbook(buf, os, runparams); + return InsetText::docbook(buf, os, runparams); } @@ -360,7 +356,7 @@ int InsetBox::plaintext(Buffer const & buf, std::ostream & os, case Doublebox: os << "[["; break; } - int i = inset.plaintext(buf, os, runparams); + int i = InsetText::plaintext(buf, os, runparams); switch (btype) { case Frameless: break; @@ -390,14 +386,13 @@ void InsetBox::validate(LaTeXFeatures & features) const features.require("fancybox"); break; } - inset.validate(features); + InsetText::validate(features); } InsetBoxMailer::InsetBoxMailer(InsetBox & inset) : inset_(inset) -{ -} +{} string const InsetBoxMailer::name_ = "box"; @@ -419,10 +414,9 @@ string const InsetBoxMailer::params2string(InsetBoxParams const & params) void InsetBoxMailer::string2params(string const & in, - InsetBoxParams & params) + InsetBoxParams & params) { params = InsetBoxParams(string()); - if (in.empty()) return; @@ -430,10 +424,17 @@ void InsetBoxMailer::string2params(string const & in, LyXLex lex(0,0); lex.setStream(data); - string token; - lex.next(); - token = lex.getString(); - lex.next(); + string name; + lex >> name; + if (!lex || name != name_) + return print_mailer_error("InsetBoxMailer", in, 1, name_); + + // This is part of the inset proper that is usually swallowed + // by LyXText::readInset + string id; + lex >> id; + if (!lex || id != "Box") + return print_mailer_error("InsetBoxMailer", in, 2, "Box"); params.read(lex); } @@ -455,7 +456,7 @@ InsetBoxParams::InsetBoxParams(string const & label) void InsetBoxParams::write(ostream & os) const { - os << type << "\n"; + os << "Box " << type << "\n"; os << "position \"" << pos << "\"\n"; os << "hor_pos \"" << hor_pos << "\"\n"; os << "has_inner_box " << inner_box << "\n"; @@ -470,13 +471,17 @@ void InsetBoxParams::write(ostream & os) const void InsetBoxParams::read(LyXLex & lex) { + if (!lex.isOK()) + return; + if (lex.isOK()) { + lex.next(); type = lex.getString(); } - string token; if (!lex.isOK()) return; lex.next(); + string token; token = lex.getString(); if (token == "position") { lex.next();