X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Finsets%2Finsetbox.C;h=2af61d15e5f8c4343bb0e4a04d02b8b7be3cc14b;hb=e28331ed63062dea10d0a21b9ec12034b4b17b9a;hp=e4547b6c1ca93c51b025bd6ad32c75e0f4fc7370;hpb=038032fefdd878a5d172b983269f5ffe84c640a9;p=lyx.git diff --git a/src/insets/insetbox.C b/src/insets/insetbox.C index e4547b6c1c..2af61d15e5 100644 --- a/src/insets/insetbox.C +++ b/src/insets/insetbox.C @@ -14,9 +14,10 @@ #include "insetbox.h" -#include "BufferView.h" +#include "cursor.h" #include "dispatchresult.h" #include "debug.h" +#include "FuncStatus.h" #include "funcrequest.h" #include "gettext.h" #include "LaTeXFeatures.h" @@ -25,9 +26,13 @@ #include "metricsinfo.h" #include "paragraph.h" -#include "support/std_sstream.h" #include "support/translator.h" +#include + + +namespace lyx { + using std::auto_ptr; using std::string; using std::istringstream; @@ -39,8 +44,10 @@ using std::endl; namespace { typedef Translator BoxTranslator; +typedef Translator BoxTranslatorLoc; -BoxTranslator const init_boxtranslator() { +BoxTranslator const init_boxtranslator() +{ BoxTranslator translator("Boxed", InsetBox::Boxed); translator.addPair("Frameless", InsetBox::Frameless); translator.addPair("ovalbox", InsetBox::ovalbox); @@ -51,8 +58,9 @@ BoxTranslator const init_boxtranslator() { } -BoxTranslator const init_boxtranslator_loc() { - BoxTranslator translator(_("Boxed"), InsetBox::Boxed); +BoxTranslatorLoc const init_boxtranslator_loc() +{ + BoxTranslatorLoc translator(_("Boxed"), InsetBox::Boxed); translator.addPair(_("Frameless"), InsetBox::Frameless); translator.addPair(_("ovalbox"), InsetBox::ovalbox); translator.addPair(_("Ovalbox"), InsetBox::Ovalbox); @@ -62,14 +70,16 @@ BoxTranslator const init_boxtranslator_loc() { } -BoxTranslator const & boxtranslator() { +BoxTranslator const & boxtranslator() +{ static BoxTranslator translator = init_boxtranslator(); return translator; } -BoxTranslator const & boxtranslator_loc() { - static BoxTranslator translator = init_boxtranslator_loc(); +BoxTranslatorLoc const & boxtranslator_loc() +{ + static BoxTranslatorLoc translator = init_boxtranslator_loc(); return translator; } @@ -78,7 +88,7 @@ BoxTranslator const & boxtranslator_loc() { void InsetBox::init() { - setInsetName("Box"); + setInsetName(from_ascii("Box")); setButtonLabel(); } @@ -103,13 +113,13 @@ InsetBox::~InsetBox() } -auto_ptr InsetBox::clone() const +auto_ptr InsetBox::doClone() const { return auto_ptr(new InsetBox(*this)); } -string const InsetBox::editMessage() const +docstring const InsetBox::editMessage() const { return _("Opened Box Inset"); } @@ -137,13 +147,20 @@ void InsetBox::setButtonLabel() font.decSize(); BoxType btype = boxtranslator().find(params_.type); + + docstring label; + label += _("Box"); + label += " ("; if (btype == Frameless) { if (params_.use_parbox) - setLabel(_("Box") + " (" + _("Parbox") + ")"); + label += _("Parbox"); else - setLabel(_("Box") + " (" + _("Minipage") + ")"); + label += _("Minipage"); } else - setLabel(_("Box") + " (" + boxtranslator_loc().find(btype) + ")"); + label += boxtranslator_loc().find(btype); + label += ")"; + + setLabel(label); font.setColor(LColor::foreground); setBackgroundColor(LColor::background); @@ -151,14 +168,27 @@ void InsetBox::setButtonLabel() } -void InsetBox::metrics(MetricsInfo & m, Dimension & dim) const +bool InsetBox::hasFixedWidth() const +{ + return params_.inner_box || params_.special != "width"; +} + + +bool InsetBox::metrics(MetricsInfo & m, Dimension & dim) const { MetricsInfo mi = m; - mi.base.textwidth = params_.width.inPixels(m.base.textwidth); + if (hasFixedWidth()) + mi.base.textwidth = params_.width.inPixels(m.base.textwidth); InsetCollapsable::metrics(mi, dim); - //if (params_.inner_box && isOpen()) - // dim.wid = mi.base.textwidth; + bool const changed = dim_ != dim; dim_ = dim; + return changed; +} + + +bool InsetBox::forceDefaultParagraphs(idx_type) const +{ + return !params_.inner_box; } @@ -169,43 +199,60 @@ bool InsetBox::showInsetDialog(BufferView * bv) const } -DispatchResult -InsetBox::priv_dispatch(FuncRequest const & cmd, - idx_type & idx, pos_type & pos) +void InsetBox::doDispatch(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_); + //lyxerr << "InsetBox::dispatch MODIFY" << endl; + InsetBoxMailer::string2params(to_utf8(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; + } + InsetCollapsable::doDispatch(cur, cmd); + break; + + default: + InsetCollapsable::doDispatch(cur, cmd); + break; + } +} + + +bool InsetBox::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; + case LFUN_BREAK_PARAGRAPH: + if (params_.inner_box) { + return InsetCollapsable::getStatus(cur, cmd, flag); + } else { + flag.enabled(false); + return true; } - return InsetCollapsable::priv_dispatch(cmd, idx, pos); default: - return InsetCollapsable::priv_dispatch(cmd, idx, pos); + return InsetCollapsable::getStatus(cur, cmd, flag); } } -int InsetBox::latex(Buffer const & buf, ostream & os, +int InsetBox::latex(Buffer const & buf, odocstream & os, OutputParams const & runparams) const { BoxType btype = boxtranslator().find(params_.type); @@ -252,11 +299,14 @@ int InsetBox::latex(Buffer const & buf, ostream & os, if (!params_.inner_box) { os << "{\\makebox"; // Special widths, see usrguide ยง3.5 + // FIXME UNICODE if (params_.special != "none") { os << "[" << params_.width.value() - << "\\" << params_.special << "]"; + << '\\' << from_utf8(params_.special) + << ']'; } else - os << "[" << width_string << "]"; + os << '[' << from_ascii(width_string) + << ']'; if (params_.hor_pos != 'c') os << "[" << params_.hor_pos << "]"; } @@ -285,16 +335,21 @@ int InsetBox::latex(Buffer const & buf, ostream & os, os << "[" << params_.pos << "]"; if (params_.height_special == "none") { - os << "[" << params_.height.asLatexString() << "]"; + // FIXME UNICODE + os << '[' << from_ascii(params_.height.asLatexString()) + << ']'; } else { // Special heights + // FIXME UNICODE os << "[" << params_.height.value() - << "\\" << params_.height_special << "]"; + << '\\' << from_utf8(params_.height_special) + << ']'; } if (params_.inner_pos != params_.pos) os << "[" << params_.inner_pos << "]"; - os << "{" << width_string << "}"; + // FIXME UNICODE + os << '{' << from_ascii(width_string) << '}'; if (params_.use_parbox) os << "{"; @@ -302,7 +357,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) @@ -334,21 +389,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); -} - - -int InsetBox::docbook(Buffer const & buf, std::ostream & os, +int InsetBox::docbook(Buffer const & buf, odocstream & os, OutputParams const & runparams) const { - return inset.docbook(buf, os, runparams); + return InsetText::docbook(buf, os, runparams); } -int InsetBox::plaintext(Buffer const & buf, std::ostream & os, +int InsetBox::plaintext(Buffer const & buf, odocstream & os, OutputParams const & runparams) const { BoxType const btype = boxtranslator().find(params_.type); @@ -362,7 +410,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; @@ -392,14 +440,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"; @@ -590,3 +637,6 @@ void InsetBoxParams::read(LyXLex & lex) lex.pushToken(token); } } + + +} // namespace lyx