X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Finsets%2FInsetListings.cpp;h=0c6b472da86d171f4f73db9d0686dc52fcaa8fb2;hb=237c132c1e6fc720b87f2fea6deb18a8395cbe0a;hp=cac92f8ce1d2a748ab92c2e69b4567aebec63799;hpb=c20baf584c1737162d639fac4b049d002b24cd58;p=lyx.git diff --git a/src/insets/InsetListings.cpp b/src/insets/InsetListings.cpp index cac92f8ce1..0c6b472da8 100644 --- a/src/insets/InsetListings.cpp +++ b/src/insets/InsetListings.cpp @@ -14,6 +14,9 @@ #include "InsetListings.h" #include "InsetCaption.h" +#include "Buffer.h" +#include "BufferParams.h" +#include "Counters.h" #include "Language.h" #include "gettext.h" #include "DispatchResult.h" @@ -31,13 +34,13 @@ 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() { @@ -47,8 +50,9 @@ void InsetListings::init() font.decSize(); 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); } @@ -66,9 +70,9 @@ InsetListings::InsetListings(InsetListings const & in) } -auto_ptr InsetListings::doClone() const +Inset * InsetListings::clone() const { - return auto_ptr(new InsetListings(*this)); + return new InsetListings(*this); } @@ -84,6 +88,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"; @@ -135,7 +154,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 +175,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,6 +195,8 @@ 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); if (param_string.empty() && caption.empty()) @@ -190,12 +211,8 @@ 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; } @@ -252,16 +269,13 @@ void InsetListings::setButtonLabel() } -bool InsetListings::metrics(MetricsInfo & mi, Dimension & dim) const +void 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; }