]> git.lyx.org Git - features.git/commitdiff
move selStart and selEnd from LyXText to BufferView
authorAndré Pönitz <poenitz@gmx.net>
Wed, 14 Jan 2004 15:09:01 +0000 (15:09 +0000)
committerAndré Pönitz <poenitz@gmx.net>
Wed, 14 Jan 2004 15:09:01 +0000 (15:09 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@8344 a592a061-630c-0410-9148-cb99ea01b6c8

src/BufferView.C
src/BufferView.h
src/BufferView_pimpl.C
src/lyxfind.C
src/lyxtext.h
src/rowpainter.C
src/text.C
src/text2.C
src/text3.C

index 92680d41efd1d7cbf8bfc7eac9972f3ce0f3121e..2baef2572a9aceda2bb0b0f07755a093772f5c18 100644 (file)
@@ -518,3 +518,36 @@ 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();
+}
index d2d55a7b798bf000cf6e6a162b451de715a8a65f..0e33ef08e75c92b7c7cc34c9ba5110195907a91f 100644 (file)
@@ -233,6 +233,14 @@ public:
        Selection & selection();
        ///
        Selection const & selection() const;
+       ///
+       CursorSlice & selStart();
+       ///
+       CursorSlice const & selStart() const;
+       ///
+       CursorSlice & selEnd();
+       ///
+       CursorSlice const & selEnd() const;
 
        ///
        Selection selection_;
index 8b9556bb5f53934619f4970d96696df3d969b7ad..67f9f5262c21fbc6bb71874277bf684ddf7000da 100644 (file)
@@ -395,10 +395,10 @@ void BufferView::Pimpl::resizeCurrentBuffer()
 
        par = bv_->cursor().par();
        pos = bv_->cursor().pos();
-       selstartpar = text->selStart().par();
-       selstartpos = text->selStart().pos();
-       selendpar = text->selEnd().par();
-       selendpos = text->selEnd().pos();
+       selstartpar = bv_->selStart().par();
+       selstartpos = bv_->selStart().pos();
+       selendpar = bv_->selEnd().par();
+       selendpos = bv_->selEnd().pos();
        sel = bv_->selection().set();
        mark_set = bv_->selection().mark();
        text->textwidth_ = bv_->workWidth();
@@ -637,8 +637,8 @@ Change const BufferView::Pimpl::getCurrentChange()
        if (!bv_->selection().set())
                return Change(Change::UNCHANGED);
 
-       return text->getPar(text->selStart())
-               ->lookupChangeFull(text->selStart().pos());
+       return text->getPar(bv_->selStart())
+               ->lookupChangeFull(bv_->selStart().pos());
 }
 
 
