X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2FBufferView_pimpl.C;h=df3527e97dd4f5a05a40c3e61f70d8dabfbb4e20;hb=a97ed20502fb6a19949cf7ef6fc18a6c6d9e347b;hp=c499fbf572b1e21d8a26fb4d4b9820b010ff9133;hpb=7de76711b14a4c0bcdf5770885be8efc59cac264;p=lyx.git diff --git a/src/BufferView_pimpl.C b/src/BufferView_pimpl.C index c499fbf572..df3527e97d 100644 --- a/src/BufferView_pimpl.C +++ b/src/BufferView_pimpl.C @@ -114,6 +114,8 @@ BufferView::Pimpl::Pimpl(BufferView * bv, LyXView * owner, : bv_(bv), owner_(owner), buffer_(0), cursor_timeout(400), using_xterm_cursor(false), cursor_(bv) { + xsel_cache_.set = false; + workarea_.reset(WorkAreaFactory::create(xpos, ypos, width, height)); screen_.reset(LyXScreenFactory::create(workarea())); @@ -293,9 +295,6 @@ void BufferView::Pimpl::buffer(Buffer * b) // set current buffer buffer_ = b; - buffer_->text().init(bv_); - buffer_->text().textwidth_ = workarea().workWidth(); - buffer_->text().fullRebreak(); top_y_ = 0; @@ -311,6 +310,10 @@ void BufferView::Pimpl::buffer(Buffer * b) lyxerr[Debug::INFO] << "Buffer addr: " << buffer_ << endl; connectBuffer(*buffer_); + buffer_->text().init(bv_); + buffer_->text().textwidth_ = workarea().workWidth(); + buffer_->text().fullRebreak(); + // If we don't have a text object for this, we make one if (bv_->text() == 0) resizeCurrentBuffer(); @@ -383,25 +386,21 @@ void BufferView::Pimpl::resizeCurrentBuffer() owner_->message(_("Formatting document...")); - lyxerr << "### resizeCurrentBuffer: text" << bv_->text() << endl; + lyxerr << "### resizeCurrentBuffer: text " << bv_->text() << endl; if (!bv_->text()) return; - //if (bv_->text()) { - par = bv_->text()->cursor.par(); - pos = bv_->text()->cursor.pos(); - selstartpar = bv_->text()->selection.start.par(); - selstartpos = bv_->text()->selection.start.pos(); - selendpar = bv_->text()->selection.end.par(); - selendpos = bv_->text()->selection.end.pos(); - selection = bv_->text()->selection.set(); - mark_set = bv_->text()->selection.mark(); - bv_->text()->fullRebreak(); - update(); - //} else { - // bv_->setText(new LyXText(bv_, 0, false, bv_->buffer()->paragraphs())); - // bv_->text()->init(bv_); - //} + par = bv_->text()->cursor.par(); + pos = bv_->text()->cursor.pos(); + selstartpar = bv_->text()->selStart().par(); + selstartpos = bv_->text()->selStart().pos(); + selendpar = bv_->text()->selEnd().par(); + selendpos = bv_->text()->selEnd().pos(); + selection = bv_->text()->selection.set(); + mark_set = bv_->text()->selection.mark(); + bv_->text()->textwidth_ = bv_->workWidth(); + bv_->text()->fullRebreak(); + update(); if (par != -1) { bv_->text()->selection.set(true); @@ -470,9 +469,9 @@ void BufferView::Pimpl::scrollDocView(int value) int const last = top_y() + workarea().workHeight() - height; LyXText * text = bv_->text(); - if (text->cursor.y() < first) + if (text->cursorY() < first) text->setCursorFromCoordinates(0, first); - else if (text->cursor.y() > last) + else if (text->cursorY() > last) text->setCursorFromCoordinates(0, last); owner_->updateLayoutChoice(); @@ -529,20 +528,22 @@ void BufferView::Pimpl::selectionRequested() LyXText * text = bv_->getLyXText(); - if (text->selection.set() && - (!bv_->text()->xsel_cache.set() || - text->selection.start != bv_->text()->xsel_cache.start || - text->selection.end != bv_->text()->xsel_cache.end)) + if (!text->selection.set()) { + xsel_cache_.set = false; + return; + } + + if (!xsel_cache_.set || + text->cursor != xsel_cache_.cursor || + text->selection.cursor != xsel_cache_.selection_cursor) { - bv_->text()->xsel_cache = text->selection; + xsel_cache_.cursor = text->cursor; + xsel_cache_.selection_cursor = text->selection.cursor; + xsel_cache_.set = text->selection.set(); sel = text->selectionAsString(*bv_->buffer(), false); - } else if (!text->selection.set()) { - sel = string(); - bv_->text()->xsel_cache.set(false); - } - if (!sel.empty()) { - workarea().putClipboard(sel); - } + if (!sel.empty()) + workarea().putClipboard(sel); + } } @@ -551,7 +552,7 @@ void BufferView::Pimpl::selectionLost() if (available()) { screen().hideCursor(); bv_->getLyXText()->clearSelection(); - bv_->text()->xsel_cache.set(false); + xsel_cache_.set = false; } } @@ -634,8 +635,8 @@ Change const BufferView::Pimpl::getCurrentChange() if (!text->selection.set()) return Change(Change::UNCHANGED); - return text->getPar(text->selection.start) - ->lookupChangeFull(text->selection.start.pos()); + return text->getPar(text->selStart()) + ->lookupChangeFull(text->selStart().pos()); } @@ -712,7 +713,7 @@ void BufferView::Pimpl::center() text->clearSelection(); int const half_height = workarea().workHeight() / 2; - int new_y = std::max(0, text->cursor.y() - half_height); + int new_y = std::max(0, text->cursorY() - half_height); // FIXME: look at this comment again ... // This updates top_y() but means the fitCursor() call @@ -753,13 +754,13 @@ InsetOld * BufferView::Pimpl::getInsetByCode(InsetOld::Code code) Buffer::inset_iterator beg = b->inset_iterator_begin(); Buffer::inset_iterator end = b->inset_iterator_end(); - bool cursorPar_seen = false; + bool cursor_par_seen = false; for (; beg != end; ++beg) { if (beg.getPar() == text->cursorPar()) { - cursorPar_seen = true; + cursor_par_seen = true; } - if (cursorPar_seen) { + if (cursor_par_seen) { if (beg.getPar() == text->cursorPar() && beg.getPos() >= text->cursor.pos()) { break; @@ -874,21 +875,25 @@ namespace { InsetOld * insetFromCoords(BufferView * bv, int x, int y) { + lyxerr << "insetFromCoords" << endl; LyXText * text = bv->text(); InsetOld * inset = 0; theTempCursor = LCursor(bv); while (true) { - InsetOld * inset_hit = text->checkInsetHit(x, y); + InsetOld * const inset_hit = text->checkInsetHit(x, y); if (!inset_hit) { lyxerr << "no further inset hit" << endl; break; } inset = inset_hit; - if (!inset_hit->descendable()) { + if (!inset->descendable()) { lyxerr << "not descendable" << endl; break; } - text = inset_hit->getText(0); + int const cell = inset->getCell(x, y + bv->top_y()); + if (cell == -1) + break; + text = inset_hit->getText(cell); lyxerr << "Hit inset: " << inset << " at x: " << x << " text: " << text << " y: " << y << endl; theTempCursor.push(static_cast(inset)); @@ -904,6 +909,8 @@ bool BufferView::Pimpl::workAreaDispatch(FuncRequest const & cmd) { switch (cmd.action) { case LFUN_MOUSE_MOTION: { + if (!available()) + return false; FuncRequest cmd1(cmd, bv_); UpdatableInset * inset = bv_->cursor().innerInset(); DispatchResult res; @@ -1130,26 +1137,6 @@ bool BufferView::Pimpl::dispatch(FuncRequest const & ev_in) mathDispatch(ev); break; - case LFUN_INSET_APPLY: { -#warning is this code ever called? - // Remove if not triggered. Mail lyx-devel if triggered. - // This code was replaced by code in text3.C. - BOOST_ASSERT(false); - string const name = ev.getArg(0); - - InsetBase * inset = owner_->getDialogs().getOpenInset(name); - if (inset) { - // This works both for 'original' and 'mathed' insets. - // Note that the localDispatch performs update also. - FuncRequest fr(bv_, LFUN_INSET_MODIFY, ev.argument); - inset->dispatch(fr); - } else { - FuncRequest fr(bv_, LFUN_INSET_INSERT, ev.argument); - dispatch(fr); - } - } - break; - case LFUN_INSET_INSERT: { // Same as above. BOOST_ASSERT(false); @@ -1258,16 +1245,6 @@ bool BufferView::Pimpl::dispatch(FuncRequest const & ev_in) bool BufferView::Pimpl::insertInset(InsetOld * inset, string const & lout) { -#ifdef LOCK - // if we are in a locking inset we should try to insert the - // inset there otherwise this is a illegal function now - if (bv_->theLockingInset()) { - if (bv_->theLockingInset()->insetAllowed(inset)) - return bv_->theLockingInset()->insertInset(bv_, inset); - return false; - } -#endif - // not quite sure if we want this... bv_->text()->recUndo(bv_->text()->cursor.par()); freezeUndo();