]> git.lyx.org Git - lyx.git/blobdiff - src/text2.C
the update/updateInset merge
[lyx.git] / src / text2.C
index 2daf79d25f4b9dd8a24aec155e4b6481750585c1..fe8c5ddd9dc059f5fcba26165af59832cbd2882d 100644 (file)
 #include "BufferView.h"
 #include "Bullet.h"
 #include "counters.h"
+#include "cursor.h"
 #include "CutAndPaste.h"
 #include "debug.h"
+#include "dispatchresult.h"
 #include "errorlist.h"
 #include "Floating.h"
 #include "FloatList.h"
@@ -70,12 +72,10 @@ using std::string;
 
 LyXText::LyXText(BufferView * bv, InsetText * inset, bool ininset,
          ParagraphList & paragraphs)
-       : height(0), width(0), anchor_y_(0),
-         inset_owner(inset), the_locking_inset(0), bv_owner(bv),
+       : height(0), width(0), inset_owner(inset), bv_owner(bv),
          in_inset_(ininset), paragraphs_(&paragraphs),
                cache_pos_(-1)
-{
-}
+{}
 
 
 void LyXText::init(BufferView * bview)
@@ -89,8 +89,6 @@ void LyXText::init(BufferView * bview)
 
        width = 0;
        height = 0;
-
-       anchor_y_ = 0;
        cache_pos_ = -1;
 
        current_font = getFont(beg, 0);
@@ -257,9 +255,10 @@ void LyXText::toggleInset()
                // No, try to see if we are inside a collapsable inset
                if (inset_owner && inset_owner->owner()
                    && inset_owner->owner()->isOpen()) {
-                       bv()->unlockInset(inset_owner->owner());
+                       finishUndo();
                        inset_owner->owner()->close(bv());
                        bv()->getLyXText()->cursorRight(bv());
+                       bv()->updateParagraphDialog();
                }
                return;
        }
@@ -274,11 +273,11 @@ void LyXText::toggleInset()
        else
                inset->open(bv());
 
-       bv()->updateInset(inset);
+       bv()->update();
 }
 
 
-/* used in setlayout */
+// used in setLayout 
 // Asger is not sure we want to do this...
 void LyXText::makeFontEntriesLayoutSpecific(BufferParams const & params,
                                            Paragraph & par)
@@ -439,6 +438,7 @@ bool LyXText::changeDepth(bv_funcs::DEPTH_CHANGE type, bool test_only)
 
                prev_after_depth = pit->getMaxDepthAfter();
 
+#warning SERIOUS: Uahh... does this mean we access end->getMaxDepthAfter?
                if (pit == end) {
                        break;
                }
@@ -549,14 +549,13 @@ void LyXText::setSelection()
 }
 
 
-
 void LyXText::clearSelection()
 {
        TextCursor::clearSelection();
 
-       // reset this in the bv_owner!
-       if (bv_owner && bv_owner->text)
-               bv_owner->text->xsel_cache.set(false);
+       // reset this in the bv()!
+       if (bv() && bv()->text)
+               bv()->text->xsel_cache.set(false);
 }
 
 
@@ -570,7 +569,10 @@ void LyXText::cursorHome()
 void LyXText::cursorEnd()
 {
        ParagraphList::iterator cpit = cursorPar();
-       setCursor(cpit, cpit->getRow(cursor.pos())->endpos() - 1);
+       pos_type end = cpit->getRow(cursor.pos())->endpos();
+       // if not on the last row of the par, put the cursor before
+       // the final space
+       setCursor(cpit, end == cpit->size() ? end : end - 1);
 }
 
 
@@ -601,9 +603,10 @@ void LyXText::toggleFree(LyXFont const & font, bool toggleall)
        // If there is a change in the language the implicit word selection
        // is disabled.
        LyXCursor resetCursor = cursor;
-       bool implicitSelection = (font.language() == ignore_language
-                                 && font.number() == LyXFont::IGNORE)
-               ? selectWordWhenUnderCursor(lyx::WHOLE_WORD_STRICT) : false;
+       bool implicitSelection =
+               font.language() == ignore_language
+               && font.number() == LyXFont::IGNORE
+               && selectWordWhenUnderCursor(lyx::WHOLE_WORD_STRICT);
 
        // Set font
        setFont(font, toggleall);
@@ -652,7 +655,7 @@ string LyXText::getStringToIndex()
 // the DTP switches for paragraphs. LyX will store them in the first
 // physical paragraph. When a paragraph is broken, the top settings rest,
 // the bottom settings are given to the new one. So I can make sure,
