]> git.lyx.org Git - lyx.git/blobdiff - src/BufferView_pimpl.C
mathed uglyfication
[lyx.git] / src / BufferView_pimpl.C
index 8b9556bb5f53934619f4970d96696df3d969b7ad..ace9dd401451713b6040c8c6f695eaceaefa0bee 100644 (file)
@@ -111,9 +111,9 @@ boost::signals::connection lostcon;
 } // anon namespace
 
 
-BufferView::Pimpl::Pimpl(BufferView * bv, LyXView * owner,
+BufferView::Pimpl::Pimpl(BufferView & bv, LyXView * owner,
             int xpos, int ypos, int width, int height)
-       : bv_(bv), owner_(owner), buffer_(0), cursor_timeout(400),
+       : bv_(&bv), owner_(owner), buffer_(0), cursor_timeout(400),
          using_xterm_cursor(false), cursor_(bv)
 {
        xsel_cache_.set = false;
@@ -160,13 +160,20 @@ void BufferView::Pimpl::connectBuffer(Buffer & buf)
        if (errorConnection_.connected())
                disconnectBuffer();
 
-       errorConnection_ = buf.error.connect(boost::bind(&BufferView::Pimpl::addError, this, _1));
-       messageConnection_ = buf.message.connect(boost::bind(&LyXView::message, owner_, _1));
-       busyConnection_ = buf.busy.connect(boost::bind(&LyXView::busy, owner_, _1));
-       titleConnection_ = buf.updateTitles.connect(boost::bind(&LyXView::updateWindowTitle, owner_));
-       timerConnection_ = buf.resetAutosaveTimers.connect(boost::bind(&LyXView::resetAutosaveTimer, owner_));
-       readonlyConnection_ = buf.readonly.connect(boost::bind(&BufferView::Pimpl::showReadonly, this, _1));
-       closingConnection_ = buf.closing.connect(boost::bind(&BufferView::Pimpl::buffer, this, (Buffer *)0));
+       errorConnection_ =
+               buf.error.connect(boost::bind(&BufferView::Pimpl::addError, this, _1));
+       messageConnection_ =
+               buf.message.connect(boost::bind(&LyXView::message, owner_, _1));
+       busyConnection_ =
+               buf.busy.connect(boost::bind(&LyXView::busy, owner_, _1));
+       titleConnection_ =
+               buf.updateTitles.connect(boost::bind(&LyXView::updateWindowTitle, owner_));
+       timerConnection_ =
+               buf.resetAutosaveTimers.connect(boost::bind(&LyXView::resetAutosaveTimer, owner_));
+       readonlyConnection_ =
+               buf.readonly.connect(boost::bind(&BufferView::Pimpl::showReadonly, this, _1));
+       closingConnection_ =
+               buf.closing.connect(boost::bind(&BufferView::Pimpl::buffer, this, (Buffer *)0));
 }
 
 
@@ -395,10 +402,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();
@@ -414,7 +421,7 @@ void BufferView::Pimpl::resizeCurrentBuffer()
                        text->setCursor(selstartpar, selstartpos);
                        bv_->resetAnchor();
                        text->setCursor(selendpar, selendpos);
-                       text->setSelection();
+                       bv_->setSelection();
                        text->setCursor(par, pos);
                } else {
                        text->setCursor(par, pos);
@@ -554,7 +561,7 @@ void BufferView::Pimpl::selectionLost()
 {
        if (available()) {
                screen().hideCursor();
-               bv_->getLyXText()->clearSelection();
+               bv_->clearSelection();
                xsel_cache_.set = false;
        }
 }
@@ -637,8 +644,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());
 }
 
 
@@ -661,7 +668,7 @@ void BufferView::Pimpl::restorePosition(unsigned int i)
 
        string const fname = saved_positions[i].filename;
 
-       bv_->text()->clearSelection();
+       bv_->clearSelection();
 
        if (fname != buffer_->fileName()) {
                Buffer * b = 0;
@@ -713,7 +720,7 @@ void BufferView::Pimpl::center()
 {
        LyXText * text = bv_->text();
 
-       text->clearSelection();
+       bv_->clearSelection();
        int const half_height = workarea().workHeight() / 2;
        int new_y = std::max(0, text->cursorY() - half_height);
 
@@ -751,7 +758,7 @@ InsetOld * BufferView::Pimpl::getInsetByCode(InsetOld::Code code)
        // should work for now. Better infrastructure is coming. (Lgb)
 
        Buffer * b = bv_->buffer();
-       LyXText * text =  bv_->getLyXText();
+       LyXText * text = bv_->getLyXText();
 
        Buffer::inset_iterator beg = b->inset_iterator_begin();
        Buffer::inset_iterator end = b->inset_iterator_end();
@@ -872,7 +879,7 @@ void BufferView::Pimpl::trackChanges()
 }
 
 #warning remove me
-LCursor theTempCursor(0);
+LCursor theTempCursor;
 
 namespace {
 
@@ -881,7 +888,7 @@ namespace {
                lyxerr << "insetFromCoords" << endl;
                LyXText * text = bv->text();
                InsetOld * inset = 0;
-               theTempCursor = LCursor(bv);
+               theTempCursor = LCursor(*bv);
                while (true) {
                        InsetOld * const inset_hit = text->checkInsetHit(x, y);
                        if (!inset_hit) {
@@ -914,16 +921,16 @@ bool BufferView::Pimpl::workAreaDispatch(FuncRequest const & cmd)
        case LFUN_MOUSE_MOTION: {
                if (!available())
                        return false;
-               FuncRequest cmd1(cmd, bv_);
+               FuncRequest cmd1 = cmd;
                UpdatableInset * inset = bv_->fullCursor().innerInset();
                DispatchResult res;
                if (inset) {
                        cmd1.x -= inset->x();
                        cmd1.y -= inset->y();
-                       res = inset->dispatch(cmd1);
+                       res = inset->dispatch(*bv_, cmd1);
                } else {
                        cmd1.y += bv_->top_y();
-                       res = bv_->fullCursor().innerText()->dispatch(cmd1);
+                       res = bv_->fullCursor().innerText()->dispatch(*bv_, cmd1);
                }
 
                if (bv_->fitCursor() || res.update()) {
@@ -955,17 +962,16 @@ bool BufferView::Pimpl::workAreaDispatch(FuncRequest const & cmd)
 
                // built temporary path to inset
                InsetOld * inset = insetFromCoords(bv_, cmd.x, cmd.y);
-               FuncRequest cmd1(cmd, bv_);
                DispatchResult res;
 
                // try to dispatch to that inset
                if (inset) {
-                       FuncRequest cmd2 = cmd1;
+                       FuncRequest cmd2 = cmd;
                        lyxerr << "dispatching action " << cmd2.action
                               << " to inset " << inset << endl;
                        cmd2.x -= inset->x();
                        cmd2.y -= inset->y();
-                       res = inset->dispatch(cmd2);
+                       res = inset->dispatch(*bv_, cmd2);
                        if (res.update()) {
                                bv_->update();
                                bv_->fullCursor().updatePos();
@@ -992,12 +998,13 @@ bool BufferView::Pimpl::workAreaDispatch(FuncRequest const & cmd)
                // otherwise set cursor to surrounding LyXText
                if (!res.dispatched()) {
                        lyxerr << "temp cursor is: " << theTempCursor << endl;
-                       lyxerr << "dispatching " << cmd1
+                       lyxerr << "dispatching " << cmd
                               << " to surrounding LyXText "
                               << theTempCursor.innerText() << endl;
                        bv_->fullCursor(theTempCursor);
+                       FuncRequest cmd1 = cmd;
                        cmd1.y += bv_->top_y();
-                       res = bv_->fullCursor().innerText()->dispatch(cmd1);
+                       res = bv_->fullCursor().innerText()->dispatch(*bv_, cmd1);
                        if (bv_->fitCursor() || res.update())
                                bv_->update();
 
@@ -1027,12 +1034,9 @@ bool BufferView::Pimpl::workAreaDispatch(FuncRequest const & cmd)
 }
 
 
-bool BufferView::Pimpl::dispatch(FuncRequest const & ev_in)
+bool BufferView::Pimpl::dispatch(FuncRequest const & ev)
 {
        // Make sure that the cached BufferView is correct.
-       FuncRequest ev = ev_in;
-       ev.setView(bv_);
-
        lyxerr[Debug::ACTION] << "BufferView::Pimpl::Dispatch:"
                << " action[" << ev.action << ']'
                << " arg[" << ev.argument << ']'
@@ -1138,13 +1142,13 @@ bool BufferView::Pimpl::dispatch(FuncRequest const & ev_in)
        case LFUN_MATH_IMPORT_SELECTION: // Imports LaTeX from the X selection
        case LFUN_MATH_DISPLAY:          // Open or create a displayed math inset
        case LFUN_MATH_MODE:             // Open or create an inlined math inset
-               mathDispatch(ev);
+               mathDispatch(*bv_, ev);
                break;
 
        case LFUN_INSET_INSERT: {
                // Same as above.
                BOOST_ASSERT(false);
-               InsetOld * inset = createInset(ev);
+               InsetOld * inset = createInset(bv_, ev);
                if (!inset || !insertInset(inset))
                        delete inset;
                break;
@@ -1236,11 +1240,38 @@ bool BufferView::Pimpl::dispatch(FuncRequest const & ev_in)
        }
 
        case LFUN_WORD_FIND:
-               lyx::find::find(ev);
+               lyx::find::find(bv_, ev);
                break;
 
        case LFUN_WORD_REPLACE:
-               lyx::find::replace(ev);
+               lyx::find::replace(bv_, ev);
+               break;
+
+       case LFUN_MARK_OFF:
+               bv_->clearSelection();
+               bv_->update();
+               bv_->resetAnchor();
+               ev.message(N_("Mark off"));
+               break;
+
+       case LFUN_MARK_ON:
+               bv_->clearSelection();
+               bv_->selection().mark(true);
+               bv_->update();
+               bv_->resetAnchor();
+               ev.message(N_("Mark on"));
+               break;
+
+       case LFUN_SETMARK:
+               bv_->clearSelection();
+               if (bv_->selection().mark()) {
+                       ev.message(N_("Mark removed"));
+               } else {
+                       bv_->selection().mark(true);
+                       ev.message(N_("Mark set"));
+               }
+               bv_->resetAnchor();
+               bv_->update();
                break;
 
        case LFUN_UNKNOWN_ACTION:
@@ -1248,7 +1279,7 @@ bool BufferView::Pimpl::dispatch(FuncRequest const & ev_in)
                break;
 
        default:
-               return bv_->getLyXText()->dispatch(FuncRequest(ev, bv_)).dispatched();
+               return bv_->getLyXText()->dispatch(*bv_, ev).dispatched();
        } // end of switch
 
        return true;
@@ -1261,7 +1292,7 @@ bool BufferView::Pimpl::insertInset(InsetOld * inset, string const & lout)
        bv_->text()->recUndo(bv_->text()->cursor().par());
        freezeUndo();
 
-       bv_->text()->clearSelection();
+       bv_->clearSelection();
        if (!lout.empty()) {
                bv_->text()->breakParagraph(bv_->buffer()->paragraphs());