]> git.lyx.org Git - lyx.git/blobdiff - src/insets/InsetText.cpp
New attempt on #9906: allow following hyperlinks via context menu.
[lyx.git] / src / insets / InsetText.cpp
index ac10443d00bcf04f67094c442db42e079dfc8b4f..10b15c88edad34abd39a31fb90b9223ff2700e91 100644 (file)
 #include "MetricsInfo.h"
 #include "output_docbook.h"
 #include "output_latex.h"
+#include "output_plaintext.h"
 #include "output_xhtml.h"
 #include "OutputParams.h"
-#include "output_plaintext.h"
 #include "Paragraph.h"
 #include "ParagraphParameters.h"
 #include "ParIterator.h"
 #include "Row.h"
-#include "xml.h"
 #include "TexRow.h"
 #include "texstream.h"
 #include "TextClass.h"
@@ -78,7 +77,8 @@ using graphics::PreviewLoader;
 /////////////////////////////////////////////////////////////////////
 
 InsetText::InsetText(Buffer * buf, UsePlain type)
-       : Inset(buf), drawFrame_(false), is_changed_(false), frame_color_(Color_insetframe),
+       : Inset(buf), drawFrame_(false), is_changed_(false), intitle_context_(false),
+         frame_color_(Color_insetframe),
        text_(this, type == DefaultLayout)
 {
 }
@@ -86,7 +86,7 @@ InsetText::InsetText(Buffer * buf, UsePlain type)
 
 InsetText::InsetText(InsetText const & in)
        : Inset(in), drawFrame_(in.drawFrame_), is_changed_(in.is_changed_),
-         frame_color_(in.frame_color_),
+         intitle_context_(false), frame_color_(in.frame_color_),
          text_(this, in.text_)
 {
 }
@@ -529,6 +529,9 @@ void InsetText::latex(otexstream & os, OutputParams const & runparams) const
        runparams.encoding = rp.encoding;
        // Pass the post_macros upstream
        runparams.post_macro = rp.post_macro;
+       // These need to be passed upstream as well
+       runparams.need_maketitle = rp.need_maketitle;
+       runparams.have_maketitle = rp.have_maketitle;
 
        if (!il.rightdelim().empty())
                os << il.rightdelim();
@@ -585,20 +588,52 @@ int InsetText::plaintext(odocstringstream & os,
 }
 
 
-int InsetText::docbook(odocstream & os, OutputParams const & runparams) const
+
+void InsetText::docbook(XMLStream & xs, OutputParams const & rp) const
+{
+       docbook(xs, rp, WriteEverything);
+}
+
+
+void InsetText::docbook(XMLStream & xs, OutputParams const & rp, XHTMLOptions opts) const
 {
-       ParagraphList::const_iterator const beg = paragraphs().begin();
+       // we will always want to output all our paragraphs when we are
+       // called this way.
+       OutputParams runparams = rp;
+       runparams.par_begin = 0;
+       runparams.par_end = text().paragraphs().size();
+
+       if (undefined()) {
+               xs.startDivision(false);
+               docbookParagraphs(text_, buffer(), xs, runparams);
+               xs.endDivision();
+               return;
+       }
+
+       InsetLayout const & il = getLayout();
+       if (opts & WriteOuterTag && !il.docbooktag().empty() && il.docbooktag() != "NONE") {
+               docstring attrs = docstring();
+               if (!il.docbookattr().empty())
+                       attrs += from_ascii(il.docbookattr());
+               if (il.docbooktag() == "link")
+                       attrs += from_ascii(" xlink:href=\"") + text_.asString() + from_ascii("\"");
+               xs << xml::StartTag(il.docbooktag(), attrs);
+       }
 
-       if (!undefined())
-               xml::openTag(os, getLayout().latexname(),
-                             beg->getID(buffer(), runparams) + getLayout().latexparam());
+       // No need for labels that are generated from counters.
 
-       docbookParagraphs(text_, buffer(), os, runparams);
+       // With respect to XHTML, paragraphs are still allowed here.
+       if (!allowMultiPar())
+               runparams.docbook_make_pars = false;
+       if (il.isPassThru())
+               runparams.pass_thru = true;
 
-       if (!undefined())
-               xml::closeTag(os, getLayout().latexname());
+       xs.startDivision(false);
+       docbookParagraphs(text_, buffer(), xs, runparams);
+       xs.endDivision();
 
-       return 0;
+       if (opts & WriteOuterTag)
+               xs << xml::EndTag(il.docbooktag());
 }
 
 
@@ -835,6 +870,17 @@ void InsetText::updateBuffer(ParIterator const & it, UpdateType utype, bool cons
                        cnt.restoreLastLayout();
                        // FIXME cnt.restoreLastCounter()?
                }
+               // Record in this inset is embedded in a title layout
+               // This is needed to decide when \maketitle is output.
+               intitle_context_ = it.paragraph().layout().intitle;
+               // Also check embedding layouts
+               size_t const n = it.depth();
+               for (size_t i = 0; i < n; ++i) {
+                       if (it[i].paragraph().layout().intitle) {
+                               intitle_context_ = true;
+                               break;
+                       }
+               }
        } else {
                DocumentClass const & tclass = buffer().masterBuffer()->params().documentClass();
                // Note that we do not need to call: