]> git.lyx.org Git - lyx.git/blobdiff - src/text3.C
Move #includes out of header files.
[lyx.git] / src / text3.C
index 85976556b05cc426415521b2b344b9279e1ad78c..2203305b57043c42851a1ad68b8790623b97fa30 100644 (file)
@@ -1,12 +1,17 @@
-/* This file is part of
- * ======================================================
+/**
+ * \file text3.C
+ * This file is part of LyX, the document processor.
+ * Licence details can be found in the file COPYING.
  *
- *           LyX, The Document Processor
+ * \author Asger Alstrup
+ * \author Lars Gullik Bjønnes
+ * \author Alfredo Braunstein
+ * \author Angus Leeming
+ * \author John Levon
+ * \author André Pönitz
  *
- *           Copyright 1995 Matthias Ettrich
- *           Copyright 1995-2002 The LyX Team.
- *
- * ====================================================== */
+ * Full author contact details are available in file CREDITS.
+ */
 
 #include <config.h>
 
@@ -111,16 +116,16 @@ namespace {
 
                int const width = inset->width();
                int const inset_x = font.isVisibleRightToLeft()
-                       ? (cur.ix() - width) : cur.ix();
+                       ? (cur.x() - width) : cur.x();
 
                Box b(
                        inset_x + inset->scroll(),
                        inset_x + width,
-                       cur.iy() - inset->ascent(),
-                       cur.iy() + inset->descent()
+                       cur.y() - inset->ascent(),
+                       cur.y() + inset->descent()
                );
 
-               if (!b.contained(x, y)) {
+               if (!b.contains(x, y)) {
                        lyxerr[Debug::GUI] << "Missed inset at x,y "
                                           << x << ',' << y
                                           << " box " << b << endl;
@@ -131,7 +136,7 @@ namespace {
 
                x -= b.x1;
                // The origin of an inset is on the baseline
-               y -= text.cursor.iy();
+               y -= text.cursor.y();
 
                return inset;
        }
@@ -141,7 +146,7 @@ namespace {
 
 InsetOld * LyXText::checkInsetHit(int & x, int & y)
 {
-       int y_tmp = y + top_y();
+       int y_tmp = y + bv_owner->top_y();
 
        LyXCursor cur;
        setCursorFromCoordinates(cur, x, y_tmp);
@@ -238,21 +243,21 @@ void LyXText::gotoInset(InsetOld::Code code, bool same_content)
 
 void LyXText::cursorPrevious()
 {
-       int y = top_y();
+       int y = bv_owner->top_y();
+
+       RowList::iterator rit = cursorRow();
 
-       if (cursorRow() == rows().begin()) {
+       if (rit == firstRow()) {
                if (y > 0)
                        bv()->updateScrollbar();
                return;
        }
 
-       RowList::iterator cursorrow = cursorRow();
-
        setCursorFromCoordinates(cursor.x_fix(), y);
        finishUndo();
 
        int new_y;
-       if (cursorrow == bv()->text->cursorRow()) {
+       if (rit == bv()->text->cursorRow()) {
                // we have a row which is taller than the workarea. The
                // simplest solution is to move to the previous row instead.
                cursorUp(true);
@@ -261,60 +266,56 @@ void LyXText::cursorPrevious()
                // tall rows, but it's not working right now.
        } else {
                if (inset_owner) {
-                       new_y = bv()->text->cursor.iy()
+                       new_y = bv()->text->cursor.y()
                                + bv()->theLockingInset()->insetInInsetY() + y
-                               + cursorRow()->height()
+                               + rit->height()
                                - bv()->workHeight() + 1;
                } else {
                        new_y = cursor.y()
-                               - cursorRow()->baseline()
-                               + cursorRow()->height()
+                               - rit->baseline()
+                               + rit->height()
                                - bv()->workHeight() + 1;
                }
        }
-       //bv()->screen().draw(bv()->text, bv(), new_y < 0 ? 0 : new_y);
-       if (cursorRow() != rows().begin()) {
-               LyXCursor cur;
-               setCursor(cur, getPar(boost::prior(cursorRow())),
-                         boost::prior(cursorRow())->pos(), false);
-               if (cur.y() > top_y()) {
-                       cursorUp(true);
-               }
-       }
+
+       LyXCursor cur;
+       ParagraphList::iterator pit = cursor.par();
+       previousRow(pit, rit);
+       setCursor(cur, pit, rit->pos(), false);
+       if (cur.y() > bv_owner->top_y())
+               cursorUp(true);
        bv()->updateScrollbar();
 }
 
 
 void LyXText::cursorNext()
 {
-       int topy = top_y();
+       int topy = bv_owner->top_y();
 
-       if (boost::next(cursorRow()) == rows().end()) {
-               int y = cursor.y() - cursorRow()->baseline() +
-                       cursorRow()->height();
-               if (y > topy + bv()->workHeight()) {
-                       //bv()->screen().draw(bv()->text, bv(), bv()->text->top_y() + bv()->workHeight());
-                       bv()->updateScrollbar();
-               }
+       RowList::iterator rit = cursorRow();
+       if (rit == lastRow()) {
+               int y = cursor.y() - rit->baseline() + cursorRow()->height();
+               if (y > topy + bv()->workHeight())
+                       bv_owner->updateScrollbar();
                return;
        }
 
-       int y = topy + bv()->workHeight();
+       int y = topy + bv_owner->workHeight();
        if (inset_owner && !topy) {
-               y -= (bv()->text->cursor.iy()
-                         - bv()->text->top_y()
-                         + bv()->theLockingInset()->insetInInsetY());
+               y -= (bv_owner->text->cursor.y()
+                         - bv_owner->top_y()
+                         + bv_owner->theLockingInset()->insetInInsetY());
        }
 
-       getRowNearY(y);
+       ParagraphList::iterator dummypit;
+       y = getRowNearY(y, dummypit)->y();
 
-       RowList::iterator cursorrow = cursorRow();
        setCursorFromCoordinates(cursor.x_fix(), y);
        // + bv->workHeight());
        finishUndo();
 
        int new_y;
-       if (cursorrow == bv()->text->cursorRow()) {
+       if (rit == bv_owner->text->cursorRow()) {
                // we have a row which is taller than the workarea. The
                // simplest solution is to move to the next row instead.
                cursorDown(true);
@@ -322,27 +323,24 @@ void LyXText::cursorNext()
                // This is what we used to do, so we wouldn't skip right past
                // tall rows, but it's not working right now.
 #if 0
-               new_y = bv->text->top_y() + bv->workHeight();
+               new_y = bv->top_y() + bv->workHeight();
 #endif
        } else {
                if (inset_owner) {
-                       new_y = bv()->text->cursor.iy()
+                       new_y = bv()->text->cursor.y()
                                + bv()->theLockingInset()->insetInInsetY()
-                               + y - cursorRow()->baseline();
+                               + y - rit->baseline();
                } else {
-                       new_y =  cursor.y() - cursorRow()->baseline();
-               }
-       }
-       //bv()->screen().draw(bv()->text, bv(), new_y);
-
-       RowList::iterator next_row = boost::next(cursorRow());
-       if (next_row != rows().end()) {
-               LyXCursor cur;
-               setCursor(cur, getPar(next_row), next_row->pos(), false);
-               if (cur.y() < top_y() + bv()->workHeight()) {
-                       cursorDown(true);
+                       new_y = cursor.y() - cursorRow()->baseline();
                }
        }
+
+       ParagraphList::iterator pit = cursor.par();
+       nextRow(pit, rit);
+       LyXCursor cur;
+       setCursor(cur, pit, rit->pos(), false);
+       if (cur.y() < bv_owner->top_y() + bv()->workHeight())
+               cursorDown(true);
        bv()->updateScrollbar();
 }
 
@@ -357,7 +355,7 @@ void specialChar(LyXText * lt, BufferView * bv, InsetSpecialChar::Kind kind)
        if (!bv->insertInset(new_inset))
                delete new_inset;
        else
-               bv->updateInset();
+               bv->updateInset(new_inset);
 }
 
 
@@ -409,7 +407,7 @@ InsetOld::RESULT LyXText::dispatch(FuncRequest const & cmd)
                        if (tmp->params().startOfAppendix()) {
                                recordUndo(bv, Undo::ATOMIC, tmp);
                                tmp->params().startOfAppendix(false);
-                               setHeightOfRow(getRow(tmp, 0));
+                               redoParagraph(tmp);
                                break;
                        }
                }
@@ -1179,14 +1177,10 @@ InsetOld::RESULT LyXText::dispatch(FuncRequest const & cmd)
                if (!isInInset() && bv->theLockingInset())
                        break;
                if (cmd.button() == mouse_button::button1) {
-                       if (!isInInset())
-                               bv->screen().toggleSelection(this, bv);
                        cursorHome();
                        selection.cursor = cursor;
                        cursorEnd();
                        setSelection();
-                       if (!isInInset())
-                               bv->screen().toggleSelection(this, bv, false);
                        bv->update();
                        bv->haveSelection(selection.set());
                }
@@ -1198,13 +1192,7 @@ InsetOld::RESULT LyXText::dispatch(FuncRequest const & cmd)
                if (!isInInset() && bv->theLockingInset())
                        break;
                if (cmd.button() == mouse_button::button1) {
-                       if (!isInInset()) {
-                               bv->screen().toggleSelection(this, bv);
-                               selectWord(lyx::WHOLE_WORD_STRICT);
-                               bv->screen().toggleSelection(this, bv, false);
-                       } else {
-                               selectWord(lyx::WHOLE_WORD_STRICT);
-                       }
+                       selectWord(lyx::WHOLE_WORD_STRICT);
                        bv->update();
                        bv->haveSelection(selection.set());
                }
@@ -1226,11 +1214,11 @@ InsetOld::RESULT LyXText::dispatch(FuncRequest const & cmd)
                        LyXFont font = bv->text->getFont(cursor.par(), cursor.pos());
                        int width = tli->width();
                        int inset_x = font.isVisibleRightToLeft()
-                               ? cursor.ix() - width : cursor.ix();
+                               ? cursor.x() - width : cursor.x();
                        int start_x = inset_x + tli->scroll();
                        FuncRequest cmd1 = cmd;
                        cmd1.x = cmd.x - start_x;
-                       cmd1.y = cmd.y - cursor.iy() + bv->text->top_y();
+                       cmd1.y = cmd.y - cursor.y() + bv->top_y();
                        tli->localDispatch(cmd1);
                        break;
                }
@@ -1245,7 +1233,7 @@ InsetOld::RESULT LyXText::dispatch(FuncRequest const & cmd)
                }
 
                RowList::iterator cursorrow = bv->text->cursorRow();
-               bv->text->setCursorFromCoordinates(cmd.x, cmd.y + bv->text->top_y());
+               bv->text->setCursorFromCoordinates(cmd.x, cmd.y + bv->top_y());
        #if 0
                // sorry for this but I have a strange error that the y value jumps at
                // a certain point. This seems like an error in my xforms library or
@@ -1265,7 +1253,6 @@ InsetOld::RESULT LyXText::dispatch(FuncRequest const & cmd)
 
                bv->text->setSelection();
                bv->update();
-               bv->fitCursor();
                break;
        }
 
@@ -1302,7 +1289,7 @@ InsetOld::RESULT LyXText::dispatch(FuncRequest const & cmd)
                        paste_internally = true;
                }
 
-               int const screen_first = bv->text->top_y();
+               int const screen_first = bv->top_y();
 
                if (bv->theLockingInset()) {
                        // We are in inset locking mode
@@ -1321,7 +1308,6 @@ InsetOld::RESULT LyXText::dispatch(FuncRequest const & cmd)
                        selection_possible = true;
 
                // Clear the selection
-               bv->screen().toggleSelection(bv->text, bv);
                bv->text->clearSelection();
                bv->update();
                bv->updateScrollbar();
@@ -1442,7 +1428,7 @@ InsetOld::RESULT LyXText::dispatch(FuncRequest const & cmd)
                        // stack. They don't *have* to
                        // alter the document...
                        // (Joacim)
-                       // ...or maybe the SetCursorParUndo()
+                       // ...or maybe the recordUndo()
                        // below isn't necessary at all anylonger?
                        if (inset_hit->lyxCode() == InsetOld::REF_CODE)
                                recordUndo(bv, Undo::ATOMIC);
@@ -1473,7 +1459,7 @@ InsetOld::RESULT LyXText::dispatch(FuncRequest const & cmd)
                }
 
                bv->beforeChange(this);
-               LyXFont const old_font(real_current_font);
+               LyXFont const old_font = real_current_font;
 
                string::const_iterator cit = cmd.argument.begin();
                string::const_iterator end = cmd.argument.end();
@@ -1488,6 +1474,7 @@ InsetOld::RESULT LyXText::dispatch(FuncRequest const & cmd)
                // update the minibuffer
                if (old_font != real_current_font)
                        bv->owner()->view_state_changed();
+               bv->updateScrollbar();
                break;
        }
 
@@ -1512,6 +1499,7 @@ InsetOld::RESULT LyXText::dispatch(FuncRequest const & cmd)
        case LFUN_INSET_CAPTION:
 #endif
        case LFUN_INSERT_NOTE:
+       case LFUN_INSERT_BRANCH:
        case LFUN_INSERT_BIBITEM:
        case LFUN_INSET_ERT:
        case LFUN_INSET_FLOAT: