]> git.lyx.org Git - features.git/commitdiff
parlist-8-b
authorLars Gullik Bjønnes <larsbj@gullik.org>
Sun, 13 Apr 2003 01:04:04 +0000 (01:04 +0000)
committerLars Gullik Bjønnes <larsbj@gullik.org>
Sun, 13 Apr 2003 01:04:04 +0000 (01:04 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@6786 a592a061-630c-0410-9148-cb99ea01b6c8

src/ChangeLog
src/bufferview_funcs.C
src/lyxtext.h
src/text.C
src/text2.C

index 869b8a3d3720a751b5795a6e4dfaf1e5b880de3b..2cb3673e565a703faa499ef3c1d985a067403d1c 100644 (file)
@@ -1,3 +1,32 @@
+2003-04-13  Lars Gullik Bjønnes  <larsbj@gullik.net>
+
+       * text2.C (cursorTop): simplify implementation
+       (cursorBottom): ditto
+       (setParagraph): use ParagraphList::iterator
+       (setCurrentFont): adjust
+       (getColumnNearX): adjust
+       (cursorRight): adjust
+       (cursorLeft): remove usage of Paragraph::previous
+       (cursorUpParagraph): ditto
+       (deleteEmptyParagraphMechanism): slight cleanup
+
+       * text.C (isBoundary): take a Paragraph const & instead of a
+       pointer as arg.
+       (addressBreakPoint): ditto
+       (leftMargin): remove usage of Paragraph::previous.
+       (setHeightOfRow): ditto
+       (cursorLeftOneWord): ditto
+       (selectNextWordToSpellcheck): ditto
+       (Delete): ditto
+       (backspace): ditto
+       (breakParagraph): remove one usage of Paragraph::next
+       (redoParagraph): ditto
+       (acceptChange): ditto
+       (insertChar): adjust
+       (rowBreakPoint): adjust
+
+       * bufferview_funcs.C (toggleAndShow): adjust
+
 2003-04-11  Alfredo Braunstein  <abraunst@libero.it>
 
        * lyxrow.[Ch]: add a cached y position to a Row and Row::y()
index 3edb7bbb11a9fc79f2cb96248ee65a1db7236b71..c7f640a03a8e38dd2c5d7e2ab5517a07ddf43d09 100644 (file)
@@ -400,7 +400,7 @@ void toggleAndShow(BufferView * bv, LyXFont const & font, bool toggleall)
                LyXCursor & cursor = text->cursor;
                text->computeBidiTables(bv->buffer(), cursor.row());
                if (cursor.boundary() !=
-                   text->isBoundary(bv->buffer(), &*cursor.par(), cursor.pos(),
+                   text->isBoundary(bv->buffer(), *cursor.par(), cursor.pos(),
                                     text->real_current_font))
                        text->setCursor(cursor.par(), cursor.pos(),
                                        false, !cursor.boundary());
index 2a1ec358436683b4a2c81bcae3d8df9600dad8b9..adf0ce3db21e0841dc739a8fd02a73c96c2f725f 100644 (file)
@@ -353,10 +353,10 @@ public:
        void setCurrentFont();
 
        ///
-       bool isBoundary(Buffer const *, Paragraph * par,
+       bool isBoundary(Buffer const *, Paragraph const & par,
                        lyx::pos_type pos) const;
        ///
-       bool isBoundary(Buffer const *, Paragraph * par,
+       bool isBoundary(Buffer const *, Paragraph const & par,
                         lyx::pos_type pos,
                         LyXFont const & font) const;
 
index ff1b144c2617774ec41e3c49cc950aaa3234b0fe..821b17d010c2c3ac88dc08e85a4318a967fd28bb 100644 (file)
@@ -471,7 +471,7 @@ void LyXText::computeBidiTables(Buffer const * buf,
 
 
 // This method requires a previous call to ComputeBidiTables()
-bool LyXText::isBoundary(Buffer const * buf, Paragraph * par,
+bool LyXText::isBoundary(Buffer const * buf, Paragraph const & par,
                         pos_type pos) const
 {
        if (!lyxrc.rtl_support || pos == 0)
@@ -486,12 +486,12 @@ bool LyXText::isBoundary(Buffer const * buf, Paragraph * par,
        bool const rtl = bidi_level(pos - 1) % 2;
        bool const rtl2 = bidi_InRange(pos)
                ? bidi_level(pos) % 2
-               : par->isRightToLeftPar(buf->params);
+               : par.isRightToLeftPar(buf->params);
        return rtl != rtl2;
 }
 
 
-bool LyXText::isBoundary(Buffer const * buf, Paragraph * par,
+bool LyXText::isBoundary(Buffer const * buf, Paragraph const & par,
                         pos_type pos, LyXFont const & font) const
 {
        if (!lyxrc.rtl_support)
@@ -500,7 +500,7 @@ bool LyXText::isBoundary(Buffer const * buf, Paragraph * par,
        bool const rtl = font.isVisibleRightToLeft();
        bool const rtl2 = bidi_InRange(pos)
                ? bidi_level(pos) % 2
-               : par->isRightToLeftPar(buf->params);
+               : par.isRightToLeftPar(buf->params);
        return rtl != rtl2;
 }
 
@@ -531,7 +531,7 @@ int LyXText::leftMargin(Row const & row) const
        if (!row.par()->getDepth()) {
                if (row.par()->layout() == tclass.defaultLayout()) {
                        // find the previous same level paragraph
-                       if (row.par()->previous()) {
+                       if (row.par() != ownerParagraphs().begin()) {
                                Paragraph * newpar = row.par()
                                        ->depthHook(row.par()->getDepth());
                                if (newpar &&
@@ -659,7 +659,7 @@ int LyXText::leftMargin(Row const & row) const
                x += len.inPixels(tw);
        }
 
-       LyXAlignment align; // wrong type
+       LyXAlignment align;
 
        if (row.par()->params().align() == LYX_ALIGN_LAYOUT)
                align = layout->align;
@@ -737,14 +737,14 @@ int LyXText::labelEnd(Row const & row) const
 namespace {
 
 // this needs special handling - only newlines count as a break point
-pos_type addressBreakPoint(pos_type i, Paragraph * par)
+pos_type addressBreakPoint(pos_type i, Paragraph const & par)
 {
-       for (; i < par->size(); ++i) {
-               if (par->isNewline(i))
+       for (; i < par.size(); ++i) {
+               if (par.isNewline(i))
                        return i;
        }
 
-       return par->size();
+       return par.size();
 }
 
 };
@@ -766,7 +766,7 @@ LyXText::rowBreakPoint(Row const & row) const
        LyXLayout_ptr const & layout = pit->layout();
 
        if (layout->margintype == MARGIN_RIGHT_ADDRESS_BOX)
-               return addressBreakPoint(row.pos(), &*pit);
+               return addressBreakPoint(row.pos(), *pit);
 
        pos_type const pos = row.pos();
        pos_type const body_pos = pit->beginningOfBody();
@@ -1099,12 +1099,12 @@ void LyXText::setHeightOfRow(RowList::iterator rit)
                {
                        if (layout->isParagraph()
                                && firstpit->getDepth() == 0
-                               && firstpit->previous())
+                               && firstpit != ownerParagraphs().begin())
                        {
                                maxasc += bv()->buffer()->params.getDefSkip().inPixels(*bv());
-                       } else if (firstpit->previous() &&
-                                  firstpit->previous()->layout()->isParagraph() &&
-                                  firstpit->previous()->getDepth() == 0)
+                       } else if (firstpit != ownerParagraphs().begin() &&
+                                  boost::prior(firstpit)->layout()->isParagraph() &&
+                                  boost::prior(firstpit)->getDepth() == 0)
                        {
                                // is it right to use defskip here too? (AS)
                                maxasc += bv()->buffer()->params.getDefSkip().inPixels(*bv());
@@ -1112,7 +1112,7 @@ void LyXText::setHeightOfRow(RowList::iterator rit)
                }
 
                // the top margin
-               if (!rit->par()->previous() && !isInInset())
+               if (rit->par() == ownerParagraphs().begin() && !isInInset())
                        maxasc += PAPER_MARGIN;
 
                // add the vertical spaces, that the user added
@@ -1207,13 +1207,13 @@ void LyXText::setHeightOfRow(RowList::iterator rit)
                        if (prev)  {
                                maxasc += int(prev->layout()->parsep * defaultRowHeight());
                        } else {
-                               if (firstpit->previous() &&
-                                       firstpit->previous()->getDepth() == 0 &&
-                                       firstpit->previous()->layout() !=
+                               if (firstpit != ownerParagraphs().begin() &&
+                                   boost::prior(firstpit)->getDepth() == 0 &&
+                                   boost::prior(firstpit)->layout() !=
                                        firstpit->layout())
                                {
                                        // avoid parsep
-                               } else if (firstpit->previous()) {
+                               } else if (firstpit != ownerParagraphs().begin()) {
                                        maxasc += int(layout->parsep * defaultRowHeight());
                                }
                        }
@@ -1532,7 +1532,7 @@ void LyXText::breakParagraph(ParagraphList & paragraphs, char keep_layout)
        // This check is necessary. Otherwise the new empty paragraph will
        // be deleted automatically. And it is more friendly for the user!
        if (cursor.pos() || isempty)
-               setCursor(cursor.par()->next(), 0);
+               setCursor(boost::next(cursor.par()), 0);
        else
                setCursor(cursor.par(), 0);
 
@@ -1547,7 +1547,7 @@ void LyXText::breakParagraph(ParagraphList & paragraphs, char keep_layout)
 void LyXText::redoParagraph()
 {
        clearSelection();
-       redoParagraphs(cursor, cursor.par()->next());
+       redoParagraphs(cursor, boost::next(cursor.par()));
        setCursorIntern(cursor.par(), cursor.pos());
 }
 
@@ -1757,7 +1757,7 @@ void LyXText::insertChar(char c)
 
                setCursor(cursor.par(), cursor.pos() + 1, false,
                          cursor.boundary());
-               if (isBoundary(bv()->buffer(), &*cursor.par(), cursor.pos())
+               if (isBoundary(bv()->buffer(), *cursor.par(), cursor.pos())
                    != cursor.boundary())
                        setCursor(cursor.par(), cursor.pos(), false,
                          !cursor.boundary());
@@ -2007,8 +2007,8 @@ void LyXText::cursorLeftOneWord(LyXCursor & cur)
                || cur.par()->isHfill(cur.pos() - 1))) {
                cur.pos(cur.pos() - 1);
        } else if (!cur.pos()) {
-               if (cur.par()->previous()) {
-                       cur.par(cur.par()->previous());
+               if (cur.par() != ownerParagraphs().begin()) {
+                       cur.par(boost::prior(cur.par()));
                        cur.pos(cur.par()->size());
                }
        } else {                // Here, cur != 0
@@ -2111,7 +2111,7 @@ void LyXText::acceptChange()
                startc.par()->acceptChange(startc.pos(), endc.pos());
                finishUndo();
                clearSelection();
-               redoParagraphs(startc, startc.par()->next());
+               redoParagraphs(startc, boost::next(startc.par()));
                setCursorIntern(startc.par(), 0);
        }
 #warning handle multi par selection
@@ -2166,7 +2166,7 @@ LyXText::selectNextWordToSpellcheck(float & value)
        // If this is not the very first word, skip rest of
        // current word because we are probably in the middle
        // of a word if there is text here.
-       if (cursor.pos() || cursor.par()->previous()) {
+       if (cursor.pos() || cursor.par() != ownerParagraphs().begin()) {
                while (cursor.pos() < cursor.par()->size()
                       && cursor.par()->isLetter(cursor.pos()))
                        cursor.pos(cursor.pos() + 1);
@@ -2390,8 +2390,9 @@ void LyXText::Delete()
 
        LyXCursor old_cursor = cursor;
        int const old_cur_par_id = old_cursor.par()->id();
-       int const old_cur_par_prev_id = old_cursor.par()->previous() ?
-               old_cursor.par()->previous()->id() : -1;
+       int const old_cur_par_prev_id =
+               (old_cursor.par() != ownerParagraphs().begin() ?
+                boost::prior(old_cursor.par())->id() : -1);
 
        // just move to the right
        cursorRight(bv());
@@ -2402,7 +2403,7 @@ void LyXText::Delete()
        // and that can very well delete the par or par->previous in
        // old_cursor. Will a solution where we compare paragraph id's
        //work better?
-       if ((cursor.par()->previous() ? cursor.par()->previous()->id() : -1)
+       if ((cursor.par() != ownerParagraphs().begin() ? boost::prior(cursor.par())->id() : -1)
            == old_cur_par_prev_id
            && cursor.par()->id() != old_cur_par_id) {
                // delete-empty-paragraph-mechanism has done it
@@ -2448,15 +2449,15 @@ void LyXText::backspace()
                        // left and let the DeleteEmptyParagraphMechanism handle the actual deletion
                        // of the paragraph.
 
-                       if (cursor.par()->previous()) {
-                               Paragraph * tmppar = cursor.par()->previous();
-                               if (cursor.par()->layout() == tmppar->layout()
-                                   && cursor.par()->getAlign() == tmppar->getAlign()) {
+                       if (cursor.par() != ownerParagraphs().begin()) {
+                               ParagraphList::iterator tmppit = boost::prior(cursor.par());
+                               if (cursor.par()->layout() == tmppit->layout()
+                                   && cursor.par()->getAlign() == tmppit->getAlign()) {
                                        // Inherit bottom DTD from the paragraph below.
                                        // (the one we are deleting)
-                                       tmppar->params().lineBottom(cursor.par()->params().lineBottom());
-                                       tmppar->params().spaceBottom(cursor.par()->params().spaceBottom());
-                                       tmppar->params().pagebreakBottom(cursor.par()->params().pagebreakBottom());
+                                       tmppit->params().lineBottom(cursor.par()->params().lineBottom());
+                                       tmppit->params().spaceBottom(cursor.par()->params().spaceBottom());
+                                       tmppit->params().pagebreakBottom(cursor.par()->params().pagebreakBottom());
                                }
 
                                cursorLeft(bv());
@@ -2471,9 +2472,10 @@ void LyXText::backspace()
                        }
                }
 
-               if (cursor.par()->previous()) {
+               if (cursor.par() != ownerParagraphs().begin()) {
                        setUndo(bv(), Undo::DELETE,
-                               cursor.par()->previous(), cursor.par()->next());
+                               &*boost::prior(cursor.par()),
+                               &*boost::next(cursor.par()));
                }
 
                ParagraphList::iterator tmppit = cursor.par();
@@ -2715,7 +2717,7 @@ void LyXText::backspace()
        // current_font = rawtmpfont;
        // real_current_font = realtmpfont;
 
-       if (isBoundary(bv()->buffer(), &*cursor.par(), cursor.pos())
+       if (isBoundary(bv()->buffer(), *cursor.par(), cursor.pos())
            != cursor.boundary())
                setCursor(cursor.par(), cursor.pos(), false,
                          !cursor.boundary());
index f87adbb30c9d5bf0daac2a534bd95743d3f09862..1a801ee63c4ec17498a1ba4fc107546159213ba8 100644 (file)
@@ -889,17 +889,18 @@ void LyXText::cursorEnd()
 
 void LyXText::cursorTop()
 {
-       while (cursor.par()->previous())
-               cursor.par(cursor.par()->previous());
-       setCursor(cursor.par(), 0);
+       setCursor(ownerParagraphs().begin(), 0);
 }
 
 
 void LyXText::cursorBottom()
 {
-       while (cursor.par()->next())
-               cursor.par(cursor.par()->next());
-       setCursor(cursor.par(), cursor.par()->size());
+#warning FIXME
+       // This is how it should be:
+       // ParagraphList::iterator lastpit = boost::prior(ownerParagraphs().end());
+       ParagraphList::iterator lastpit = &ownerParagraphs().back();
+       int pos = lastpit->size();
+       setCursor(lastpit, pos);
 }
 
 
@@ -987,21 +988,22 @@ void LyXText::setParagraph(bool line_top, bool line_bottom,
        }
 
        // make sure that the depth behind the selection are restored, too
-       Paragraph * endpar = selection.end.par()->next();
-       Paragraph * undoendpar = endpar;
-
-       if (endpar && endpar->getDepth()) {
-               while (endpar && endpar->getDepth()) {
-                       endpar = endpar->next();
-                       undoendpar = endpar;
+       ParagraphList::iterator endpit = boost::next(selection.end.par());
+       ParagraphList::iterator undoendpit = endpit;
+
+       if (endpit != ownerParagraphs().end() && endpit->getDepth()) {
+               while (endpit != ownerParagraphs().end() &&
+                      endpit->getDepth()) {
+                       ++endpit;
+                       undoendpit = endpit;
                }
        }
-       else if (endpar) {
+       else if (endpit != ownerParagraphs().end()) {
                // because of parindents etc.
-               endpar = endpar->next();
+               ++endpit;
        }
 
-       setUndo(bv(), Undo::EDIT, &*selection.start.par(), undoendpar);
+       setUndo(bv(), Undo::EDIT, &*selection.start.par(), &*undoendpit);
 
 
        ParagraphList::iterator tmppit = selection.end.par();
@@ -1032,7 +1034,7 @@ void LyXText::setParagraph(bool line_top, bool line_bottom,
                tmppit = boost::prior(cursor.par());
        }
 
-       redoParagraphs(selection.start, endpar);
+       redoParagraphs(selection.start, endpit);
 
        clearSelection();
        setCursor(selection.start.par(), selection.start.pos());
@@ -1858,7 +1860,7 @@ void LyXText::setCurrentFont()
        real_current_font = getFont(bv()->buffer(), cursor.par(), pos);
 
        if (cursor.pos() == cursor.par()->size() &&
-           isBoundary(bv()->buffer(), &*cursor.par(), cursor.pos()) &&
+           isBoundary(bv()->buffer(), *cursor.par(), cursor.pos()) &&
            !cursor.boundary()) {
                Language const * lang =
                        cursor.par()->getParLanguage(bv()->buffer()->params);
@@ -1964,7 +1966,7 @@ LyXText::getColumnNearX(RowList::iterator rit, int & x, bool & boundary) const
                bool const rtl = (bidi_level(c) % 2 == 1);
                if (left_side == rtl) {
                        ++c;
-                       boundary = isBoundary(bv()->buffer(), &*rit->par(), c);
+                       boundary = isBoundary(bv()->buffer(), *rit->par(), c);
                }
        }
 
@@ -2052,11 +2054,11 @@ void LyXText::cursorLeft(bool internal)
                bool boundary = cursor.boundary();
                setCursor(cursor.par(), cursor.pos() - 1, true, false);
                if (!internal && !boundary &&
-                   isBoundary(bv()->buffer(), &*cursor.par(), cursor.pos() + 1))
+                   isBoundary(bv()->buffer(), *cursor.par(), cursor.pos() + 1))
                        setCursor(cursor.par(), cursor.pos() + 1, true, true);
-       } else if (cursor.par()->previous()) { // steps into the above paragraph.
-               Paragraph * par = cursor.par()->previous();
-               setCursor(par, par->size());
+       } else if (cursor.par() != ownerParagraphs().begin()) { // steps into the above paragraph.
+               ParagraphList::iterator pit = boost::prior(cursor.par());
+               setCursor(pit, pit->size());
        }
 }
 
@@ -2072,7 +2074,7 @@ void LyXText::cursorRight(bool internal)
        else if (!at_end) {
                setCursor(cursor.par(), cursor.pos() + 1, true, false);
                if (!internal &&
-                   isBoundary(bv()->buffer(), &*cursor.par(), cursor.pos()))
+                   isBoundary(bv()->buffer(), *cursor.par(), cursor.pos()))
                        setCursor(cursor.par(), cursor.pos(), true, true);
        } else if (cursor.par()->next())
                setCursor(cursor.par()->next(), 0);
@@ -2132,8 +2134,8 @@ void LyXText::cursorUpParagraph()
        if (cursor.pos() > 0) {
                setCursor(cursor.par(), 0);
        }
-       else if (cursor.par()->previous()) {
-               setCursor(cursor.par()->previous(), 0);
+       else if (cursor.par() != ownerParagraphs().begin()) {
+               setCursor(boost::prior(cursor.par()), 0);
        }
 }
 
@@ -2242,7 +2244,7 @@ bool LyXText::deleteEmptyParagraphMechanism(LyXCursor const & old_cursor)
        }
 
        // don't delete anything if this is the ONLY paragraph!
-       if (!old_cursor.par()->next() && !old_cursor.par()->previous())
+       if (ownerParagraphs().size() == 1)
                return false;
 
        // Do not delete empty paragraphs with keepempty set.
@@ -2257,9 +2259,9 @@ bool LyXText::deleteEmptyParagraphMechanism(LyXCursor const & old_cursor)
        // we can't possibly have deleted a paragraph before this point
        bool deleted = false;
 
-       if ((old_cursor.par()->empty()
-            || (old_cursor.par()->size() == 1
-                && old_cursor.par()->isLineSeparator(0)))) {
+       if (old_cursor.par()->empty() ||
+           (old_cursor.par()->size() == 1 &&
+            old_cursor.par()->isLineSeparator(0))) {
                // ok, we will delete anything
                LyXCursor tmpcursor;
 
@@ -2272,12 +2274,10 @@ bool LyXText::deleteEmptyParagraphMechanism(LyXCursor const & old_cursor)
                        tmpcursor = cursor;
                        cursor = old_cursor; // that undo can restore the right cursor position
                        Paragraph * endpar = old_cursor.par()->next();
-#warning FIXME This if clause looks very redundant. (Lgb)
-                       if (endpar && endpar->getDepth()) {
-                               while (endpar && endpar->getDepth()) {
-                                       endpar = endpar->next();
-                               }
+                       while (endpar && endpar->getDepth()) {
+                               endpar = endpar->next();
                        }
+
                        setUndo(bv(), Undo::DELETE, &*old_cursor.par(), endpar);
                        cursor = tmpcursor;
 
@@ -2307,11 +2307,10 @@ bool LyXText::deleteEmptyParagraphMechanism(LyXCursor const & old_cursor)
                        tmpcursor = cursor;
                        cursor = old_cursor; // that undo can restore the right cursor position
                        Paragraph * endpar = old_cursor.par()->next();
-                       if (endpar && endpar->getDepth()) {
-                               while (endpar && endpar->getDepth()) {
-                                       endpar = endpar->next();
-                               }
+                       while (endpar && endpar->getDepth()) {
+                               endpar = endpar->next();
                        }
+
                        setUndo(bv(), Undo::DELETE, &*old_cursor.par(), endpar);
                        cursor = tmpcursor;