X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Finsets%2FInsetListings.cpp;h=d3deadb6242df1fc3a51a4cf5b6cef0c2fe46098;hb=2c357c1d23b7b83839a9beb8225d4f1ae4f793b4;hp=cac92f8ce1d2a748ab92c2e69b4567aebec63799;hpb=c20baf584c1737162d639fac4b049d002b24cd58;p=lyx.git diff --git a/src/insets/InsetListings.cpp b/src/insets/InsetListings.cpp index cac92f8ce1..d3deadb624 100644 --- a/src/insets/InsetListings.cpp +++ b/src/insets/InsetListings.cpp @@ -14,61 +14,46 @@ #include "InsetListings.h" #include "InsetCaption.h" -#include "Language.h" -#include "gettext.h" +#include "Buffer.h" +#include "BufferParams.h" +#include "Counters.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 support::token; -using support::contains; -using support::subst; - -using std::auto_ptr; -using std::istringstream; -using std::ostream; -using std::ostringstream; -using std::string; +using namespace std; +using namespace lyx::support; -char const lstinline_delimiters[] = "!*()-=+|;:'\"`,<.>/?QWERTYUIOPASDFGHJKLZXCVBNMqwertyuiopasdfghjklzxcvbnm"; +namespace lyx { -void InsetListings::init() -{ - setButtonLabel(); - Font font(Font::ALL_SANE); - font.decSize(); - font.decSize(); - font.setColor(Color::none); - setLabelFont(font); - text_.current_font.setLanguage(latex_language); - text_.real_current_font.setLanguage(latex_language); -} +char const lstinline_delimiters[] = + "!*()-=+|;:'\"`,<.>/?QWERTYUIOPASDFGHJKLZXCVBNMqwertyuiopasdfghjklzxcvbnm"; InsetListings::InsetListings(BufferParams const & bp, InsetListingsParams const & par) - : InsetERT(bp, par.status()) -{ - init(); -} + : InsetCollapsable(bp, par.status()) +{} InsetListings::InsetListings(InsetListings const & in) - : InsetERT(in), params_(in.params_) -{ - init(); -} + : InsetCollapsable(in), params_(in.params_) +{} -auto_ptr InsetListings::doClone() const +Inset * InsetListings::clone() const { - return auto_ptr(new InsetListings(*this)); + return new InsetListings(*this); } @@ -84,6 +69,21 @@ Inset::DisplayType InsetListings::display() const } +void InsetListings::updateLabels(Buffer const & buf, ParIterator const & it) +{ + Counters & cnts = buf.params().getTextClass().counters(); + string const saveflt = cnts.current_float(); + + // Tell to captions what the current float is + cnts.current_float("listing"); + + InsetCollapsable::updateLabels(buf, it); + + //reset afterwards + cnts.current_float(saveflt); +} + + void InsetListings::write(Buffer const & buf, ostream & os) const { os << "listings" << "\n"; @@ -118,7 +118,7 @@ void InsetListings::read(Buffer const & buf, Lexer & lex) break; } } - InsetERT::read(buf, lex); + InsetCollapsable::read(buf, lex); } @@ -135,7 +135,7 @@ int InsetListings::latex(Buffer const & buf, odocstream & os, // NOTE: I use {} to quote text, which is an experimental feature // of the listings package (see page 25 of the manual) int lines = 0; - bool lstinline = params().isInline(); + bool isInline = params().isInline(); // get the paragraphs. We can not output them directly to given odocstream // because we can not yet determine the delimiter character of \lstinline docstring code; @@ -156,17 +156,17 @@ int InsetListings::latex(Buffer const & buf, odocstream & os, ++par; // for the inline case, if there are multiple paragraphs // they are simply joined. Otherwise, expect latex errors. - if (par != end && !lstinline && !captionline) { + if (par != end && !isInline && !captionline) { code += "\n"; ++lines; } } - char const * delimiter; - if (lstinline) { - for (delimiter = lstinline_delimiters; delimiter != '\0'; ++delimiter) + if (isInline) { + char const * delimiter = lstinline_delimiters; + for (; delimiter != '\0'; ++delimiter) if (!contains(code, *delimiter)) break; - // this code piece contains all possible special character? !!! + // This code piece contains all possible special character? !!! // Replace ! with a warning message and use ! as delimiter. if (*delimiter == '\0') { code = subst(code, from_ascii("!"), from_ascii(" WARNING: no lstline delimiter can be used ")); @@ -176,8 +176,16 @@ int InsetListings::latex(Buffer const & buf, odocstream & os, os << "\\lstinline" << *delimiter; else os << "\\lstinline[" << from_ascii(param_string) << "]" << *delimiter; + 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 { @@ -190,12 +198,7 @@ int InsetListings::latex(Buffer const & buf, odocstream & os, os << from_utf8(param_string) << "]\n"; } lines += 4; - } - os << code; - if (lstinline) - os << *delimiter; - else { - os << "\n\\end{lstlisting}\n\\endgroup\n"; + os << code << "\n\\end{lstlisting}\n\\endgroup\n"; lines += 3; } @@ -219,11 +222,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; } } @@ -240,7 +243,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); } } @@ -248,37 +251,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() == Deco_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); } @@ -289,27 +272,18 @@ 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 + 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);