]> git.lyx.org Git - lyx.git/blobdiff - src/BufferView.C
more cursor dispatch
[lyx.git] / src / BufferView.C
index ecfdd5543b694ae3536646924094e2c4c9d61548..d1ff326a342b1ed739c172f98612c333a29d6fc8 100644 (file)
 using lyx::support::bformat;
 using lyx::support::MakeAbsPath;
 
+using std::distance;
 using std::find;
 using std::string;
+using std::swap;
 using std::vector;
 
 
@@ -58,8 +60,7 @@ extern BufferList bufferlist;
 
 BufferView::BufferView(LyXView * owner, int xpos, int ypos,
                       int width, int height)
-       : pimpl_(new Pimpl(*this, owner, xpos, ypos, width, height)),
-         x_target_(0)
+       : pimpl_(new Pimpl(*this, owner, xpos, ypos, width, height))
 {}
 
 
@@ -260,7 +261,7 @@ bool BufferView::insertLyXFile(string const & filen)
 
        string const fname = MakeAbsPath(filen);
 
-       clearSelection();
+       cursor().clearSelection();
        text()->breakParagraph(buffer()->paragraphs());
 
        bool res = buffer()->readFile(fname, text()->cursorPar());
@@ -300,7 +301,7 @@ void BufferView::setCursorFromRow(int row)
 }
 
 
-bool BufferView::insertInset(InsetOld * inset, string const & lout)
+bool BufferView::insertInset(InsetBase * inset, string const & lout)
 {
        return pimpl_->insertInset(inset, lout);
 }
@@ -313,11 +314,11 @@ void BufferView::gotoLabel(string const & label)
                vector<string> labels;
                it->getLabelList(*buffer(), labels);
                if (find(labels.begin(),labels.end(),label) != labels.end()) {
-                       clearSelection();
+                       cursor().clearSelection();
                        text()->setCursor(
-                               std::distance(text()->paragraphs().begin(), it.getPar()),
+                               distance(text()->paragraphs().begin(), it.getPar()),
                                it.getPos());
-                       resetAnchor();
+                       cursor().resetAnchor();
                        update();
                        return;
                }
@@ -331,8 +332,8 @@ void BufferView::undo()
                return;
 
        owner()->message(_("Undo"));
-       clearSelection();
-       if (!textUndo(this))
+       cursor().clearSelection();
+       if (!textUndo(*this))
                owner()->message(_("No further undo information"));
        update();
        switchKeyMap();
@@ -345,8 +346,8 @@ void BufferView::redo()
                return;
 
        owner()->message(_("Redo"));
-       clearSelection();
-       if (!textRedo(this))
+       cursor().clearSelection();
+       if (!textRedo(*this))
                owner()->message(_("No further redo information"));
        update();
        switchKeyMap();
@@ -392,15 +393,9 @@ bool BufferView::ChangeRefsIfUnique(string const & from, string const & to)
 }
 
 
-UpdatableInset * BufferView::innerInset() const
-{
-       return static_cast<UpdatableInset*>(fullCursor().innerInset());
-}
-
-
 LyXText * BufferView::getLyXText() const
 {
-       return fullCursor().innerText();
+       return cursor().innerText();
 }
 
 
@@ -417,10 +412,10 @@ Encoding const * BufferView::getEncoding() const
        LyXText * t = getLyXText();
        if (!t)
                return 0;
-       return t->cursorPar()->getFont(
-               buffer()->params(),
-               t->cursor().pos(),
-               outerFont(t->cursorPar(), t->paragraphs())
+       CursorSlice const & cur = cursor().innerTextSlice();
+       return t->getPar(cur.par())->getFont(
+               buffer()->params(), cur.pos(),
+               outerFont(t->getPar(cur.par()), t->paragraphs())
        ).language()->encoding();
 }
 
@@ -437,72 +432,6 @@ int BufferView::workHeight() const
 }
 
 
