]> git.lyx.org Git - lyx.git/blobdiff - src/text2.C
bug + spped fixes + small stuff
[lyx.git] / src / text2.C
index 3aa14065e64f7b1e305d9ca1210be7fda80f5249..6e4c06c7430308e8da540cb65a07390b29fb1b9d 100644 (file)
@@ -79,9 +79,9 @@ LyXText::LyXText(BufferView * bv, bool in_inset)
 {}
 
 
-void LyXText::init(BufferView * bview)
+void LyXText::init(BufferView * bv)
 {
-       bv_owner = bview;
+       bv_owner = bv;
 
        ParagraphList::iterator const beg = paragraphs().begin();
        ParagraphList::iterator const end = paragraphs().end();
@@ -94,8 +94,7 @@ void LyXText::init(BufferView * bview)
        current_font = getFont(beg, 0);
 
        redoParagraphs(beg, end);
-       setCursorIntern(0, 0);
-       bv()->cursor().resetAnchor();
+       bv->cursor().resetAnchor();
 
        updateCounters();
 }
@@ -214,38 +213,6 @@ void LyXText::setCharFont(
 }
 
 
-InsetBase * LyXText::getInset() const
-{
-       ParagraphList::iterator pit = cursorPar();
-       pos_type const pos = cursor().pos();
-
-       if (pos < pit->size() && pit->isInset(pos)) {
-               return pit->getInset(pos);
-       }
-       return 0;
-}
-
-
-bool LyXText::toggleInset()
-{
-       InsetBase * inset = getInset();
-       // is there an editable inset at cursor position?
-       if (!isEditableInset(inset))
-               return false;
-       //bv()->owner()->message(inset->editMessage());
-
-       // do we want to keep this?? (JMarc)
-       if (!isHighlyEditableInset(inset))
-               recUndo(cursor().par());
-
-       if (inset->isOpen())
-               inset->close();
-       else
-               inset->open();
-       return true;
-}
-
-
 // used in setLayout
 // Asger is not sure we want to do this...
 void LyXText::makeFontEntriesLayoutSpecific(BufferParams const & params,
@@ -324,11 +291,9 @@ void LyXText::setLayout(string const & layout)
                bv()->owner()->dispatch(FuncRequest(LFUN_ENDSEL));
                bv()->owner()->dispatch(FuncRequest(LFUN_CUT));
                InsetBase * inset = new InsetEnvironment(params, layout);
-               if (bv()->insertInset(inset)) {
-                       //inset->edit(bv());
-                       //bv()->owner()->dispatch(FuncRequest(LFUN_PASTE));
-               } else
-                       delete inset;
+               insertInset(inset);
+               //inset->edit(bv());
+               //bv()->owner()->dispatch(FuncRequest(LFUN_PASTE));
                return;
        }
 
@@ -501,8 +466,7 @@ void LyXText::cursorTop()
 
 void LyXText::cursorBottom()
 {
-       ParagraphList::iterator lastpit =
-               boost::prior(paragraphs().end());
+       ParagraphList::iterator lastpit = boost::prior(paragraphs().end());
        setCursor(lastpit, lastpit->size());
 }
 
@@ -555,7 +519,7 @@ string LyXText::getStringToIndex()
        else if (cur.selBegin().par() != cur.selEnd().par())
                bv()->owner()->message(_("Cannot index more than one paragraph!"));
        else
-               idxstring = selectionAsString(*bv()->buffer(), false);
+               idxstring = cur.selectionAsString(false);
 
        // Reset cursors to their original position.
        cursor() = reset_cursor;
@@ -931,7 +895,7 @@ void LyXText::cutSelection(bool doclear, bool realcut)
        // 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)
-       bv()->stuffClipboard(selectionAsString(*bv()->buffer(), true));
+       bv()->stuffClipboard(cur.selectionAsString(true));
 
        // This doesn't make sense, if there is no selection
        if (!cur.selection())
@@ -982,7 +946,7 @@ void LyXText::copySelection()
 {
        LCursor & cur = bv()->cursor();
        // stuff the selection onto the X clipboard, from an explicit copy request
-       bv()->stuffClipboard(selectionAsString(*bv()->buffer(), true));
+       bv()->stuffClipboard(cur.selectionAsString(true));
 
        // this doesnt make sense, if there is no selection
        if (!cur.selection())
@@ -1087,8 +1051,7 @@ void LyXText::insertStringAsLines(string const & str)
        ParagraphList::iterator pit = cursorPar();
        pos_type pos = cursor().pos();
        ParagraphList::iterator endpit = boost::next(cursorPar());
-
-       recUndo(cursor().par());
+       recordUndo(cur, Undo::ATOMIC);
 
        // only to be sure, should not be neccessary
        cur.clearSelection();
@@ -1243,7 +1206,7 @@ void LyXText::setCurrentFont()
        }
 }
 
-
+// x is an absolute screen coord
 // returns the column near the specified x-coordinate of the row
 // x is set to the real beginning of this column
 pos_type LyXText::getColumnNearX(ParagraphList::iterator pit,
@@ -1363,7 +1326,8 @@ void LyXText::setCursorFromCoordinates(CursorSlice & cur, int x, int y)
        ParagraphList::iterator pit;
        Row const & row = *getRowNearY(y, pit);
        bool bound = false;
-       pos_type const pos = row.pos() + getColumnNearX(pit, row, x, bound);
+       int xx = x + xo_; // getRowNearX get absolute x coords
+       pos_type const pos = row.pos() + getColumnNearX(pit, row, xx, bound);
        cur.par() = parOffset(pit);
        cur.pos() = pos;
        cur.boundary() = bound;
@@ -1373,10 +1337,11 @@ void LyXText::setCursorFromCoordinates(CursorSlice & cur, int x, int y)
 // x,y are absolute screen coordinates
 void LyXText::edit(LCursor & cur, int x, int y)
 {
-       int xx = x; // is modified by getColumnNearX
        ParagraphList::iterator pit;
-       Row const & row = *getRowNearY(y, pit);
+       Row const & row = *getRowNearY(y - yo_, pit);
        bool bound = false;
+
+       int xx = x; // is modified by getColumnNearX
        pos_type const pos = row.pos() + getColumnNearX(pit, row, xx, bound);
        cur.par() = parOffset(pit);
        cur.pos() = pos;
@@ -1385,11 +1350,12 @@ void LyXText::edit(LCursor & cur, int x, int y)
        // try to descend into nested insets
        InsetBase * inset = checkInsetHit(x, y);
        if (inset) {
-               // This should be just before or just behind the cursor position
-               // set above.
+               // This should be just before or just behind the
+               // cursor position set above.
                BOOST_ASSERT((pos != 0 && inset == pit->getInset(pos - 1))
                             || inset == pit->getInset(pos));
-               // Make sure the cursor points to the position before this inset.
+               // Make sure the cursor points to the position before
+               // this inset.
                if (inset == pit->getInset(pos - 1))
                        --cur.pos();
                inset->edit(cur, x, y);
@@ -1458,10 +1424,11 @@ DispatchResult LyXText::moveLeftIntern(bool front,
 
 DispatchResult LyXText::moveUp()
 {
-       if (cursorPar() == firstPar() && cursorRow() == firstRow())
+       LCursor & cur = bv()->cursor();
+       if (cur.par() == 0 && cursorRow() == firstRow())
                return DispatchResult(false, FINISHED_UP);
        cursorUp(false);
-       bv()->cursor().clearSelection();
+       cur.clearSelection();
        return DispatchResult(true);
 }
 
@@ -1469,7 +1436,7 @@ DispatchResult LyXText::moveUp()
 DispatchResult LyXText::moveDown()
 {
        LCursor & cur = bv()->cursor();
-       if (cursorPar() == lastPar() && cursorRow() == lastRow())
+       if (cur.par() == cur.lastpar() && cursorRow() == lastRow())
                return DispatchResult(false, FINISHED_DOWN);
        cursorDown(false);
        cur.clearSelection();
@@ -1739,13 +1706,13 @@ ParagraphList & LyXText::paragraphs() const
 
 void LyXText::recUndo(paroffset_type first, paroffset_type last) const
 {
-       recordUndo(Undo::ATOMIC, this, first, last);
+       recordUndo(bv()->cursor(), Undo::ATOMIC, first, last);
 }
 
 
 void LyXText::recUndo(lyx::paroffset_type par) const
 {
-       recordUndo(Undo::ATOMIC, this, par, par);
+       recordUndo(bv()->cursor(), Undo::ATOMIC, par, par);
 }
 
 
@@ -1755,6 +1722,26 @@ bool LyXText::isInInset() const
 }
 
 
+bool LyXText::toggleInset()
+{
+       InsetBase * inset = bv()->cursor().nextInset();
+       // is there an editable inset at cursor position?
+       if (!isEditableInset(inset))
+               return false;
+       //bv()->owner()->message(inset->editMessage());
+
+       // do we want to keep this?? (JMarc)
+       if (!isHighlyEditableInset(inset))
+               recUndo(cursor().par());
+
+       if (inset->isOpen())
+               inset->close();
+       else
+               inset->open();
+       return true;
+}
+
+
 int defaultRowHeight()
 {
        return int(font_metrics::maxHeight(LyXFont(LyXFont::ALL_SANE)) *  1.2);