]> git.lyx.org Git - lyx.git/blobdiff - src/insets/insettext.C
* BufferParams:
[lyx.git] / src / insets / insettext.C
index 2330b999e8b7836500131f9103ecea8c120acd45..9b7426c643e8580853a835d74cae7bca4953c623 100644 (file)
@@ -31,6 +31,7 @@
 #include "lyxrc.h"
 #include "lyxtext.h"
 #include "metricsinfo.h"
+#include "outputparams.h"
 #include "output_docbook.h"
 #include "output_latex.h"
 #include "output_plaintext.h"
@@ -212,7 +213,7 @@ void InsetText::drawSelection(PainterInfo & pi, int x, int y) const
        int const h = a + tm.descent() + border_;
        pi.pain.fillRectangle(x, y - a, (wide() ? tm.maxWidth() : w), h,
                backgroundColor());
-       text_.drawSelection(pi, x, y);
+       text_.drawSelection(pi, x + border_, y);
 }
 
 
@@ -279,74 +280,18 @@ void InsetText::setChange(Change const & change)
 
 void InsetText::acceptChanges(BufferParams const & bparams)
 {
-       ParagraphList & pars = paragraphs();
-       pit_type const parsize = (pit_type) pars.size();
-
-       // first, accept changes within each individual paragraph (do not consider end-of-par)
-       for (pit_type pit = 0; pit < parsize; ++pit) {
-               if (pars[pit].size() != 0)   // prevent assertion failure 
-                       pars[pit].acceptChanges(bparams, 0, pars[pit].size());
-       }
-
-       // next, accept imaginary end-of-par characters
-       for (pit_type pit = 0; pit < parsize; ++pit) {
-               pos_type pos = pars[pit].size();
-
-               if (pars[pit].isInserted(pos)) {
-                       pars[pit].setChange(pos, Change(Change::UNCHANGED));
-               } else if (pars[pit].isDeleted(pos)) {
-                       if (pit == pars.size() - 1) {
-                               // we cannot remove a par break at the end of the last paragraph;
-                               // instead, we mark it unchanged
-                               pars[pit].setChange(pos, Change(Change::UNCHANGED));
-                       } else {
-                               mergeParagraph(bparams, pars, pit);
-                               --pit;
-                       }
-               }
-       }
-
-       // FIXME: finally, invoke the DEPM
+       text_.acceptChanges(bparams);
 }
 
 
 void InsetText::rejectChanges(BufferParams const & bparams)
 {
-       ParagraphList & pars = paragraphs();
-       pit_type const parsize = (pit_type) pars.size();
-
-       // first, reject changes within each individual paragraph (do not consider end-of-par)
-       
-       for (pit_type pit = 0; pit < parsize; ++pit) {
-               if (pars[pit].size() != 0)   // prevent assertion failure
-                       pars[pit].rejectChanges(bparams, 0, pars[pit].size());
-       }
-
-       // next, reject imaginary end-of-par characters
-       for (pit_type pit = 0; pit < parsize; ++pit) {
-               pos_type pos = pars[pit].size();
-
-               if (pars[pit].isDeleted(pos)) {
-                       pars[pit].setChange(pos, Change(Change::UNCHANGED));
-               } else if (pars[pit].isInserted(pos)) {
-                       if (pit == pars.size() - 1) {
-                               // we mark the par break at the end of the last paragraph unchanged
-                               pars[pit].setChange(pos, Change(Change::UNCHANGED));
-                       } else {
-                               mergeParagraph(bparams, pars, pit);
-                               --pit;
-                       }
-               }
-       }
-
-       // FIXME: finally, invoke the DEPM
+       text_.rejectChanges(bparams);
 }
 
 
 int InsetText::latex(Buffer const & buf, odocstream & os,
-                    OutputParams const & runparams) const
+                     OutputParams const & runparams) const
 {
        TexRow texrow;
        latexParagraphs(buf, paragraphs(), os, texrow, runparams);
@@ -355,25 +300,34 @@ int InsetText::latex(Buffer const & buf, odocstream & os,
 
 
 int InsetText::plaintext(Buffer const & buf, odocstream & os,
-                    OutputParams const & runparams) const
+                         OutputParams const & runparams) const
 {
        ParagraphList::const_iterator beg = paragraphs().begin();
        ParagraphList::const_iterator end = paragraphs().end();
        ParagraphList::const_iterator it = beg;
        bool ref_printed = false;
-       odocstringstream oss;
-       for (; it != end; ++it)
+       int len = 0;
+       for (; it != end; ++it) {
+               if (it != beg) {
+                       os << '\n';
+                       if (runparams.linelen > 0)
+                               os << '\n';
+               }
+               odocstringstream oss;
                writePlaintextParagraph(buf, *it, oss, runparams, ref_printed);
+               docstring const str = oss.str();
+               os << str;
+               // FIXME: len is not computed fully correctly; in principle,
+               // we have to count the characters after the last '\n'
+               len = str.size();
+       }
 
-       docstring const str = oss.str();
-       os << str;
-       // Return how many newlines we issued.
-       return int(lyx::count(str.begin(), str.end(), '\n'));
+       return len;
 }
 
 
 int InsetText::docbook(Buffer const & buf, odocstream & os,
-                      OutputParams const & runparams) const
+                       OutputParams const & runparams) const
 {
        docbookParagraphs(paragraphs(), buf, os, runparams);
        return 0;