X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Finsets%2FInsetListings.cpp;h=b52e9fb9afa9b09b51ea23e7976bc20a88d4c060;hb=3d443b4c9dc657663a7d67c8254894345e551a06;hp=e756d4fb7b5c462890aad16e0fa9709ca1a6d929;hpb=601a8e0192b60274ab316c0bfa31811d236c972e;p=lyx.git diff --git a/src/insets/InsetListings.cpp b/src/insets/InsetListings.cpp index e756d4fb7b..b52e9fb9af 100644 --- a/src/insets/InsetListings.cpp +++ b/src/insets/InsetListings.cpp @@ -17,13 +17,15 @@ #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 "gettext.h" +#include "InsetList.h" +#include "Language.h" #include "MetricsInfo.h" -#include "Cursor.h" + #include "support/lstrings.h" #include @@ -34,44 +36,46 @@ using support::token; using support::contains; using support::subst; -using std::auto_ptr; using std::istringstream; using std::ostream; using std::ostringstream; using std::string; -char const lstinline_delimiters[] = "!*()-=+|;:'\"`,<.>/?QWERTYUIOPASDFGHJKLZXCVBNMqwertyuiopasdfghjklzxcvbnm"; +char const lstinline_delimiters[] = + "!*()-=+|;:'\"`,<.>/?QWERTYUIOPASDFGHJKLZXCVBNMqwertyuiopasdfghjklzxcvbnm"; void InsetListings::init() { setButtonLabel(); - Font font(Font::ALL_SANE); + FontInfo font = sane_font; font.decSize(); font.decSize(); - font.setColor(Color::none); + font.setColor(Color_none); setLabelFont(font); - text_.current_font.setLanguage(latex_language); - text_.real_current_font.setLanguage(latex_language); + // 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()) + : InsetCollapsable(bp, par.status()) { + setLayout(bp); init(); } InsetListings::InsetListings(InsetListings const & in) - : InsetERT(in), params_(in.params_) + : InsetCollapsable(in), params_(in.params_) { init(); } -auto_ptr InsetListings::doClone() const +Inset * InsetListings::clone() const { - return auto_ptr(new InsetListings(*this)); + return new InsetListings(*this); } @@ -136,7 +140,7 @@ void InsetListings::read(Buffer const & buf, Lexer & lex) break; } } - InsetERT::read(buf, lex); + InsetCollapsable::read(buf, lex); } @@ -197,7 +201,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(buf, rp); + runparams.encoding = rp.encoding; if (param_string.empty() && caption.empty()) os << "\n\\begingroup\n\\inputencoding{latin1}\n\\begin{lstlisting}\n"; else { @@ -235,11 +245,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; } } @@ -256,7 +266,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); } } @@ -264,37 +274,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() == 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); } @@ -305,15 +295,6 @@ 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 { @@ -322,10 +303,10 @@ docstring InsetListings::getCaption(Buffer const & buf, 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);