]> git.lyx.org Git - lyx.git/blobdiff - src/insets/InsetText.cpp
Remove all BufferParam arguments in InsetXXX methods (since insets know about their...
[lyx.git] / src / insets / InsetText.cpp
index 1d843502ce4e4f718ba890ae4ae7d1402578060c..a396041a30bbb453b7725cf64aa325835495df3e 100644 (file)
@@ -26,6 +26,7 @@
 #include "ErrorList.h"
 #include "FuncRequest.h"
 #include "FuncStatus.h"
+#include "InsetCaption.h"
 #include "InsetList.h"
 #include "Intl.h"
 #include "Lexer.h"
@@ -34,6 +35,7 @@
 #include "MetricsInfo.h"
 #include "output_docbook.h"
 #include "output_latex.h"
+#include "output_xhtml.h"
 #include "OutputParams.h"
 #include "output_plaintext.h"
 #include "paragraph_funcs.h"
@@ -71,11 +73,11 @@ using graphics::PreviewLoader;
 
 /////////////////////////////////////////////////////////////////////
 
-InsetText::InsetText(Buffer const & buf)
+InsetText::InsetText(Buffer const & buf, UsePlain type)
        : drawFrame_(false), frame_color_(Color_insetframe)
 {
        setBuffer(const_cast<Buffer &>(buf));
-       initParagraphs();
+       initParagraphs(type);
 }
 
 
@@ -99,13 +101,17 @@ void InsetText::setBuffer(Buffer & buf)
 }
 
 
-void InsetText::initParagraphs()
+void InsetText::initParagraphs(UsePlain type)
 {
        LASSERT(paragraphs().empty(), /**/);
        paragraphs().push_back(Paragraph());
        Paragraph & ourpar = paragraphs().back();
        ourpar.setInsetOwner(this);
-       ourpar.setDefaultLayout(buffer_->params().documentClass());
+       DocumentClass const & dc = buffer_->params().documentClass();
+       if (type == DefaultLayout)
+               ourpar.setDefaultLayout(dc);
+       else
+               ourpar.setPlainLayout(dc);
 }
 
 
@@ -179,6 +185,13 @@ void InsetText::metrics(MetricsInfo & mi, Dimension & dim) const
        // Hand font through to contained lyxtext:
        tm.font_.fontInfo() = mi.base.font;
        mi.base.textwidth -= 2 * TEXT_TO_INSET_OFFSET;
+
+       // This can happen when a layout has a left and right margin,
+       // and the view is made very narrow. We can't do better than 
+       // to draw it partly out of view (bug 5890).
+       if (mi.base.textwidth < 1)
+               mi.base.textwidth = 1;
+
        if (hasFixedWidth())
                tm.metrics(mi, dim, mi.base.textwidth);
        else
@@ -251,7 +264,16 @@ void InsetText::doDispatch(Cursor & cur, FuncRequest & cmd)
 {
        LYXERR(Debug::ACTION, "InsetText::doDispatch()"
                << " [ cmd.action = " << cmd.action << ']');
-       text_.dispatch(cur, cmd);
+
+       // Dispatch only to text_ if the cursor is inside
+       // the text_. It is not for context menus (bug 5797).
+       if (cur.text() == &text_)
+               text_.dispatch(cur, cmd);
+       else
+               cur.undispatched();
+       
+       if (!cur.result().dispatched())
+               Inset::doDispatch(cur, cmd);
 }
 
 
@@ -273,9 +295,13 @@ bool InsetText::getStatus(Cursor & cur, FuncRequest const & cmd,
        default:
                // Dispatch only to text_ if the cursor is inside
                // the text_. It is not for context menus (bug 5797).
+               bool ret = false;
                if (cur.text() == &text_)
-                       return text_.getStatus(cur, cmd, status);
-               return false;
+                       ret = text_.getStatus(cur, cmd, status);
+               
+               if (!ret)
+                       ret = Inset::getStatus(cur, cmd, status);
+               return ret;
        }
 }
 
