]> git.lyx.org Git - lyx.git/blobdiff - src/insets/InsetRef.cpp
DocBook: support bookauthor in bibliographies.
[lyx.git] / src / insets / InsetRef.cpp
index 0938b47e2713db4f636dae909e36fe7248431cf7..c8bc837a5f4d50b0ec74dd843fe87d12426aed16 100644 (file)
@@ -260,12 +260,12 @@ void InsetRef::latex(otexstream & os, OutputParams const & rp) const
 {
        string const & cmd = getCmdName();
        docstring const & data = getEscapedLabel(rp);
-       bool const hyper_on = buffer().params().pdfoptions().use_hyperref;
+       bool const hyper_on = buffer().masterParams().pdfoptions().use_hyperref;
 
        if (rp.inulemcmd > 0)
                os << "\\mbox{";
 
-       if (buffer().params().use_refstyle && cmd == "eqref") {
+       if (buffer().masterParams().use_refstyle && cmd == "eqref") {
                // we advertise this as printing "(n)", so we'll do that, at least
                // for refstyle, since refstlye's own \eqref prints, by default,
                // "equation n". if one wants \eqref, one can get it by using a
@@ -281,7 +281,7 @@ void InsetRef::latex(otexstream & os, OutputParams const & rp) const
                docstring prefix;
                bool const use_caps     = getParam("caps") == "true";
                bool const use_plural   = getParam("plural") == "true";
-               bool const use_refstyle = buffer().params().use_refstyle;
+               bool const use_refstyle = buffer().masterParams().use_refstyle;
                docstring const fcmd =
                        getFormattedCmd(data, label, prefix, use_refstyle, use_caps);
                os << fcmd;
@@ -382,11 +382,11 @@ void InsetRef::docbook(XMLStream & xs, OutputParams const &) const
 }
 
 
-docstring InsetRef::xhtml(XMLStream & xs, OutputParams const & op) const
+docstring InsetRef::displayString(docstring const & ref, string const & cmd,
+               string const & language) const
+
 {
-       docstring const & ref = getParam("reference");
        InsetLabel const * il = buffer().insetLabel(ref, true);
-       string const & cmd = params().getCmdName();
        docstring display_string;
 
        if (il && !il->counterValue().empty()) {
@@ -397,11 +397,11 @@ docstring InsetRef::xhtml(XMLStream & xs, OutputParams const & op) const
                else if (cmd == "vref")
                        // normally, would be "ref on page #", but we have no pages
                        display_string = value;
-               else if (cmd == "pageref" || cmd == "vpageref")
+               else if (cmd == "pageref" || cmd == "vpageref") {
                        // normally would be "on page #", but we have no pages.
-                       display_string = translateIfPossible(from_ascii("elsewhere"),
-                               op.local_font->language()->lang());
-               else if (cmd == "eqref")
+                       display_string =
+                               translateIfPossible(from_ascii("elsewhere"), language);
+               else if (cmd == "eqref")
                        display_string = '(' + value + ')';
                else if (cmd == "formatted") {
                        display_string = il->formattedCounter();
@@ -418,14 +418,21 @@ docstring InsetRef::xhtml(XMLStream & xs, OutputParams const & op) const
                        // in that section. So this is not trivial.
                        display_string = il->prettyCounter();
        } else
-                       display_string = ref;
+               display_string = ref;
+       return display_string;
+}
+
 
+docstring InsetRef::xhtml(XMLStream & xs, OutputParams const & op) const
+       {
+       docstring const & ref = getParam("reference");
+       string const & cmd = params().getCmdName();
        // FIXME What we'd really like to do is to be able to output some
        // appropriate sort of text here. But to do that, we need to associate
        // some sort of counter with the label, and we don't have that yet.
        docstring const attr = "href=\"#" + xml::cleanAttr(ref) + '"';
        xs << xml::StartTag("a", to_utf8(attr));
-       xs << display_string;
+       xs << displayString(ref, cmd, getLocalOrDefaultLang(op)->lang());
        xs << xml::EndTag("a");
        return docstring();
 }
@@ -520,14 +527,20 @@ void InsetRef::updateBuffer(ParIterator const & it, UpdateType, bool const /*del
                label += getParam("name");
        }
 
+       bool const use_formatted_ref = buffer().params().use_formatted_ref;
        unsigned int const maxLabelChars = 24;
-       if (label.size() > maxLabelChars) {
+       // Show label in tooltip when formatted references are shown in the work
+       // area or it is too long
+       if (use_formatted_ref || label.size() > maxLabelChars) {
                tooltip_ = label;
                support::truncateWithEllipsis(label, maxLabelChars);
        } else
                tooltip_ = from_ascii("");
 
        screen_label_ = label;
+       // If use_formatted_ref is active, this will be overwritten in addToToc.
+       // (We can't do it now because it might be a forward-reference
+       // and so the reference might not be in the label cache yet.
        broken_ = false;
        setBroken(broken_);
 }
@@ -551,10 +564,18 @@ void InsetRef::addToToc(DocIterator const & cpit, bool output_active,
                        shared_ptr<Toc> toc2 = backend.toc("brokenrefs");
                        toc2->push_back(TocItem(cpit, 0, screenLabel(), output_active));
                }
-               // This InsetRef has already been taken care of in InsetLabel::addToToc().
+
+               // Code for display of formatted references
+               bool const use_formatted_ref = buffer().params().use_formatted_ref;
+               if (use_formatted_ref) {
+                       string const & cmd = getCmdName();
+                       docstring const & ref = getParam("reference");
+                       if (cmd != "pageref" && cmd != "vpageref" && cmd != "vref" &&
+                                       cmd != "labelonly")
+                               screen_label_ = displayString(ref, cmd);
+               }
                return;
        }
-
        // It seems that this reference does not point to any valid label.
        broken_ = true;
        setBroken(broken_);
@@ -576,7 +597,7 @@ void InsetRef::validate(LaTeXFeatures & features) const
                docstring const data = getEscapedLabel(features.runparams());
                docstring label;
                docstring prefix;
-               bool const use_refstyle = buffer().params().use_refstyle;
+               bool const use_refstyle = buffer().masterParams().use_refstyle;
                bool const use_caps   = getParam("caps") == "true";
                docstring const fcmd =
                        getFormattedCmd(data, label, prefix, use_refstyle, use_caps);