]> git.lyx.org Git - lyx.git/blobdiff - src/text2.C
Compile fix following this weekend's commits.
[lyx.git] / src / text2.C
index 4ddfcffa2c8338d78cc66421514e8675b604b019..3867ffa8c03ca61e44967fab0623795215177f0b 100644 (file)
@@ -17,7 +17,7 @@
 #include "lyxtext.h"
 #include "LString.h"
 #include "paragraph.h"
-#include "layout.h"
+#include "lyxtextclasslist.h"
 #include "LyXView.h"
 #include "undo_funcs.h"
 #include "buffer.h"
@@ -862,9 +862,10 @@ void LyXText::redoParagraphs(BufferView * bview, LyXCursor const & cur,
 
        if (!tmprow->previous()) {
                // a trick/hack for UNDO
-               // Can somebody please tell me _why_ this solves
-               // anything. (Lgb)
-               first_phys_par = firstParagraph();
+               // This is needed because in an UNDO/REDO we could have changed
+               // the ownerParagrah() so the paragraph inside the row is NOT
+               // my really first par anymore. Got it Lars ;) (Jug 20011206)
+               first_phys_par = ownerParagraph();
        } else {
                first_phys_par = tmprow->par();
                while (tmprow->previous()
@@ -886,7 +887,7 @@ void LyXText::redoParagraphs(BufferView * bview, LyXCursor const & cur,
                tmppar = tmprow->next()->par();
        else
                tmppar = 0;
-       while (tmppar != endpar) {
+       while (tmprow->next() && tmppar != endpar) {
                removeRow(tmprow->next());
                if (tmprow->next()) {
                        tmppar = tmprow->next()->par();
@@ -1012,7 +1013,7 @@ void LyXText::setSelection(BufferView * bview)
 
 
 string const LyXText::selectionAsString(Buffer const * buffer,
-                                       bool label) const
+                                        bool label) const
 {
        if (!selection.set()) return string();
        string result;
@@ -1683,8 +1684,8 @@ void LyXText::insertInset(BufferView * bview, Inset * inset)
 {
        if (!cursor.par()->insetAllowed(inset->lyxCode()))
                return;
-       setUndo(bview, Undo::INSERT,
-               cursor.par(), cursor.par()->next());
+       // I don't know if this is necessary here (Jug 20020102)
+       setUndo(bview, Undo::INSERT, cursor.par(), cursor.par()->next());
        cursor.par()->insertInset(cursor.pos(), inset);
        // Just to rebreak and refresh correctly.
        // The character will not be inserted a second time
@@ -1795,14 +1796,7 @@ void LyXText::cutSelection(BufferView * bview, bool doclear, bool realcut)
 
 void LyXText::copySelection(BufferView * bview)
 {
-       // Stuff what we got on the clipboard. Even if there is no selection.
-
-       // There is a problem with having the stuffing here in that the
-       // larger the selection the slower LyX will get. This can be
-       // solved by running the line below only when the selection has
-       // finished. The solution used currently just works, to make it
-       // faster we need to be more clever and probably also have more
-       // calls to stuffClipboard. (Lgb)
+       // stuff the selection onto the X clipboard, from an explicit copy request
        bview->stuffClipboard(selectionAsString(bview->buffer(), true));
 
        // this doesnt make sense, if there is no selection
@@ -1851,13 +1845,6 @@ void LyXText::pasteSelection(BufferView * bview)
 }
 
 
-// returns a pointer to the very first Paragraph
-Paragraph * LyXText::firstParagraph() const
-{
-       return ownerParagraph();
-}
-
-
 // sets the selection over the number of characters of string, no check!!
 void LyXText::setSelectionOverString(BufferView * bview, string const & str)
 {
@@ -2075,7 +2062,7 @@ bool LyXText::updateInset(BufferView * bview, Inset * inset)
   
        // check every paragraph
   
-       Paragraph * par = firstParagraph();
+       Paragraph * par = ownerParagraph();
        do {
                pos = par->getPositionOfInset(inset);
                if (pos != -1) {
@@ -2089,19 +2076,22 @@ bool LyXText::updateInset(BufferView * bview, Inset * inset)
 }
 
 
-void LyXText::setCursor(BufferView * bview, Paragraph * par,
+bool LyXText::setCursor(BufferView * bview, Paragraph * par,
                         pos_type pos, 
                         bool setfont, bool boundary) const
 {
        LyXCursor old_cursor = cursor;
        setCursorIntern(bview, par, pos, setfont, boundary);
-       deleteEmptyParagraphMechanism(bview, old_cursor);
+       return deleteEmptyParagraphMechanism(bview, old_cursor);
 }
 
 
-void LyXText::setCursor(BufferView *bview, LyXCursor & cur, Paragraph * par,
+void LyXText::setCursor(BufferView * bview, LyXCursor & cur, Paragraph * par,
                        pos_type pos, bool boundary) const
 {
+       lyx::Assert(par);
+       lyx::Assert(bview);
+       
        cur.par(par);
        cur.pos(pos);
        cur.boundary(boundary);
@@ -2120,15 +2110,19 @@ void LyXText::setCursor(BufferView *bview, LyXCursor & cur, Paragraph * par,
        float fill_hfill;
        float fill_label_hfill;
        prepareToPrint(bview, row, x, fill_separator, fill_hfill,
-                      fill_label_hfill);
+                      fill_label_hfill);
        pos_type cursor_vpos = 0;
        pos_type last = rowLastPrintable(row);
 
-       if (pos > last + 1)   // This shouldn't happen.
+       if (pos > last + 1) {
+               // This shouldn't happen.
                pos = last + 1;
-       else if (pos < row->pos())
+               cur.pos(pos);
+       } else if (pos < row->pos()) {
                pos = row->pos();
-
+               cur.pos(pos);
+       }
+       
        if (last < row->pos())
                 cursor_vpos = row->pos();
        else if (pos > last && !boundary)
@@ -2185,8 +2179,7 @@ void LyXText::setCursor(BufferView *bview, LyXCursor & cur, Paragraph * par,
 
 
 void LyXText::setCursorIntern(BufferView * bview, Paragraph * par,
-                             pos_type pos,
-                             bool setfont, bool boundary) const
+                              pos_type pos, bool setfont, bool boundary) const
 {
        InsetText * it = static_cast<InsetText *>(par->inInset());
        if (it) {
@@ -2205,8 +2198,7 @@ void LyXText::setCursorIntern(BufferView * bview, Paragraph * par,
                        // I moved the lyxerr stuff in here so we can see if
                        // this is actually really needed and where!
                        // (Jug)
-                       it->getLyXText(bview)->setCursorIntern(bview, par, pos, setfont,
-                                                              boundary);
+                       // it->getLyXText(bview)->setCursorIntern(bview, par, pos, setfont, boundary);
                        return;
                }
        }
@@ -2367,21 +2359,19 @@ void LyXText::fixCursorAfterDelete(BufferView * bview,
 }
 
 
-void LyXText::deleteEmptyParagraphMechanism(BufferView * bview,
+bool LyXText::deleteEmptyParagraphMechanism(BufferView * bview,
                                            LyXCursor const & old_cursor) const
 {
        // Would be wrong to delete anything if we have a selection.
-       if (selection.set()) return;
+       if (selection.set()) return false;
 
        // We allow all kinds of "mumbo-jumbo" when freespacing.
        if (textclasslist.Style(bview->buffer()->params.textclass,
                                old_cursor.par()->getLayout()).free_spacing
            || old_cursor.par()->isFreeSpacing())
        {
-               return;
+               return false;
        }
-
-       bool deleted = false;
        
        /* Ok I'll put some comments here about what is missing.
           I have fixed BackSpace (and thus Delete) to not delete
@@ -2436,23 +2426,27 @@ void LyXText::deleteEmptyParagraphMechanism(BufferView * bview,
                        fixCursorAfterDelete(bview, toggle_cursor, old_cursor);
                        fixCursorAfterDelete(bview, toggle_end_cursor,
                                             old_cursor);
-                       return;
+                       return false;
                }
        }
 
        // don't delete anything if this is the ONLY paragraph!
        if (!old_cursor.par()->next() && !old_cursor.par()->previous())
-               return;
+               return false;
        
        // Do not delete empty paragraphs with keepempty set.
        if ((textclasslist.Style(bview->buffer()->params.textclass,
                                 old_cursor.par()->getLayout())).keepempty)
-               return;
+               return false;
 
        // only do our magic if we changed paragraph
        if (old_cursor.par() == cursor.par()) 
-               return;
+               return false;
        
+       // record if we have deleted a paragraph
+       // we can't possibly have deleted a paragraph before this point
+       bool deleted = false;
+
        if ((old_cursor.par()->size() == 0
             || (old_cursor.par()->size() == 1
                 && old_cursor.par()->isLineSeparator(0)))) {
@@ -2482,7 +2476,7 @@ void LyXText::deleteEmptyParagraphMechanism(BufferView * bview,
                        if (ownerParagraph() == old_cursor.par()) {
                                ownerParagraph(ownerParagraph()->next());
                        }
-                               // delete old par
+                       // delete old par
                        delete old_cursor.par();
                                        
                        /* Breakagain the next par. Needed because of
@@ -2532,7 +2526,7 @@ void LyXText::deleteEmptyParagraphMechanism(BufferView * bview,
                setCursorIntern(bview, cursor.par(), cursor.pos());
 
                if (selection.cursor.par()  == old_cursor.par()
-                   && selection.cursor.pos() == selection.cursor.pos()) {
+                   && selection.cursor.pos() == old_cursor.pos()) {
                        // correct selection
                        selection.cursor = cursor;
                }
@@ -2546,6 +2540,7 @@ void LyXText::deleteEmptyParagraphMechanism(BufferView * bview,
                        selection.cursor = cursor;
                }
        }
+       return deleted;
 }
 
 
@@ -2555,7 +2550,7 @@ void LyXText::toggleAppendix(BufferView * bview)
        bool start = !par->params().startOfAppendix();
 
        // ensure that we have only one start_of_appendix in this document
-       Paragraph * tmp = firstParagraph();
+       Paragraph * tmp = ownerParagraph();
        for (; tmp; tmp = tmp->next()) {
                tmp->params().startOfAppendix(false);
        }
@@ -2596,11 +2591,7 @@ void LyXText::ownerParagraph(int id, Paragraph * p) const
        if (op && op->inInset()) {
                static_cast<InsetText *>(op->inInset())->paragraph(p);
        } else {
-               if (inset_owner) {
-                       inset_owner->paragraph(p);
-               } else {
-                       bv_owner->buffer()->paragraph = p;
-               }
+               ownerParagraph(p);
        }
 }