@@ -290,15 +316,15 @@ void InsetText::setChange(Change const & change)
 }
 
 
-void InsetText::acceptChanges(BufferParams const & bparams)
+void InsetText::acceptChanges()
 {
-       text_.acceptChanges(bparams);
+       text_.acceptChanges(buffer().params());
 }
 
 
-void InsetText::rejectChanges(BufferParams const & bparams)
+void InsetText::rejectChanges()
 {
-       text_.rejectChanges(bparams);
+       text_.rejectChanges(buffer().params());
 }
 
 
@@ -343,6 +369,13 @@ int InsetText::docbook(odocstream & os, OutputParams const & runparams) const
 }
 
 
+docstring InsetText::xhtml(odocstream & os, OutputParams const & runparams) const
+{
+       xhtmlParagraphs(paragraphs(), buffer(), os, runparams);
+       return docstring();
+}
+
+
 void InsetText::validate(LaTeXFeatures & features) const
 {
        for_each(paragraphs().begin(), paragraphs().end(),
@@ -463,9 +496,9 @@ void InsetText::updateLabels(ParIterator const & it)
        ParIterator it2 = it;
        it2.forwardPos();
        LASSERT(&it2.inset() == this && it2.pit() == 0, return);
-       if (producesOutput()) {
+       if (producesOutput())
                buffer().updateLabels(it2);
-       else {
+       else {
                DocumentClass const & tclass = buffer().masterBuffer()->params().documentClass();
                Counters const savecnt = tclass.counters();
                buffer().updateLabels(it2);
@@ -515,7 +548,7 @@ void InsetText::addToToc(DocIterator const & cdit)
                                break;
                        }
                }
-               /// now the toc entry for the paragraph
+               // now the toc entry for the paragraph
                int const toclevel = par.layout().toclevel;
                if (toclevel != Layout::NOT_IN_TOC && toclevel >= min_toclevel) {
                        dit.pos() = 0;
@@ -544,7 +577,7 @@ bool InsetText::notifyCursorLeaves(Cursor const & old, Cursor & cur)
        LASSERT(&insetCur.inset() == this, /**/);
        
        // update the old paragraph's words
-       insetCur.paragraph().updateWords(insetCur.top());
+       insetCur.paragraph().updateWords();
        
        return Inset::notifyCursorLeaves(old, cur);
 }
@@ -619,4 +652,48 @@ docstring InsetText::contextMenu(BufferView const &, int, int) const
 }
 
 
+InsetCaption const * InsetText::getCaptionInset() const
+{
+       ParagraphList::const_iterator pit = paragraphs().begin();
+       for (; pit != paragraphs().end(); ++pit) {
+               InsetList::const_iterator it = pit->insetList().begin();
+               for (; it != pit->insetList().end(); ++it) {
+                       Inset & inset = *it->inset;
+                       if (inset.lyxCode() == CAPTION_CODE) {
+                               InsetCaption const * ins =
+                                       static_cast<InsetCaption const *>(it->inset);
+                               return ins;
+                       }
+               }
+       }
+       return 0;
+}
+
+
+docstring InsetText::getCaptionText(OutputParams const & runparams) const
+{
+       InsetCaption const * ins = getCaptionInset();
+       if (ins == 0)
+               return docstring();
+
+       odocstringstream ods;
+       ins->getCaptionAsPlaintext(ods, runparams);
+       return ods.str();
+}
+
+
+docstring InsetText::getCaptionHTML(OutputParams const & runparams) const
+{
+       InsetCaption const * ins = getCaptionInset();
+       if (ins == 0)
+               return docstring();
+
+       odocstringstream ods;
+       docstring def = ins->getCaptionAsHTML(ods, runparams);
+       if (!def.empty())
+               ods << def << '\n';
+       return ods.str();
+}
+
+
 } // namespace lyx