]> git.lyx.org Git - features.git/blobdiff - src/insets/insettext.C
add ParagraphList::erase, make mergeParagraph take a Buffer* arg, adjust other funcs...
[features.git] / src / insets / insettext.C
index f5ab4e26c476beacf16103f863b249258e0536d2..df7a181653685d6001b87f56c5cc975987120191 100644 (file)
@@ -10,9 +10,6 @@
 
 #include <config.h>
 
-#ifdef __GNUG__
-#pragma implementation
-#endif
 
 #include "insettext.h"
 
@@ -39,6 +36,7 @@
 #include "WordLangTuple.h"
 #include "paragraph_funcs.h"
 #include "sgml.h"
+#include "rowpainter.h"
 
 #include "frontends/Alert.h"
 #include "frontends/Dialogs.h"
@@ -107,6 +105,7 @@ void InsetText::saveLyXTextState(LyXText * t) const
        }
 }
 
+
 void InsetText::restoreLyXTextState(BufferView * bv, LyXText * t) const
 {
        if (sstate.lpar) {
@@ -146,6 +145,8 @@ InsetText::InsetText(BufferParams const & bp)
 {
        paragraphs.set(new Paragraph);
        paragraphs.begin()->layout(bp.getLyXTextClass().defaultLayout());
+       if (bp.tracking_changes)
+               paragraphs.begin()->trackChanges();
        init();
 }
 
@@ -208,8 +209,18 @@ InsetText::~InsetText()
 }
 
 
-void InsetText::clear()
+void InsetText::clear(bool just_mark_erased)
 {
+       if (just_mark_erased) {
+               ParagraphList::iterator it = paragraphs.begin();
+               ParagraphList::iterator end = paragraphs.end();
+               for (; it != end; ++it) {
+                       it->markErased();
+               }
+               need_update = FULL;
+               return;
+       }
+
        // This is a gross hack...
        LyXLayout_ptr old_layout = paragraphs.begin()->layout();
 
@@ -255,7 +266,10 @@ void InsetText::read(Buffer const * buf, LyXLex & lex)
        Paragraph::depth_type depth = 0;
        LyXFont font(LyXFont::ALL_INHERIT);
 
-       clear();
+       clear(false);
+
+       if (buf->params.tracking_changes)
+               paragraphs.begin()->trackChanges();
 
        while (lex.isOK()) {
                lex.nextToken();
@@ -455,8 +469,10 @@ void InsetText::draw(BufferView * bv, LyXFont const & f,
                int yf = y_offset + first;
                y = 0;
                while ((row != 0) && (yf < ph)) {
-                       lt->getVisibleRow(bv, y + y_offset + first, int(x),
-                                         row, y + lt->first_y, cleared);
+                       Row * prev = row->previous();
+                       RowPainter rp(*bv, *lt, *row);
+                       if (rp.paint(y + y_offset + first, int(x), y + lt->first_y, cleared))
+                               lt->markChangeInDraw(bv, row, prev);
                        if (bv->text->status() == LyXText::CHANGED_IN_DRAW) {
                                lt->need_break_row = row;
                                lt->fullRebreak(bv);
@@ -1124,7 +1140,9 @@ bool InsetText::lfunMouseRelease(FuncRequest const & cmd)
                        inset_y = ciy(bv) + drawTextYOffset;
                        cmd1.x = cmd.x - inset_x;
                        cmd1.y = cmd.x - inset_y;
-                       ret = inset->localDispatch(cmd1);
+// note that we should do ret = inset->localDispatch(cmd1)
+// and fix this instead (Alfredo);
+                       ret = true;
                        inset->edit(bv, cmd1.x, cmd1.y, cmd.button());
                }
                updateLocal(bv, CURSOR_PAR, false);
@@ -1221,20 +1239,10 @@ Inset::RESULT InsetText::localDispatch(FuncRequest const & ev)
                                }
                                break;
                        case FINISHED_DOWN:
-                       {
-                               LyXText *lt = getLyXText(bv);
-                               if (lt->cursor.irow()->next()) {
-                                       lt->setCursorFromCoordinates(
-                                               bv, lt->cursor.ix() + inset_x,
-                                               lt->cursor.iy() -
-                                               lt->cursor.irow()->baseline() +
-                                               lt->cursor.irow()->height() + 1);
-                                       lt->cursor.x_fix(lt->cursor.x());
+                               if ((result = moveDown(bv)) >= FINISHED) {
                                        updateLocal(bv, CURSOR, false);
-                               } else {
                                        bv->unlockInset(this);
                                }
-                       }
                                break;
                        default:
                                result = DISPATCHED;
@@ -1416,7 +1424,7 @@ Inset::RESULT InsetText::localDispatch(FuncRequest const & ev)
                if (!autoBreakRows) {
 
                        if (CutAndPaste::nrOfParagraphs() > 1) {
-                               Alert::alert(_("Impossible operation"),
+                               Alert::alert(_("Impossible operation!"),
                                                   _("Cannot include more than one paragraph!"),
                                                   _("Sorry."));
                                break;
@@ -1587,7 +1595,7 @@ int InsetText::latex(Buffer const * buf, ostream & os,
                     bool moving_arg, bool) const
 {
        TexRow texrow;
-       buf->latexParagraphs(os, &*(paragraphs.begin()), 0,
+       buf->latexParagraphs(os, paragraphs.begin(), paragraphs.end(),
                             texrow, moving_arg);
        return texrow.rows();
 }
@@ -1664,7 +1672,7 @@ int InsetText::docbook(Buffer const * buf, ostream & os, bool mixcont) const
                        break;
 
                case LATEX_COMMAND:
-                       buf->sgmlError(p, 0,  _("Error : LatexType Command not allowed here.\n"));
+                       buf->sgmlError(p, 0,  _("Error: LatexType Command not allowed here.\n"));
                        return -1;
                        break;
 
@@ -1769,15 +1777,6 @@ void InsetText::validate(LaTeXFeatures & features) const
 }
 
 
-int InsetText::beginningOfMainBody(Paragraph * p) const
-{
-       if (p->layout()->labeltype != LABEL_MANUAL)
-               return 0;
-       else
-               return p->beginningOfMainBody();
-}
-
-
 void InsetText::getCursorPos(BufferView * bv, int & x, int & y) const
 {
        if (the_locking_inset) {
@@ -2137,9 +2136,24 @@ void InsetText::setParagraphData(Paragraph * p, bool same_id)
 }
 
 
+void InsetText::markNew(bool track_changes)
+{
+       ParagraphList::iterator pit = paragraphs.begin();
+       ParagraphList::iterator pend = paragraphs.end();
+       for (; pit != pend; ++pit) {
+               if (track_changes) {
+                       pit->trackChanges();
+               } else {
+                       // no-op when not tracking
+                       pit->cleanChanges();
+               }
+       }
+}
+
+
 void InsetText::setText(string const & data, LyXFont const & font)
 {
-       clear();
+       clear(false);
        for (unsigned int i = 0; i < data.length(); ++i)
                paragraphs.begin()->insertChar(i, data[i], font);
        reinitLyXText();
@@ -2505,23 +2519,6 @@ void InsetText::clearInset(BufferView * bv, int baseline, bool & cleared) const
 }
 
 
-Paragraph * InsetText::getParFromID(int id) const
-{
-       ParagraphList::iterator it = paragraphs.begin();
-       ParagraphList::iterator end = paragraphs.end();
-       for (; it != end; ++it) {
-               if (it->id() == id) {
-                       return &*(it);
-               }
-               Paragraph * tmp2 = it->getParFromID(id);
-               if (tmp2 != 0) {
-                       return tmp2;
-               }
-       }
-       return 0;
-}
-
-
 Paragraph * InsetText::firstParagraph() const
 {
        Paragraph * result;
@@ -2540,9 +2537,9 @@ Paragraph * InsetText::getFirstParagraph(int i) const
 
 LyXCursor const & InsetText::cursor(BufferView * bv) const
 {
-               if (the_locking_inset)
-                               return the_locking_inset->cursor(bv);
-               return getLyXText(bv)->cursor;
+       if (the_locking_inset)
+               return the_locking_inset->cursor(bv);
+       return getLyXText(bv)->cursor;
 }
 
 
@@ -2667,6 +2664,36 @@ void InsetText::toggleSelection(BufferView * bv, bool kill_selection)
 }
 
 
+bool InsetText::nextChange(BufferView * bv, lyx::pos_type & length)
+{
+       bool clear = false;
+       if (!lt) {
+               lt = getLyXText(bv);
+               clear = true;
+       }
+       if (the_locking_inset) {
+               if (the_locking_inset->nextChange(bv, length))
+                       return true;
+               lt->cursorRight(bv, true);
+       }
+       lyxfind::SearchResult result =
+               lyxfind::findNextChange(bv, lt, length);
+
+       if (result == lyxfind::SR_FOUND) {
+               LyXCursor cur = lt->cursor;
+               bv->unlockInset(bv->theLockingInset());
+               if (bv->lockInset(this))
+                       locked = true;
+               lt->cursor = cur;
+               lt->setSelectionRange(bv, length);
+               updateLocal(bv, SELECTION, false);
+       }
+       if (clear)
+               lt = 0;
+       return result != lyxfind::SR_NOT_FOUND;
+}
+
+
 bool InsetText::searchForward(BufferView * bv, string const & str,
                              bool cs, bool mw)
 {
@@ -2689,7 +2716,7 @@ bool InsetText::searchForward(BufferView * bv, string const & str,
                if (bv->lockInset(this))
                        locked = true;
                lt->cursor = cur;
-               lt->setSelectionOverString(bv, str);
+               lt->setSelectionRange(bv, str.length());
                updateLocal(bv, SELECTION, false);
        }
        if (clear)
@@ -2724,7 +2751,7 @@ bool InsetText::searchBackward(BufferView * bv, string const & str,
                if (bv->lockInset(this))
                        locked = true;
                lt->cursor = cur;
-               lt->setSelectionOverString(bv, str);
+               lt->setSelectionRange(bv, str.length());
                updateLocal(bv, SELECTION, false);
        }
        if (clear)
@@ -2743,7 +2770,6 @@ bool InsetText::checkInsertChar(LyXFont & font)
 
 void InsetText::collapseParagraphs(BufferView * bv) const
 {
-       BufferParams const & bparams = bv->buffer()->params;
        LyXText * llt = getLyXText(bv);
 
        while (paragraphs.begin()->next()) {
@@ -2764,7 +2790,7 @@ void InsetText::collapseParagraphs(BufferView * bv) const
                                        llt->selection.end.pos() + paragraphs.begin()->size());
                        }
                }
-               mergeParagraph(bparams, &*paragraphs.begin());
+               mergeParagraph(bv->buffer(), paragraphs.begin());
        }
        reinitLyXText();
 }
@@ -2778,18 +2804,23 @@ void InsetText::getDrawFont(LyXFont & font) const
 }
 
 
-void InsetText::appendParagraphs(BufferParams const & bparams,
+void InsetText::appendParagraphs(Buffer * buffer,
                                 Paragraph * newpar)
 {
+       BufferParams const & bparams = buffer->params;
        Paragraph * buf;
        Paragraph * tmpbuf = newpar;
        Paragraph * lastbuffer = buf = new Paragraph(*tmpbuf, false);
+       if (bparams.tracking_changes)
+               buf->cleanChanges();
 
        while (tmpbuf->next()) {
                tmpbuf = tmpbuf->next();
                lastbuffer->next(new Paragraph(*tmpbuf, false));
                lastbuffer->next()->previous(lastbuffer);
                lastbuffer = lastbuffer->next();
+               if (bparams.tracking_changes)
+                       lastbuffer->cleanChanges();
        }
        lastbuffer = &*(paragraphs.begin());
        while (lastbuffer->next())
@@ -2806,7 +2837,7 @@ void InsetText::appendParagraphs(BufferParams const & bparams,
        // paste it!
        lastbuffer->next(buf);
        buf->previous(lastbuffer);
-       mergeParagraph(bparams, lastbuffer);
+       mergeParagraph(buffer, lastbuffer);
 
        reinitLyXText();
 }