-// they do not duplicate themself and you cannnot make dirty things with
+// they do not duplicate themself and you cannot play dirty tricks with
 // them!
 
 void LyXText::setParagraph(
@@ -686,7 +689,6 @@ void LyXText::setParagraph(
 
        recUndo(selection.start.par(), parOffset(undoendpit) - 1);
 
-
        int tmppit = selection.end.par();
 
        while (tmppit != selection.start.par() - 1) {
@@ -722,8 +724,7 @@ void LyXText::setParagraph(
        setCursor(selection.end.par(), selection.end.pos());
        setSelection();
        setCursor(tmpcursor.par(), tmpcursor.pos());
-       if (inset_owner)
-               bv()->updateInset(inset_owner);
+       bv()->update();
 }
 
 
@@ -1017,6 +1018,7 @@ void LyXText::insertInset(InsetOld * inset)
 {
        if (!cursorPar()->insetAllowed(inset->lyxCode()))
                return;
+
        recUndo(cursor.par());
        freezeUndo();
        cursorPar()->insertInset(cursor.pos(), inset);
@@ -1336,9 +1338,8 @@ void LyXText::setCursor(LyXCursor & cur, paroffset_type par,
                BOOST_ASSERT(false);
        }
        // now get the cursors x position
-       float x = getCursorX(pit, row, pos, boundary);
-       cur.x(int(x));
-       cur.x_fix(cur.x());
+       cur.x(int(getCursorX(pit, row, pos, boundary)));
+       bv()->x_target(cur.x());
 }
 
 
@@ -1352,7 +1353,7 @@ float LyXText::getCursorX(ParagraphList::iterator pit, Row const & row,
        double fill_label_hfill = row.fill_label_hfill();
        pos_type const row_pos  = row.pos();
        pos_type const end = row.endpos();
-       
+
        if (end <= row_pos)
                cursor_vpos = row_pos;
        else if (pos >= end && !boundary)
@@ -1617,24 +1618,22 @@ void LyXText::cursorUp(bool selecting)
        ParagraphList::iterator cpit = cursorPar();
        Row const & crow = *cpit->getRow(cursor.pos());
 #if 1
-       int x = cursor.x_fix();
+       int x = bv()->x_target();
        int y = cursor.y() - crow.baseline() - 1;
        setCursorFromCoordinates(x, y);
        if (!selecting) {
-               int topy = bv_owner->top_y();
+               int topy = bv()->top_y();
                int y1 = cursor.y() - topy;
                int y2 = y1;
                y -= topy;
                InsetOld * inset_hit = checkInsetHit(x, y1);
-               if (inset_hit && isHighlyEditableInset(inset_hit)) {
-                       inset_hit->dispatch(
-                               FuncRequest(bv(), LFUN_INSET_EDIT, x, y - (y2 - y1), mouse_button::none));
-               }
+               if (inset_hit && isHighlyEditableInset(inset_hit))
+                       inset_hit->edit(bv(), x, y - (y2 - y1));
        }
 #else
        lyxerr << "cursorUp: y " << cursor.y() << " bl: " <<
                crow.baseline() << endl;
-       setCursorFromCoordinates(cursor.x_fix(),
+       setCursorFromCoordinates(bv()->x_target(),
                cursor.y() - crow.baseline() - 1);
 #endif
 }
@@ -1645,22 +1644,20 @@ void LyXText::cursorDown(bool selecting)
        ParagraphList::iterator cpit = cursorPar();
        Row const & crow = *cpit->getRow(cursor.pos());
 #if 1
-       int x = cursor.x_fix();
+       int x = bv()->x_target();
        int y = cursor.y() - crow.baseline() + crow.height() + 1;
        setCursorFromCoordinates(x, y);
        if (!selecting) {
-               int topy = bv_owner->top_y();
+               int topy = bv()->top_y();
                int y1 = cursor.y() - topy;
                int y2 = y1;
                y -= topy;
                InsetOld * inset_hit = checkInsetHit(x, y1);
-               if (inset_hit && isHighlyEditableInset(inset_hit)) {
-                       FuncRequest cmd(bv(), LFUN_INSET_EDIT, x, y - (y2 - y1), mouse_button::none);
-                       inset_hit->dispatch(cmd);
-               }
+               if (inset_hit && isHighlyEditableInset(inset_hit))
+                       inset_hit->edit(bv(), x, y - (y2 - y1));
        }
 #else
-       setCursorFromCoordinates(cursor.x_fix(),
+       setCursorFromCoordinates(bv()->x_target(),
                 cursor.y() - crow.baseline() + crow.height() + 1);
 #endif
 }
@@ -1795,8 +1792,8 @@ bool LyXText::deleteEmptyParagraphMechanism(LyXCursor const & old_cursor)
        // we can't possibly have deleted a paragraph before this point
        bool deleted = false;
 
-       if (old_pit->empty() ||
-           (old_pit->size() == 1 && old_pit->isLineSeparator(0))) {
+       if (old_pit->empty()
+           || (old_pit->size() == 1 && old_pit->isLineSeparator(0))) {
                // ok, we will delete something
                LyXCursor tmpcursor;
 
@@ -1816,8 +1813,12 @@ bool LyXText::deleteEmptyParagraphMechanism(LyXCursor const & old_cursor)
                recUndo(parOffset(old_pit), parOffset(endpit) - 1);
                cursor = tmpcursor;
 
+               // cache cursor pit
+               ParagraphList::iterator tmppit = cursorPar();
                // delete old par
                ownerParagraphs().erase(old_pit);
+               // update cursor par offset
+               cursor.par(parOffset(tmppit));
                redoParagraph();
 
                // correct cursor y
@@ -1828,15 +1829,17 @@ bool LyXText::deleteEmptyParagraphMechanism(LyXCursor const & old_cursor)
                        selection.cursor = cursor;
                }
        }
-       if (!deleted) {
-               if (old_pit->stripLeadingSpaces()) {
-                       redoParagraph(old_pit);
-                       // correct cursor y
-                       setCursorIntern(cursor.par(), cursor.pos());
-                       selection.cursor = cursor;
-               }
+
+       if (deleted)
+               return true;
+
+       if (old_pit->stripLeadingSpaces()) {
+               redoParagraph(old_pit);
+               // correct cursor y
+               setCursorIntern(cursor.par(), cursor.pos());
+               selection.cursor = cursor;
        }
-       return deleted;
+       return false;
 }
 
 
@@ -1868,6 +1871,5 @@ bool LyXText::isInInset() const
 int defaultRowHeight()
 {
        LyXFont const font(LyXFont::ALL_SANE);
-       return int(font_metrics::maxAscent(font)
-                + font_metrics::maxDescent(font) * 1.5);
+       return int(font_metrics::maxHeight(font) *  1.2);
 }