index 16aa614b8b3a2a38ed38c70e15b5e1647cf14e4d..87225f67ed3e6bc8bb2de0e96c19a774eb9c2e34 100644 (file)
@@ -394,8 +394,7 @@ int replace(BufferView * bv,
 
        text->replaceSelectionWithString(replacestr);
        text->setSelectionRange(replacestr.length());
-       text->cursor() = fw ? text->selEnd() : text->selStart();
-
+       bv->cursor() = fw ? bv->selEnd() : bv->selStart();
        bv->buffer()->markDirty();
        find(bv, searchstr, cs, mw, fw);
        bv->update();
index b301d0f91d9b4a4b212a1ad07511b130b2b20b45..44a8419f58f68a1c8609bfba4c5169fe2217a574 100644 (file)
@@ -409,15 +409,6 @@ public:
        void setSelection();
        ///
        void clearSelection();
-       ///
-       CursorSlice & selStart();
-       ///
-       CursorSlice const & selStart() const;
-       ///
-       CursorSlice & selEnd();
-       ///
-       CursorSlice const & selEnd() const;
-
 
 public:
        ///
index 5e49460f44af4d2f4ac3d2fbbec219f31fe233b4..8fe21d9e616c7fff7e3f9ab99ecc521dbea25a19 100644 (file)
@@ -391,14 +391,14 @@ void RowPainter::paintSelection()
        bool const is_rtl = pit_->isRightToLeftPar(bv_.buffer()->params());
 
        // the current selection
-       int const startx = text_.cursorX(text_.selStart());
-       int const endx = text_.cursorX(text_.selEnd());
-       int const starty = text_.cursorY(text_.selStart());
-       int const endy = text_.cursorY(text_.selEnd());
-       ParagraphList::iterator startpit = text_.getPar(text_.selStart());
-       ParagraphList::iterator endpit = text_.getPar(text_.selEnd());
-       RowList::iterator startrow = startpit->getRow(text_.selStart().pos());
-       RowList::iterator endrow = endpit->getRow(text_.selEnd().pos());
+       int const startx = text_.cursorX(bv_.selStart());
+       int const endx = text_.cursorX(bv_.selEnd());
+       int const starty = text_.cursorY(bv_.selStart());
+       int const endy = text_.cursorY(bv_.selEnd());
+       ParagraphList::iterator startpit = text_.getPar(bv_.selStart());
+       ParagraphList::iterator endpit = text_.getPar(bv_.selEnd());
+       RowList::iterator startrow = startpit->getRow(bv_.selStart().pos());
+       RowList::iterator endrow = endpit->getRow(bv_.selEnd().pos());
        int const h = row_.height();
 
        int const row_y = pit_->y + row_.y_offset();
@@ -468,9 +468,9 @@ void RowPainter::paintSelection()
                }
 
                if (((startpit != pit_ && startrow != rit_)
-                               || text_.selStart().pos() <= pos) &&
+                               || bv_.selStart().pos() <= pos) &&
                        ((endpit != pit_ && endrow != rit_)
-                               || pos < text_.selEnd().pos())) {
+                               || pos < bv_.selEnd().pos())) {
                        // Here we do not use x_ as xo_ was added to x_.
                        pain_.fillRectangle(int(old_tmpx), yo_,
                                int(tmpx - old_tmpx + 1), h, LColor::selection);
index d8ab74fca4a205b8b2749abe34769f63ab1230b9..eaccc9cc027ac5ca63ab8e0d09e5e6f1c386d30f 100644 (file)
@@ -1127,9 +1127,9 @@ void LyXText::acceptChange()
        if (!bv()->selection().set() && cursorPar()->size())
                return;
 
-       if (selStart().par() == selEnd().par()) {
-               CursorSlice const & startc = selStart();
-               CursorSlice const & endc = selEnd();
+       if (bv()->selStart().par() == bv()->selEnd().par()) {
+               CursorSlice const & startc = bv()->selStart();
+               CursorSlice const & endc = bv()->selEnd();
                recordUndo(Undo::INSERT, this, startc.par());
                getPar(startc)->acceptChange(startc.pos(), endc.pos());
                finishUndo();
@@ -1146,9 +1146,9 @@ void LyXText::rejectChange()
        if (!bv()->selection().set() && cursorPar()->size())
                return;
 
-       if (selStart().par() == selEnd().par()) {
-               CursorSlice const & startc = selStart();
-               CursorSlice const & endc = selEnd();
+       if (bv()->selStart().par() == bv()->selEnd().par()) {
+               CursorSlice const & startc = bv()->selStart();
+               CursorSlice const & endc = bv()->selEnd();
                recordUndo(Undo::INSERT, this, startc.par());
                getPar(startc)->rejectChange(startc.pos(), endc.pos());
                finishUndo();
@@ -1225,8 +1225,8 @@ void LyXText::changeCase(LyXText::TextCase action)
        CursorSlice to;
 
        if (bv()->selection().set()) {
-               from = selStart();
-               to = selEnd();
+               from = bv()->selStart();
+               to = bv()->selEnd();
        } else {
                from = cursor();
                getWord(from, to, lyx::PARTIAL_WORD);
@@ -1511,10 +1511,10 @@ string LyXText::selectionAsString(Buffer const & buffer, bool label) const
                return string();
 
        // should be const ...
-       ParagraphList::iterator startpit = getPar(selStart());
-       ParagraphList::iterator endpit = getPar(selEnd());
-       size_t const startpos = selStart().pos();
-       size_t const endpos = selEnd().pos();
+       ParagraphList::iterator startpit = getPar(bv()->selStart());
+       ParagraphList::iterator endpit = getPar(bv()->selEnd());
+       size_t const startpos = bv()->selStart().pos();
+       size_t const endpos = bv()->selEnd().pos();
 
        if (startpit == endpit)
                return startpit->asString(buffer, startpos, endpos, label);
@@ -1959,39 +1959,6 @@ CursorSlice const & LyXText::anchor() const
 }
 
 
-CursorSlice const & LyXText::selStart() const
-{
-       if (!bv()->selection().set())
-               return cursor();
-       // can't use std::min as this creates a new object
-       return anchor() < cursor() ? anchor() : cursor();
-}
-
-
-CursorSlice const & LyXText::selEnd() const
-{
-       if (!bv()->selection().set())
-               return cursor();
-       return anchor() > cursor() ? anchor() : cursor();
-}
-
-
-CursorSlice & LyXText::selStart()
-{
-       if (!bv()->selection().set())
-               return cursor();
-       return anchor() < cursor() ? anchor() : cursor();
-}
-
-
-CursorSlice & LyXText::selEnd()
-{
-       if (!bv()->selection().set())
-               return cursor();
-       return anchor() > cursor() ? anchor() : cursor();
-}
-
-
 void LyXText::setSelection()
 {
        bv()->selection().set(true);
index 5745a389cb79bd88aabd251fc53374a1728e057c..c362d0dc5a71a486e43cd5d08e0639fe94c06922 100644 (file)
@@ -333,8 +333,8 @@ void LyXText::setLayout(string const & layout)
                return;
        }
 
-       ParagraphList::iterator start = getPar(selStart().par());
-       ParagraphList::iterator end = boost::next(getPar(selEnd().par()));
+       ParagraphList::iterator start = getPar(bv()->selStart().par());
+       ParagraphList::iterator end = boost::next(getPar(bv()->selEnd().par()));
        ParagraphList::iterator endpit = setLayout(start, end, layout);
 
        redoParagraphs(start, endpit);
@@ -353,8 +353,8 @@ void getSelectionSpan(LyXText & text,
                beg = text.cursorPar();
                end = boost::next(beg);
        } else {
-               beg = text.getPar(text.selStart());
-               end = boost::next(text.getPar(text.selEnd()));
+               beg = text.getPar(text.bv()->selStart());
+               end = boost::next(text.getPar(text.bv()->selEnd()));
        }
 }
 
@@ -448,14 +448,14 @@ void LyXText::setFont(LyXFont const & font, bool toggleall)
        }
 
        // ok we have a selection.
-       recUndo(selStart().par(), selEnd().par());
+       recUndo(bv()->selStart().par(), bv()->selEnd().par());
        freezeUndo();
 
-       ParagraphList::iterator beg = getPar(selStart().par());
-       ParagraphList::iterator end = getPar(selEnd().par());
+       ParagraphList::iterator beg = getPar(bv()->selStart().par());
+       ParagraphList::iterator end = getPar(bv()->selEnd().par());
        
-       PosIterator pos(&paragraphs(), beg, selStart().pos());
-       PosIterator posend(&paragraphs(), end, selEnd().pos());
+       PosIterator pos(&paragraphs(), beg, bv()->selStart().pos());
+       PosIterator posend(&paragraphs(), end, bv()->selEnd().pos());
 
        BufferParams const & params = bv()->buffer()->params();
 
@@ -549,7 +549,7 @@ string LyXText::getStringToIndex()
        string idxstring;
        if (!bv()->selection().set())
                bv()->owner()->message(_("Nothing to index!"));
-       else if (selStart().par() != selEnd().par())
+       else if (bv()->selStart().par() != bv()->selEnd().par())
                bv()->owner()->message(_("Cannot index more than one paragraph!"));
        else
                idxstring = selectionAsString(*bv()->buffer(), false);
@@ -576,11 +576,11 @@ void LyXText::setParagraph(Spacing const & spacing, LyXAlignment align,
        string const & labelwidthstring, bool noindent)
 {
        // make sure that the depth behind the selection are restored, too
-       ParagraphList::iterator undopit = undoSpan(getPar(selEnd()));
-       recUndo(selStart().par(), parOffset(undopit) - 1);
+       ParagraphList::iterator undopit = undoSpan(getPar(bv()->selEnd()));
+       recUndo(bv()->selStart().par(), parOffset(undopit) - 1);
 
-       ParagraphList::reverse_iterator pit(getPar(selEnd().par()));
-       ParagraphList::reverse_iterator beg(getPar(selStart().par()));
+       ParagraphList::reverse_iterator pit(getPar(bv()->selEnd().par()));
+       ParagraphList::reverse_iterator beg(getPar(bv()->selStart().par()));
 
        for (--pit; pit != beg; ++pit) {
                ParagraphParameters & params = pit->params();
@@ -601,7 +601,7 @@ void LyXText::setParagraph(Spacing const & spacing, LyXAlignment align,
                params.noindent(noindent);
        }
 
-       redoParagraphs(getPar(selStart()), undopit);
+       redoParagraphs(getPar(bv()->selStart()), undopit);
 }
 
 
@@ -932,29 +932,29 @@ void LyXText::cutSelection(bool doclear, bool realcut)
        if (!bv()->selection().set())
                return;
 
-       // OK, we have a selection. This is always between selStart()
-       // and selEnd()
+       // OK, we have a selection. This is always between bv()->selStart()
+       // and bv()->selEnd()
 
        // make sure that the depth behind the selection are restored, too
-       ParagraphList::iterator begpit = getPar(selStart().par());
-       ParagraphList::iterator endpit = getPar(selEnd().par());
+       ParagraphList::iterator begpit = getPar(bv()->selStart().par());
+       ParagraphList::iterator endpit = getPar(bv()->selEnd().par());
        ParagraphList::iterator undopit = undoSpan(endpit);
-       recUndo(selStart().par(), parOffset(undopit) - 1);
+       recUndo(bv()->selStart().par(), parOffset(undopit) - 1);
 
-       int endpos = selEnd().pos();
+       int endpos = bv()->selEnd().pos();
 
        BufferParams const & bufparams = bv()->buffer()->params();
        boost::tie(endpit, endpos) = realcut ?
                CutAndPaste::cutSelection(bufparams,
                                          paragraphs(),
                                          begpit , endpit,
-                                         selStart().pos(), endpos,
+                                         bv()->selStart().pos(), endpos,
                                          bufparams.textclass,
                                          doclear)
                : CutAndPaste::eraseSelection(bufparams,
                                              paragraphs(),
                                              begpit, endpit,
-                                             selStart().pos(), endpos,
+                                             bv()->selStart().pos(), endpos,
                                              doclear);
        // sometimes necessary
        if (doclear)
@@ -982,20 +982,20 @@ void LyXText::copySelection()
        if (!bv()->selection().set())
                return;
 
-       // ok we have a selection. This is always between selStart()
+       // ok we have a selection. This is always between bv()->selStart()
        // and sel_end cursor
 
        // copy behind a space if there is one
-       while (getPar(selStart())->size() > selStart().pos()
-              && getPar(selStart())->isLineSeparator(selStart().pos())
-              && (selStart().par() != selEnd().par()
-                  || selStart().pos() < selEnd().pos()))
-               selStart().pos(selStart().pos() + 1);
-
-       CutAndPaste::copySelection(getPar(selStart().par()),
-                                  getPar(selEnd().par()),
-                                  selStart().pos(), 
-                                  selEnd().pos(),
+       while (getPar(bv()->selStart())->size() > bv()->selStart().pos()
+              && getPar(bv()->selStart())->isLineSeparator(bv()->selStart().pos())
+              && (bv()->selStart().par() != bv()->selEnd().par()
+                  || bv()->selStart().pos() < bv()->selEnd().pos()))
+               bv()->selStart().pos(bv()->selStart().pos() + 1);
+
+       CutAndPaste::copySelection(getPar(bv()->selStart().par()),
+                                  getPar(bv()->selEnd().par()),
+                                  bv()->selStart().pos(), 
+                                  bv()->selEnd().pos(),
                                   bv()->buffer()->params().textclass);
 }
 
@@ -1052,16 +1052,16 @@ void LyXText::replaceSelectionWithString(string const & str)
        freezeUndo();
 
        // Get font setting before we cut
-       pos_type pos = selEnd().pos();
-       LyXFont const font = getPar(selStart())
+       pos_type pos = bv()->selEnd().pos();
+       LyXFont const font = getPar(bv()->selStart())
                ->getFontSettings(bv()->buffer()->params(),
-                                 selStart().pos());
+                                 bv()->selStart().pos());
 
        // Insert the new string
        string::const_iterator cit = str.begin();
        string::const_iterator end = str.end();
        for (; cit != end; ++cit) {
-               getPar(selEnd())->insertChar(pos, (*cit), font);
+               getPar(bv()->selEnd())->insertChar(pos, (*cit), font);
                ++pos;
        }
 
index e48cb3acaad38f46fe4a3099e8b77a16b1ce34fe..c3e533c83890be6c8a50e25560b628ab2b406fcf 100644 (file)
@@ -1073,10 +1073,10 @@ DispatchResult LyXText::dispatch(FuncRequest const & cmd)
                bool change_layout = (current_layout != layout);
 
                if (!change_layout && bv->selection().set() &&
-                       selStart().par() != selEnd().par())
+                       bv->selStart().par() != bv->selEnd().par())
                {
-                       ParagraphList::iterator spit = getPar(selStart());
-                       ParagraphList::iterator epit = boost::next(getPar(selEnd()));
+                       ParagraphList::iterator spit = getPar(bv->selStart());
+                       ParagraphList::iterator epit = boost::next(getPar(bv->selEnd()));
                        while (spit != epit) {
                                if (spit->layout()->name() != current_layout) {
                                        change_layout = true;