-void BufferView::fullCursor(LCursor const & cur)
-{
-       pimpl_->cursor_ = cur;
-}
-
-
-LCursor & BufferView::fullCursor()
-{
-       return pimpl_->cursor_;
-}
-
-
-LCursor const & BufferView::fullCursor() const
-{
-       return pimpl_->cursor_;
-}
-
-
-CursorSlice & BufferView::cursor()
-{
-       return fullCursor().cursor_.back();
-}
-
-
-CursorSlice const & BufferView::cursor() const
-{
-       return fullCursor().cursor_.back();
-}
-
-
-CursorSlice & BufferView::anchor()
-{
-       return fullCursor().anchor_.back();
-}
-
-
-CursorSlice const & BufferView::anchor() const
-{
-       return fullCursor().anchor_.back();
-}
-
-
-Selection & BufferView::selection()
-{
-       return selection_;
-}
-
-
-Selection const & BufferView::selection() const
-{
-       return selection_;
-}
-
-
-void BufferView::x_target(int x)
-{
-       x_target_ = x;
-}
-
-
-int BufferView::x_target() const
-{
-       return x_target_;
-}
-
-
 void BufferView::updateParagraphDialog()
 {
        pimpl_->updateParagraphDialog();
@@ -515,69 +444,26 @@ LyXText * BufferView::text() const
 }
 
 
-void BufferView::resetAnchor()
-{
-       return fullCursor().resetAnchor();
-}
-
-
-CursorSlice const & BufferView::selStart() const
-{
-       if (!selection().set())
-               return cursor();
-       // can't use std::min as this creates a new object
-       return anchor() < cursor() ? anchor() : cursor();
-}
-
-
-CursorSlice const & BufferView::selEnd() const
-{
-       if (!selection().set())
-               return cursor();
-       return anchor() > cursor() ? anchor() : cursor();
-}
-
-
-CursorSlice & BufferView::selStart()
-{
-       if (!selection().set())
-               return cursor();
-       return anchor() < cursor() ? anchor() : cursor();
-}
-
-
-CursorSlice & BufferView::selEnd()
-{
-       if (selection().set())
-               return cursor();
-       return anchor() > cursor() ? anchor() : cursor();
-}
-
-
-void BufferView::setSelection()
-{
-       selection().set(true);
-       // a selection with no contents is not a selection
-       if (cursor().par() == anchor().par() && cursor().pos() == anchor().pos())
-               selection().set(false);
-}
-
-
-void BufferView::clearSelection()
+void BufferView::setCursor(ParIterator const & par,
+                          lyx::pos_type pos)
 {
-       selection().set(false);
-       selection().mark(false);
-       resetAnchor();
-       unsetXSel();
+       LCursor & cur = cursor();
+       cur.reset();
+       ParIterator::PosHolder const & positions = par.positions();
+       int const last = par.size() - 1;
+       for (int i = 0; i < last; ++i)
+               (*positions[i].it)->inset->edit(cur, true);
+       cur.resetAnchor();
+       LyXText * lt = par.text(*buffer());
+       lt->setCursor(par.pit(), pos);
 }
 
 
-
 /*
 if the fitCursor call refers to some point in never-explored-land, then we
 don't have y information in insets there, then we cannot even do an update
 to get it (because we need the y infomation for setting top_y first). So
-this is solved in put_selection_at with:
+this is solved in putSelectionAt with:
 
 - setting top_y to the y of the outerPar (that has good info)
 - calling update
@@ -591,23 +477,24 @@ void BufferView::putSelectionAt(PosIterator const & cur,
                      int length, bool backwards)
 {
        ParIterator par(cur);
-       
-       clearSelection();
+
+       cursor().clearSelection();
 
        LyXText * text = par.text(*buffer());
-       par.lockPath(this);
+       setCursor(par, cur.pos());
+       
        // hack for the chicken and egg problem
        if (par.inset())
                top_y(par.outerPar()->y);
        update();
        text->setCursor(cur.pit(), cur.pos());
-       fullCursor().updatePos();
+       cursor().updatePos();
 
        if (length) {
                text->setSelectionRange(length);
-               setSelection();
+               cursor().setSelection();
                if (backwards)
-                       std::swap(cursor(), anchor());
+                       swap(cursor().cursor_, cursor().anchor_);
        }
 
        fitCursor();
@@ -615,7 +502,13 @@ void BufferView::putSelectionAt(PosIterator const & cur,
 }
 
 
-CursorSlice & cursorTip(BufferView & bv)
+LCursor & BufferView::cursor()
+{
+       return pimpl_->cursor_;
+}
+
+
+LCursor const & BufferView::cursor() const
 {
-       return bv.cursor();
+       return pimpl_->cursor_;
 }