X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Finsets%2FInsetListings.cpp;h=0b63ec28e6783c45f3bd06a9da710068096c7d42;hb=a694476ac68fd56c23eace194e9e6ac5b2a5cac5;hp=082c1a6de8b656e944acd83f346538a766e3a2f8;hpb=af06ed5ff1aa10021480da9c393a4ddb6b182933;p=lyx.git diff --git a/src/insets/InsetListings.cpp b/src/insets/InsetListings.cpp index 082c1a6de8..0b63ec28e6 100644 --- a/src/insets/InsetListings.cpp +++ b/src/insets/InsetListings.cpp @@ -17,57 +17,38 @@ #include "Buffer.h" #include "BufferParams.h" #include "Counters.h" -#include "Language.h" -#include "gettext.h" +#include "Cursor.h" #include "DispatchResult.h" #include "FuncRequest.h" #include "FuncStatus.h" +#include "support/gettext.h" +#include "InsetList.h" +#include "Language.h" #include "MetricsInfo.h" -#include "Cursor.h" +#include "TextClass.h" + +#include "support/docstream.h" #include "support/lstrings.h" #include -namespace lyx { +using namespace std; +using namespace lyx::support; -using support::token; -using support::contains; -using support::subst; +namespace lyx { -using std::istringstream; -using std::ostream; -using std::ostringstream; -using std::string; char const lstinline_delimiters[] = "!*()-=+|;:'\"`,<.>/?QWERTYUIOPASDFGHJKLZXCVBNMqwertyuiopasdfghjklzxcvbnm"; -void InsetListings::init() -{ - setButtonLabel(); - Font font(Font::ALL_SANE); - font.decSize(); - font.decSize(); - font.setColor(Color::none); - setLabelFont(font); - // FIXME: what to do with those? - //text_.current_font.setLanguage(latex_language); - //text_.real_current_font.setLanguage(latex_language); -} - - -InsetListings::InsetListings(BufferParams const & bp, InsetListingsParams const & par) - : InsetERT(bp, par.status()) -{ - init(); -} +InsetListings::InsetListings(Buffer const & buf, InsetListingsParams const & par) + : InsetCollapsable(buf, par.status()) +{} InsetListings::InsetListings(InsetListings const & in) - : InsetERT(in), params_(in.params_) -{ - init(); -} + : InsetCollapsable(in), params_(in.params_) +{} Inset * InsetListings::clone() const @@ -88,22 +69,22 @@ Inset::DisplayType InsetListings::display() const } -void InsetListings::updateLabels(Buffer const & buf, ParIterator const & it) +void InsetListings::updateLabels(ParIterator const & it) { - Counters & cnts = buf.params().getTextClass().counters(); + Counters & cnts = buffer().params().documentClass().counters(); string const saveflt = cnts.current_float(); // Tell to captions what the current float is cnts.current_float("listing"); - InsetCollapsable::updateLabels(buf, it); + InsetCollapsable::updateLabels(it); //reset afterwards cnts.current_float(saveflt); } -void InsetListings::write(Buffer const & buf, ostream & os) const +void InsetListings::write(ostream & os) const { os << "listings" << "\n"; InsetListingsParams const & par = params(); @@ -115,11 +96,11 @@ void InsetListings::write(Buffer const & buf, ostream & os) const os << "inline true\n"; else os << "inline false\n"; - InsetCollapsable::write(buf, os); + InsetCollapsable::write(os); } -void InsetListings::read(Buffer const & buf, Lexer & lex) +void InsetListings::read(Lexer & lex) { while (lex.isOK()) { lex.next(); @@ -137,18 +118,17 @@ void InsetListings::read(Buffer const & buf, Lexer & lex) break; } } - InsetERT::read(buf, lex); + InsetCollapsable::read(lex); } -docstring const InsetListings::editMessage() const +docstring InsetListings::editMessage() const { return _("Opened Listing Inset"); } -int InsetListings::latex(Buffer const & buf, odocstream & os, - OutputParams const & runparams) const +int InsetListings::latex(odocstream & os, OutputParams const & runparams) const { string param_string = params().params(); // NOTE: I use {} to quote text, which is an experimental feature @@ -198,7 +178,13 @@ int InsetListings::latex(Buffer const & buf, odocstream & os, os << code << *delimiter; } else { - docstring const caption = getCaption(buf, runparams); + OutputParams rp = runparams; + // FIXME: the line below would fix bug 4182, + // but real_current_font moved to cursor. + //rp.local_font = &text_.real_current_font; + rp.moving_arg = true; + docstring const caption = getCaption(rp); + runparams.encoding = rp.encoding; if (param_string.empty() && caption.empty()) os << "\n\\begingroup\n\\inputencoding{latin1}\n\\begin{lstlisting}\n"; else { @@ -211,8 +197,7 @@ int InsetListings::latex(Buffer const & buf, odocstream & os, os << from_utf8(param_string) << "]\n"; } lines += 4; - os << code - << "\n\\end{lstlisting}\n\\endgroup\n"; + os << code << "\n\\end{lstlisting}\n\\endgroup\n"; lines += 3; } @@ -236,11 +221,11 @@ void InsetListings::doDispatch(Cursor & cur, FuncRequest & cmd) InsetListingsMailer(*this).showDialog(&cur.bv()); break; } - InsetERT::doDispatch(cur, cmd); + InsetCollapsable::doDispatch(cur, cmd); break; } default: - InsetERT::doDispatch(cur, cmd); + InsetCollapsable::doDispatch(cur, cmd); break; } } @@ -257,7 +242,7 @@ bool InsetListings::getStatus(Cursor & cur, FuncRequest const & cmd, status.enabled(!params().isInline()); return true; default: - return InsetERT::getStatus(cur, cmd, status); + return InsetCollapsable::getStatus(cur, cmd, status); } } @@ -265,37 +250,17 @@ bool InsetListings::getStatus(Cursor & cur, FuncRequest const & cmd, void InsetListings::setButtonLabel() { // FIXME UNICODE - setLabel(isOpen() ? _("Listing") : getNewLabel(_("Listing"))); -} - - -bool InsetListings::metrics(MetricsInfo & mi, Dimension & dim) const -{ - Font tmpfont = mi.base.font; - getDrawFont(mi.base.font); - mi.base.font.realize(tmpfont); - InsetCollapsable::metrics(mi, dim); - mi.base.font = tmpfont; - bool const changed = dim_ != dim; - dim_ = dim; - return changed; -} - - -void InsetListings::draw(PainterInfo & pi, int x, int y) const -{ - Font tmpfont = pi.base.font; - getDrawFont(pi.base.font); - pi.base.font.realize(tmpfont); - InsetCollapsable::draw(pi, x, y); - pi.base.font = tmpfont; + if (decoration() == InsetLayout::Classic) + setLabel(isOpen() ? _("Listing") : getNewLabel(_("Listing"))); + else + setLabel(getNewLabel(_("Listing"))); } void InsetListings::validate(LaTeXFeatures & features) const { features.require("listings"); - InsetERT::validate(features); + InsetCollapsable::validate(features); } @@ -306,32 +271,22 @@ bool InsetListings::showInsetDialog(BufferView * bv) const } -void InsetListings::getDrawFont(Font & font) const -{ - font = Font(Font::ALL_INHERIT, latex_language); - font.setFamily(Font::TYPEWRITER_FAMILY); - // FIXME: define Color::listing? - font.setColor(Color::foreground); -} - - -docstring InsetListings::getCaption(Buffer const & buf, - OutputParams const & runparams) const +docstring InsetListings::getCaption(OutputParams const & runparams) const { if (paragraphs().empty()) return docstring(); ParagraphList::const_iterator pit = paragraphs().begin(); for (; pit != paragraphs().end(); ++pit) { - InsetList::const_iterator it = pit->insetlist.begin(); - for (; it != pit->insetlist.end(); ++it) { + InsetList::const_iterator it = pit->insetList().begin(); + for (; it != pit->insetList().end(); ++it) { Inset & inset = *it->inset; - if (inset.lyxCode() == Inset::CAPTION_CODE) { + if (inset.lyxCode() == CAPTION_CODE) { odocstringstream ods; InsetCaption * ins = static_cast(it->inset); - ins->getOptArg(buf, ods, runparams); - ins->getArgument(buf, ods, runparams); + ins->getOptArg(ods, runparams); + ins->getArgument(ods, runparams); return ods.str(); } }