diff --git a/src/BufferView.cpp b/src/BufferView.cpp index 109fa8eb24..af08fd62a5 100644 --- a/src/BufferView.cpp +++ b/src/BufferView.cpp @@ -349,9 +349,9 @@ typedef std::map TextMetricsCache; // ///////////////////////////////////////////////////////////////////// -struct BufferView::BufferViewPrivate +struct BufferView::Private { - BufferViewPrivate(BufferView & bv): wh_(0), cursor_(bv), + Private(BufferView & bv): wh_(0), cursor_(bv), multiparsel_cache_(false), anchor_ref_(0), offset_ref_(0), need_centering_(false), last_inset_(0), gui_(0) {} @@ -401,14 +401,14 @@ struct BufferView::BufferViewPrivate BufferView::BufferView(Buffer & buf) - : width_(0), height_(0), buffer_(buf), d(*new BufferViewPrivate(*this)) + : width_(0), height_(0), buffer_(buf), d(new Private(*this)) { - d.xsel_cache_.set = false; - d.intl_.initKeyMapper(lyxrc.use_kbmap); + d->xsel_cache_.set = false; + d->intl_.initKeyMapper(lyxrc.use_kbmap); - d.cursor_.push(buffer_.inset()); - d.cursor_.resetAnchor(); - d.cursor_.setCurrentFont(); + d->cursor_.push(buffer_.inset()); + d->cursor_.resetAnchor(); + d->cursor_.setCurrentFont(); if (graphics::Previews::status() != LyXRC::PREVIEW_OFF) graphics::Previews::get().generateBufferPreviews(buffer_); @@ -424,33 +424,33 @@ BufferView::~BufferView() // restore to the left of the top level inset. LyX::ref().session().lastFilePos().save( support::FileName(buffer_.fileName()), - boost::tie(d.cursor_.bottom().pit(), d.cursor_.bottom().pos()) ); + boost::tie(d->cursor_.bottom().pit(), d->cursor_.bottom().pos()) ); - delete &d; + delete d; } Intl & BufferView::getIntl() { - return d.intl_; + return d->intl_; } Intl const & BufferView::getIntl() const { - return d.intl_; + return d->intl_; } CoordCache & BufferView::coordCache() { - return d.coord_cache_; + return d->coord_cache_; } CoordCache const & BufferView::coordCache() const { - return d.coord_cache_; + return d->coord_cache_; } @@ -468,12 +468,12 @@ Buffer const & BufferView::buffer() const bool BufferView::fitCursor() { - if (cursorStatus(d.cursor_) == CUR_INSIDE) { + if (cursorStatus(d->cursor_) == CUR_INSIDE) { frontend::FontMetrics const & fm = - theFontMetrics(d.cursor_.getFont()); + theFontMetrics(d->cursor_.getFont()); int const asc = fm.maxAscent(); int const des = fm.maxDescent(); - Point const p = getPos(d.cursor_, d.cursor_.boundary()); + Point const p = getPos(d->cursor_, d->cursor_.boundary()); if (p.y_ - asc >= 0 && p.y_ + des < height_) return false; } @@ -484,12 +484,12 @@ bool BufferView::fitCursor() bool BufferView::multiParSel() { - if (!d.cursor_.selection()) + if (!d->cursor_.selection()) return false; - bool ret = d.multiparsel_cache_; - d.multiparsel_cache_ = d.cursor_.selBegin().pit() != d.cursor_.selEnd().pit(); + bool ret = d->multiparsel_cache_; + d->multiparsel_cache_ = d->cursor_.selBegin().pit() != d->cursor_.selEnd().pit(); // Either this, or previous selection spans paragraphs - return ret || d.multiparsel_cache_; + return ret || d->multiparsel_cache_; } @@ -498,7 +498,7 @@ void BufferView::processUpdateFlags(Update::flags flags) // last_inset_ points to the last visited inset. This pointer may become // invalid because of keyboard editing. Since all such operations // causes screen update(), I reset last_inset_ to avoid such a problem. - d.last_inset_ = 0; + d->last_inset_ = 0; // This is close to a hot-path. LYXERR(Debug::DEBUG) << BOOST_CURRENT_FUNCTION @@ -518,12 +518,12 @@ void BufferView::processUpdateFlags(Update::flags flags) // Case when no explicit update is requested. if (!flags) { // no need to redraw anything. - d.metrics_info_.update_strategy = NoScreenUpdate; + d->metrics_info_.update_strategy = NoScreenUpdate; return; } if (flags == Update::Decoration) { - d.metrics_info_.update_strategy = DecorationUpdate; + d->metrics_info_.update_strategy = DecorationUpdate; buffer_.changed(); return; } @@ -538,12 +538,12 @@ void BufferView::processUpdateFlags(Update::flags flags) return; } if (flags & Update::Decoration) { - d.metrics_info_.update_strategy = DecorationUpdate; + d->metrics_info_.update_strategy = DecorationUpdate; buffer_.changed(); return; } // no screen update is needed. - d.metrics_info_.update_strategy = NoScreenUpdate; + d->metrics_info_.update_strategy = NoScreenUpdate; return; } @@ -578,39 +578,39 @@ void BufferView::processUpdateFlags(Update::flags flags) void BufferView::updateScrollbar() { Text & t = buffer_.text(); - TextMetrics & tm = d.text_metrics_[&t]; + TextMetrics & tm = d->text_metrics_[&t]; int const parsize = int(t.paragraphs().size() - 1); - if (d.anchor_ref_ > parsize) { - d.anchor_ref_ = parsize; - d.offset_ref_ = 0; + if (d->anchor_ref_ > parsize) { + d->anchor_ref_ = parsize; + d->offset_ref_ = 0; } LYXERR(Debug::GUI) << BOOST_CURRENT_FUNCTION << " Updating scrollbar: height: " << t.paragraphs().size() - << " curr par: " << d.cursor_.bottom().pit() + << " curr par: " << d->cursor_.bottom().pit() << " default height " << defaultRowHeight() << endl; // It would be better to fix the scrollbar to understand // values in [0..1] and divide everything by wh // estimated average paragraph height: - if (d.wh_ == 0) - d.wh_ = height_ / 4; + if (d->wh_ == 0) + d->wh_ = height_ / 4; - int h = tm.parMetrics(d.anchor_ref_).height(); + int h = tm.parMetrics(d->anchor_ref_).height(); // Normalize anchor/offset (MV): - while (d.offset_ref_ > h && d.anchor_ref_ < parsize) { - d.anchor_ref_++; - d.offset_ref_ -= h; - h = tm.parMetrics(d.anchor_ref_).height(); + while (d->offset_ref_ > h && d->anchor_ref_ < parsize) { + d->anchor_ref_++; + d->offset_ref_ -= h; + h = tm.parMetrics(d->anchor_ref_).height(); } // Look at paragraph heights on-screen int sumh = 0; int nh = 0; - for (pit_type pit = d.anchor_ref_; pit <= parsize; ++pit) { + for (pit_type pit = d->anchor_ref_; pit <= parsize; ++pit) { if (sumh > height_) break; int const h2 = tm.parMetrics(pit).height(); @@ -621,19 +621,19 @@ void BufferView::updateScrollbar() BOOST_ASSERT(nh); int const hav = sumh / nh; // More realistic average paragraph height - if (hav > d.wh_) - d.wh_ = hav; + if (hav > d->wh_) + d->wh_ = hav; BOOST_ASSERT(h); - d.scrollbarParameters_.height = (parsize + 1) * d.wh_; - d.scrollbarParameters_.position = d.anchor_ref_ * d.wh_ + int(d.offset_ref_ * d.wh_ / float(h)); - d.scrollbarParameters_.lineScrollHeight = int(d.wh_ * defaultRowHeight() / float(h)); + d->scrollbarParameters_.height = (parsize + 1) * d->wh_; + d->scrollbarParameters_.position = d->anchor_ref_ * d->wh_ + int(d->offset_ref_ * d->wh_ / float(h)); + d->scrollbarParameters_.lineScrollHeight = int(d->wh_ * defaultRowHeight() / float(h)); } ScrollbarParameters const & BufferView::scrollbarParameters() const { - return d.scrollbarParameters_; + return d->scrollbarParameters_; } @@ -643,17 +643,17 @@ void BufferView::scrollDocView(int value) << "[ value = " << value << "]" << endl; Text & t = buffer_.text(); - TextMetrics & tm = d.text_metrics_[&t]; + TextMetrics & tm = d->text_metrics_[&t]; - float const bar = value / float(d.wh_ * t.paragraphs().size()); + float const bar = value / float(d->wh_ * t.paragraphs().size()); - d.anchor_ref_ = int(bar * t.paragraphs().size()); - if (d.anchor_ref_ > int(t.paragraphs().size()) - 1) - d.anchor_ref_ = int(t.paragraphs().size()) - 1; + d->anchor_ref_ = int(bar * t.paragraphs().size()); + if (d->anchor_ref_ > int(t.paragraphs().size()) - 1) + d->anchor_ref_ = int(t.paragraphs().size()) - 1; - tm.redoParagraph(d.anchor_ref_); - int const h = tm.parMetrics(d.anchor_ref_).height(); - d.offset_ref_ = int((bar * t.paragraphs().size() - d.anchor_ref_) * h); + tm.redoParagraph(d->anchor_ref_); + int const h = tm.parMetrics(d->anchor_ref_).height(); + d->offset_ref_ = int((bar * t.paragraphs().size() - d->anchor_ref_) * h); updateMetrics(false); buffer_.changed(); } @@ -661,12 +661,12 @@ void BufferView::scrollDocView(int value) void BufferView::setCursorFromScrollbar() { - TextMetrics & tm = d.text_metrics_[&buffer_.text()]; + TextMetrics & tm = d->text_metrics_[&buffer_.text()]; int const height = 2 * defaultRowHeight(); int const first = height; int const last = height_ - height; - Cursor & cur = d.cursor_; + Cursor & cur = d->cursor_; switch (cursorStatus(cur)) { case CUR_ABOVE: @@ -696,10 +696,10 @@ void BufferView::setCursorFromScrollbar() Change const BufferView::getCurrentChange() const { - if (!d.cursor_.selection()) + if (!d->cursor_.selection()) return Change(Change::UNCHANGED); - DocIterator dit = d.cursor_.selectionBegin(); + DocIterator dit = d->cursor_.selectionBegin(); return dit.paragraph().lookupChange(dit.pos()); } @@ -725,10 +725,10 @@ void BufferView::saveBookmark(unsigned int idx) // when lyx exits. LyX::ref().session().bookmarks().save( FileName(buffer_.fileName()), - d.cursor_.bottom().pit(), - d.cursor_.bottom().pos(), - d.cursor_.paragraph().id(), - d.cursor_.pos(), + d->cursor_.bottom().pit(), + d->cursor_.bottom().pos(), + d->cursor_.paragraph().id(), + d->cursor_.pos(), idx ); if (idx) @@ -743,7 +743,7 @@ bool BufferView::moveToPosition(pit_type bottom_pit, pos_type bottom_pos, bool success = false; DocIterator doc_it; - d.cursor_.clearSelection(); + d->cursor_.clearSelection(); // if a valid par_id is given, try it first // This is the case for a 'live' bookmark when unique paragraph ID @@ -785,7 +785,7 @@ bool BufferView::moveToPosition(pit_type bottom_pit, pos_type bottom_pos, // Note: only bottom (document) level pit is set. setCursor(doc_it); // set the current font. - d.cursor_.setCurrentFont(); + d->cursor_.setCurrentFont(); // center the screen on this new position. center(); } @@ -797,16 +797,16 @@ bool BufferView::moveToPosition(pit_type bottom_pit, pos_type bottom_pos, void BufferView::translateAndInsert(char_type c, Text * t, Cursor & cur) { if (lyxrc.rtl_support) { - if (d.cursor_.real_current_font.isRightToLeft()) { - if (d.intl_.keymap == Intl::PRIMARY) - d.intl_.keyMapSec(); + if (d->cursor_.real_current_font.isRightToLeft()) { + if (d->intl_.keymap == Intl::PRIMARY) + d->intl_.keyMapSec(); } else { - if (d.intl_.keymap == Intl::SECONDARY) - d.intl_.keyMapPrim(); + if (d->intl_.keymap == Intl::SECONDARY) + d->intl_.keyMapPrim(); } } - d.intl_.getTransManager().translateAndInsert(c, t, cur); + d->intl_.getTransManager().translateAndInsert(c, t, cur); } @@ -818,8 +818,8 @@ int BufferView::workWidth() const void BufferView::updateOffsetRef() { - // No need to update d.offset_ref_ in this case. - if (!d.need_centering_) + // No need to update d->offset_ref_ in this case. + if (!d->need_centering_) return; // We are not properly started yet, delay until resizing is @@ -827,20 +827,20 @@ void BufferView::updateOffsetRef() if (height_ == 0) return; - CursorSlice & bot = d.cursor_.bottom(); - TextMetrics & tm = d.text_metrics_[bot.text()]; + CursorSlice & bot = d->cursor_.bottom(); + TextMetrics & tm = d->text_metrics_[bot.text()]; ParagraphMetrics const & pm = tm.parMetrics(bot.pit()); - int y = coordOffset(d.cursor_, d.cursor_.boundary()).y_; - d.offset_ref_ = y + pm.ascent() - height_ / 2; + int y = coordOffset(d->cursor_, d->cursor_.boundary()).y_; + d->offset_ref_ = y + pm.ascent() - height_ / 2; - d.need_centering_ = false; + d->need_centering_ = false; } void BufferView::center() { - d.anchor_ref_ = d.cursor_.bottom().pit(); - d.need_centering_ = true; + d->anchor_ref_ = d->cursor_.bottom().pit(); + d->need_centering_ = true; } @@ -848,7 +848,7 @@ FuncStatus BufferView::getStatus(FuncRequest const & cmd) { FuncStatus flag; - Cursor & cur = d.cursor_; + Cursor & cur = d->cursor_; switch (cmd.action) { @@ -1009,7 +1009,7 @@ Update::flags BufferView::dispatch(FuncRequest const & cmd) << " button[" << cmd.button() << ']' << endl; - Cursor & cur = d.cursor_; + Cursor & cur = d->cursor_; // Default Update flags. Update::flags updateFlags = Update::Force | Update::FitCursor; @@ -1060,7 +1060,7 @@ Update::flags BufferView::dispatch(FuncRequest const & cmd) docstring label = cmd.argument(); if (label.empty()) { InsetRef * inset = - getInsetByCode(d.cursor_, + getInsetByCode(d->cursor_, Inset::REF_CODE); if (inset) { label = inset->getParam("reference"); @@ -1109,21 +1109,21 @@ Update::flags BufferView::dispatch(FuncRequest const & cmd) } case LFUN_OUTLINE_UP: - outline(OutlineUp, d.cursor_); - d.cursor_.text()->setCursor(d.cursor_, d.cursor_.pit(), 0); + outline(OutlineUp, d->cursor_); + d->cursor_.text()->setCursor(d->cursor_, d->cursor_.pit(), 0); updateLabels(buffer_); break; case LFUN_OUTLINE_DOWN: - outline(OutlineDown, d.cursor_); - d.cursor_.text()->setCursor(d.cursor_, d.cursor_.pit(), 0); + outline(OutlineDown, d->cursor_); + d->cursor_.text()->setCursor(d->cursor_, d->cursor_.pit(), 0); updateLabels(buffer_); break; case LFUN_OUTLINE_IN: - outline(OutlineIn, d.cursor_); + outline(OutlineIn, d->cursor_); updateLabels(buffer_); break; case LFUN_OUTLINE_OUT: - outline(OutlineOut, d.cursor_); + outline(OutlineOut, d->cursor_); updateLabels(buffer_); break; @@ -1177,21 +1177,21 @@ Update::flags BufferView::dispatch(FuncRequest const & cmd) case LFUN_ALL_CHANGES_ACCEPT: // select complete document - d.cursor_.reset(buffer_.inset()); - d.cursor_.selHandle(true); - buffer_.text().cursorBottom(d.cursor_); + d->cursor_.reset(buffer_.inset()); + d->cursor_.selHandle(true); + buffer_.text().cursorBottom(d->cursor_); // accept everything in a single step to support atomic undo - buffer_.text().acceptOrRejectChanges(d.cursor_, Text::ACCEPT); + buffer_.text().acceptOrRejectChanges(d->cursor_, Text::ACCEPT); break; case LFUN_ALL_CHANGES_REJECT: // select complete document - d.cursor_.reset(buffer_.inset()); - d.cursor_.selHandle(true); - buffer_.text().cursorBottom(d.cursor_); + d->cursor_.reset(buffer_.inset()); + d->cursor_.selHandle(true); + buffer_.text().cursorBottom(d->cursor_); // reject everything in a single step to support atomic undo // Note: reject does not work recursively; the user may have to repeat the operation - buffer_.text().acceptOrRejectChanges(d.cursor_, Text::REJECT); + buffer_.text().acceptOrRejectChanges(d->cursor_, Text::REJECT); break; case LFUN_WORD_FIND: @@ -1244,7 +1244,7 @@ Update::flags BufferView::dispatch(FuncRequest const & cmd) break; case LFUN_BIBTEX_DATABASE_ADD: { - Cursor tmpcur = d.cursor_; + Cursor tmpcur = d->cursor_; findInset(tmpcur, Inset::BIBTEX_CODE, false); InsetBibtex * inset = getInsetByCode(tmpcur, Inset::BIBTEX_CODE); @@ -1256,7 +1256,7 @@ Update::flags BufferView::dispatch(FuncRequest const & cmd) } case LFUN_BIBTEX_DATABASE_DEL: { - Cursor tmpcur = d.cursor_; + Cursor tmpcur = d->cursor_; findInset(tmpcur, Inset::BIBTEX_CODE, false); InsetBibtex * inset = getInsetByCode(tmpcur, Inset::BIBTEX_CODE); @@ -1344,7 +1344,7 @@ Update::flags BufferView::dispatch(FuncRequest const & cmd) } scroll(cmd.action == LFUN_SCREEN_UP? - height_ : height_); cur.reset(buffer_.inset()); - d.text_metrics_[&buffer_.text()].editXY(cur, p.x_, p.y_); + d->text_metrics_[&buffer_.text()].editXY(cur, p.x_, p.y_); //FIXME: what to do with cur.x_target()? finishUndo(); // The metrics are already up to date. see scroll() @@ -1360,7 +1360,7 @@ Update::flags BufferView::dispatch(FuncRequest const & cmd) scroll(cmd.action == LFUN_SCREEN_UP_SELECT? - height_ : height_); // FIXME: We need to verify if the cursor stayed within an inset... //cur.reset(buffer_.inset()); - d.text_metrics_[&buffer_.text()].editXY(cur, p.x_, p.y_); + d->text_metrics_[&buffer_.text()].editXY(cur, p.x_, p.y_); finishUndo(); while (cur.depth() > initial_depth) { cur.forwardInset(); @@ -1381,20 +1381,20 @@ Update::flags BufferView::dispatch(FuncRequest const & cmd) docstring const BufferView::requestSelection() { - Cursor & cur = d.cursor_; + Cursor & cur = d->cursor_; if (!cur.selection()) { - d.xsel_cache_.set = false; + d->xsel_cache_.set = false; return docstring(); } - if (!d.xsel_cache_.set || - cur.top() != d.xsel_cache_.cursor || - cur.anchor_.top() != d.xsel_cache_.anchor) + if (!d->xsel_cache_.set || + cur.top() != d->xsel_cache_.cursor || + cur.anchor_.top() != d->xsel_cache_.anchor) { - d.xsel_cache_.cursor = cur.top(); - d.xsel_cache_.anchor = cur.anchor_.top(); - d.xsel_cache_.set = cur.selection(); + d->xsel_cache_.cursor = cur.top(); + d->xsel_cache_.anchor = cur.anchor_.top(); + d->xsel_cache_.set = cur.selection(); return cur.selectionAsString(false); } return docstring(); @@ -1403,12 +1403,12 @@ docstring const BufferView::requestSelection() void BufferView::clearSelection() { - d.cursor_.clearSelection(); + d->cursor_.clearSelection(); // Clear the selection buffer. Otherwise a subsequent // middle-mouse-button paste would use the selection buffer, // not the more current external selection. cap::clearSelection(); - d.xsel_cache_.set = false; + d->xsel_cache_.set = false; // The buffer did not really change, but this causes the // redraw we need because we cleared the selection above. buffer_.changed(); @@ -1427,7 +1427,7 @@ void BufferView::resize(int width, int height) Inset const * BufferView::getCoveringInset(Text const & text, int x, int y) { - TextMetrics & tm = d.text_metrics_[&text]; + TextMetrics & tm = d->text_metrics_[&text]; Inset * inset = tm.checkInsetHit(x, y); if (!inset) return 0; @@ -1464,7 +1464,7 @@ void BufferView::mouseEventDispatch(FuncRequest const & cmd0) Cursor cur(*this); cur.push(buffer_.inset()); - cur.selection() = d.cursor_.selection(); + cur.selection() = d->cursor_.selection(); // Either the inset under the cursor or the // surrounding Text will handle this event. @@ -1477,36 +1477,36 @@ void BufferView::mouseEventDispatch(FuncRequest const & cmd0) // Get inset under mouse, if there is one. Inset const * covering_inset = getCoveringInset(buffer_.text(), cmd.x, cmd.y); - if (covering_inset == d.last_inset_) + if (covering_inset == d->last_inset_) // Same inset, no need to do anything... return; bool need_redraw = false; // const_cast because of setMouseHover(). Inset * inset = const_cast(covering_inset); - if (d.last_inset_) + if (d->last_inset_) // Remove the hint on the last hovered inset (if any). - need_redraw |= d.last_inset_->setMouseHover(false); + need_redraw |= d->last_inset_->setMouseHover(false); if (inset) // Highlighted the newly hovered inset (if any). need_redraw |= inset->setMouseHover(true); - d.last_inset_ = inset; + d->last_inset_ = inset; if (!need_redraw) return; // if last metrics update was in singlepar mode, WorkArea::redraw() will // not expose the button for redraw. We adjust here the metrics dimension // to enable a full redraw in any case as this is not costly. - TextMetrics & tm = d.text_metrics_[&buffer_.text()]; + TextMetrics & tm = d->text_metrics_[&buffer_.text()]; std::pair firstpm = tm.first(); std::pair lastpm = tm.last(); int y1 = firstpm.second->position() - firstpm.second->ascent(); int y2 = lastpm.second->position() + lastpm.second->descent(); - d.metrics_info_ = ViewMetricsInfo(firstpm.first, lastpm.first, y1, y2, + d->metrics_info_ = ViewMetricsInfo(firstpm.first, lastpm.first, y1, y2, FullScreenUpdate, buffer_.text().paragraphs().size()); // Reinitialize anchor to first pit. - d.anchor_ref_ = firstpm.first; - d.offset_ref_ = -y1; + d->anchor_ref_ = firstpm.first; + d->offset_ref_ = -y1; LYXERR(Debug::PAINTING) << "Mouse hover detected at: (" << cmd.x << ", " << cmd.y << ")" << "\nTriggering redraw: y1: " << y1 << " y2: " << y2 @@ -1519,7 +1519,7 @@ void BufferView::mouseEventDispatch(FuncRequest const & cmd0) } // Build temporary cursor. - Inset * inset = d.text_metrics_[&buffer_.text()].editXY(cur, cmd.x, cmd.y); + Inset * inset = d->text_metrics_[&buffer_.text()].editXY(cur, cmd.x, cmd.y); // Put anchor at the same position. cur.resetAnchor(); @@ -1559,7 +1559,7 @@ void BufferView::scroll(int y) void BufferView::scrollDown(int offset) { Text * text = &buffer_.text(); - TextMetrics & tm = d.text_metrics_[text]; + TextMetrics & tm = d->text_metrics_[text]; int ymax = height_ + offset; while (true) { std::pair last = tm.last(); @@ -1574,7 +1574,7 @@ void BufferView::scrollDown(int offset) break; tm.newParMetricsDown(); } - d.offset_ref_ += offset; + d->offset_ref_ += offset; updateMetrics(false); buffer_.changed(); } @@ -1583,7 +1583,7 @@ void BufferView::scrollDown(int offset) void BufferView::scrollUp(int offset) { Text * text = &buffer_.text(); - TextMetrics & tm = d.text_metrics_[text]; + TextMetrics & tm = d->text_metrics_[text]; int ymin = - offset; while (true) { std::pair first = tm.first(); @@ -1598,7 +1598,7 @@ void BufferView::scrollUp(int offset) break; tm.newParMetricsUp(); } - d.offset_ref_ -= offset; + d->offset_ref_ -= offset; updateMetrics(false); buffer_.changed(); } @@ -1611,11 +1611,11 @@ void BufferView::setCursorFromRow(int row) buffer_.texrow().getIdFromRow(row, tmpid, tmppos); - d.cursor_.reset(buffer_.inset()); + d->cursor_.reset(buffer_.inset()); if (tmpid == -1) - buffer_.text().setCursor(d.cursor_, 0, 0); + buffer_.text().setCursor(d->cursor_, 0, 0); else - buffer_.text().setCursor(d.cursor_, buffer_.getParFromID(tmpid).pit(), tmppos); + buffer_.text().setCursor(d->cursor_, buffer_.getParFromID(tmpid).pit(), tmppos); } @@ -1641,9 +1641,9 @@ TextMetrics const & BufferView::textMetrics(Text const * t) const TextMetrics & BufferView::textMetrics(Text const * t) { - TextMetricsCache::iterator tmc_it = d.text_metrics_.find(t); - if (tmc_it == d.text_metrics_.end()) { - tmc_it = d.text_metrics_.insert( + TextMetricsCache::iterator tmc_it = d->text_metrics_.find(t); + if (tmc_it == d->text_metrics_.end()) { + tmc_it = d->text_metrics_.insert( make_pair(t, TextMetrics(this, const_cast(t)))).first; } return tmc_it->second; @@ -1667,10 +1667,10 @@ void BufferView::setCursor(DocIterator const & dit) { size_t const n = dit.depth(); for (size_t i = 0; i < n; ++i) - dit[i].inset().edit(d.cursor_, true); + dit[i].inset().edit(d->cursor_, true); - d.cursor_.setCursor(dit); - d.cursor_.selection() = false; + d->cursor_.setCursor(dit); + d->cursor_.selection() = false; } @@ -1681,7 +1681,7 @@ bool BufferView::checkDepm(Cursor & cur, Cursor & old) return false; bool need_anchor_change = false; - bool changed = d.cursor_.text()->deleteEmptyParagraphMechanism(cur, old, + bool changed = d->cursor_.text()->deleteEmptyParagraphMechanism(cur, old, need_anchor_change); if (need_anchor_change) @@ -1709,20 +1709,20 @@ bool BufferView::mouseSetCursor(Cursor & cur, bool select) // Has the cursor just left the inset? bool badcursor = false; - bool leftinset = (&d.cursor_.inset() != &cur.inset()); + bool leftinset = (&d->cursor_.inset() != &cur.inset()); if (leftinset) - badcursor = notifyCursorLeaves(d.cursor_, cur); + badcursor = notifyCursorLeaves(d->cursor_, cur); // FIXME: shift-mouse selection doesn't work well across insets. - bool do_selection = select && &d.cursor_.anchor().inset() == &cur.inset(); + bool do_selection = select && &d->cursor_.anchor().inset() == &cur.inset(); // do the dEPM magic if needed // FIXME: (1) move this to InsetText::notifyCursorLeaves? // FIXME: (2) if we had a working InsetText::notifyCursorLeaves, // the leftinset bool would not be necessary (badcursor instead). bool update = leftinset; - if (!do_selection && !badcursor && d.cursor_.inTexted()) - update |= checkDepm(cur, d.cursor_); + if (!do_selection && !badcursor && d->cursor_.inTexted()) + update |= checkDepm(cur, d->cursor_); // if the cursor was in an empty script inset and the new // position is in the nucleus of the inset, notifyCursorLeaves @@ -1741,12 +1741,12 @@ bool BufferView::mouseSetCursor(Cursor & cur, bool select) } //lyxerr << "5 cur after" << dit <cursor_.setCursor(dit); + d->cursor_.boundary(cur.boundary()); if (do_selection) - d.cursor_.setSelection(); + d->cursor_.setSelection(); else - d.cursor_.clearSelection(); + d->cursor_.clearSelection(); finishUndo(); return update; @@ -1756,48 +1756,48 @@ bool BufferView::mouseSetCursor(Cursor & cur, bool select) void BufferView::putSelectionAt(DocIterator const & cur, int length, bool backwards) { - d.cursor_.clearSelection(); + d->cursor_.clearSelection(); setCursor(cur); if (length) { if (backwards) { - d.cursor_.pos() += length; - d.cursor_.setSelection(d.cursor_, -length); + d->cursor_.pos() += length; + d->cursor_.setSelection(d->cursor_, -length); } else - d.cursor_.setSelection(d.cursor_, length); + d->cursor_.setSelection(d->cursor_, length); } } Cursor & BufferView::cursor() { - return d.cursor_; + return d->cursor_; } Cursor const & BufferView::cursor() const { - return d.cursor_; + return d->cursor_; } pit_type BufferView::anchor_ref() const { - return d.anchor_ref_; + return d->anchor_ref_; } ViewMetricsInfo const & BufferView::viewMetricsInfo() { - return d.metrics_info_; + return d->metrics_info_; } bool BufferView::singleParUpdate() { Text & buftext = buffer_.text(); - pit_type const bottom_pit = d.cursor_.bottom().pit(); + pit_type const bottom_pit = d->cursor_.bottom().pit(); TextMetrics & tm = textMetrics(&buftext); int old_height = tm.parMetrics(bottom_pit).height(); @@ -1814,7 +1814,7 @@ bool BufferView::singleParUpdate() int y1 = pm.position() - pm.ascent(); int y2 = pm.position() + pm.descent(); - d.metrics_info_ = ViewMetricsInfo(bottom_pit, bottom_pit, y1, y2, + d->metrics_info_ = ViewMetricsInfo(bottom_pit, bottom_pit, y1, y2, SingleParUpdate, buftext.paragraphs().size()); LYXERR(Debug::PAINTING) << BOOST_CURRENT_FUNCTION @@ -1836,22 +1836,22 @@ void BufferView::updateMetrics(bool singlepar) Text & buftext = buffer_.text(); pit_type const npit = int(buftext.paragraphs().size()); - if (d.anchor_ref_ > int(npit - 1)) { - d.anchor_ref_ = int(npit - 1); - d.offset_ref_ = 0; + if (d->anchor_ref_ > int(npit - 1)) { + d->anchor_ref_ = int(npit - 1); + d->offset_ref_ = 0; } // Clear out the position cache in case of full screen redraw, - d.coord_cache_.clear(); + d->coord_cache_.clear(); // Clear out paragraph metrics to avoid having invalid metrics // in the cache from paragraphs not relayouted below // The complete text metrics will be redone. - d.text_metrics_.clear(); + d->text_metrics_.clear(); TextMetrics & tm = textMetrics(&buftext); - pit_type const pit = d.anchor_ref_; + pit_type const pit = d->anchor_ref_; int pit1 = pit; int pit2 = pit; @@ -1861,7 +1861,7 @@ void BufferView::updateMetrics(bool singlepar) // Take care of anchor offset if case a recentering is needed. updateOffsetRef(); - int y0 = tm.parMetrics(pit).ascent() - d.offset_ref_; + int y0 = tm.parMetrics(pit).ascent() - d->offset_ref_; // Redo paragraphs above anchor if necessary. int y1 = y0; @@ -1876,14 +1876,14 @@ void BufferView::updateMetrics(bool singlepar) y1 -= tm.parMetrics(pit1).ascent(); // Normalize anchor for next time - d.anchor_ref_ = pit1; - d.offset_ref_ = -y1; + d->anchor_ref_ = pit1; + d->offset_ref_ = -y1; // Grey at the beginning is ugly if (pit1 == 0 && y1 > 0) { y0 -= y1; y1 = 0; - d.anchor_ref_ = 0; + d->anchor_ref_ = 0; } // Redo paragraphs below the anchor if necessary. @@ -1908,19 +1908,19 @@ void BufferView::updateMetrics(bool singlepar) << " singlepar: 0" << endl; - d.metrics_info_ = ViewMetricsInfo(pit1, pit2, y1, y2, + d->metrics_info_ = ViewMetricsInfo(pit1, pit2, y1, y2, FullScreenUpdate, npit); if (lyxerr.debugging(Debug::WORKAREA)) { LYXERR(Debug::WORKAREA) << "BufferView::updateMetrics" << endl; - d.coord_cache_.dump(); + d->coord_cache_.dump(); } } void BufferView::menuInsertLyXFile(string const & filenm) { - BOOST_ASSERT(d.cursor_.inTexted()); + BOOST_ASSERT(d->cursor_.inTexted()); string filename = filenm; if (filename.empty()) { @@ -1973,8 +1973,8 @@ void BufferView::menuInsertLyXFile(string const & filenm) ErrorList & el = buffer_.errorList("Parse"); // Copy the inserted document error list into the current buffer one. el = buf.errorList("Parse"); - recordUndo(d.cursor_); - cap::pasteParagraphList(d.cursor_, buf.paragraphs(), + recordUndo(d->cursor_); + cap::pasteParagraphList(d->cursor_, buf.paragraphs(), buf.params().getTextClassPtr(), el); res = _("Document %1$s inserted."); } else @@ -2097,79 +2097,79 @@ void BufferView::draw(frontend::Painter & pain) // FIXME: We should also distinguish DecorationUpdate to avoid text // drawing if possible. This is not possible to do easily right now // because of the single backing pixmap. - pi.full_repaint = d.metrics_info_.update_strategy != SingleParUpdate; + pi.full_repaint = d->metrics_info_.update_strategy != SingleParUpdate; if (pi.full_repaint) // Clear background (if not delegated to rows) - pain.fillRectangle(0, d.metrics_info_.y1, width_, - d.metrics_info_.y2 - d.metrics_info_.y1, + pain.fillRectangle(0, d->metrics_info_.y1, width_, + d->metrics_info_.y2 - d->metrics_info_.y1, buffer_.inset().backgroundColor()); LYXERR(Debug::PAINTING) << "\t\t*** START DRAWING ***" << endl; Text & text = buffer_.text(); - TextMetrics const & tm = d.text_metrics_[&text]; - int y = d.metrics_info_.y1 + tm.parMetrics(d.metrics_info_.p1).ascent(); + TextMetrics const & tm = d->text_metrics_[&text]; + int y = d->metrics_info_.y1 + tm.parMetrics(d->metrics_info_.p1).ascent(); if (!pi.full_repaint) - tm.drawParagraph(pi, d.metrics_info_.p1, 0, y); + tm.drawParagraph(pi, d->metrics_info_.p1, 0, y); else tm.draw(pi, 0, y); LYXERR(Debug::PAINTING) << "\n\t\t*** END DRAWING ***" << endl; // and grey out above (should not happen later) -// lyxerr << "par ascent: " << text.getPar(d.metrics_info_.p1).ascent() << endl; - if (d.metrics_info_.y1 > 0 - && d.metrics_info_.update_strategy == FullScreenUpdate) - pain.fillRectangle(0, 0, width_, d.metrics_info_.y1, Color::bottomarea); +// lyxerr << "par ascent: " << text.getPar(d->metrics_info_.p1).ascent() << endl; + if (d->metrics_info_.y1 > 0 + && d->metrics_info_.update_strategy == FullScreenUpdate) + pain.fillRectangle(0, 0, width_, d->metrics_info_.y1, Color::bottomarea); // and possibly grey out below -// lyxerr << "par descent: " << text.getPar(d.metrics_info_.p1).ascent() << endl; - if (d.metrics_info_.y2 < height_ - && d.metrics_info_.update_strategy == FullScreenUpdate) - pain.fillRectangle(0, d.metrics_info_.y2, width_, - height_ - d.metrics_info_.y2, Color::bottomarea); +// lyxerr << "par descent: " << text.getPar(d->metrics_info_.p1).ascent() << endl; + if (d->metrics_info_.y2 < height_ + && d->metrics_info_.update_strategy == FullScreenUpdate) + pain.fillRectangle(0, d->metrics_info_.y2, width_, + height_ - d->metrics_info_.y2, Color::bottomarea); } void BufferView::message(docstring const & msg) { - if (d.gui_) - d.gui_->message(msg); + if (d->gui_) + d->gui_->message(msg); } void BufferView::showDialog(std::string const & name) { - if (d.gui_) - d.gui_->showDialog(name); + if (d->gui_) + d->gui_->showDialog(name); } void BufferView::showDialogWithData(std::string const & name, std::string const & data) { - if (d.gui_) - d.gui_->showDialogWithData(name, data); + if (d->gui_) + d->gui_->showDialogWithData(name, data); } void BufferView::showInsetDialog(std::string const & name, std::string const & data, Inset * inset) { - if (d.gui_) - d.gui_->showInsetDialog(name, data, inset); + if (d->gui_) + d->gui_->showInsetDialog(name, data, inset); } void BufferView::updateDialog(std::string const & name, std::string const & data) { - if (d.gui_) - d.gui_->updateDialog(name, data); + if (d->gui_) + d->gui_->updateDialog(name, data); } void BufferView::setGuiDelegate(frontend::GuiBufferViewDelegate * gui) { - d.gui_ = gui; + d->gui_ = gui; } diff --git a/src/BufferView.h b/src/BufferView.h index df58d927e4..5ed29beecd 100644 --- a/src/BufferView.h +++ b/src/BufferView.h @@ -290,8 +290,8 @@ private: void updateOffsetRef(); - struct BufferViewPrivate; - BufferViewPrivate & d; + struct Private; + Private * const d; }; /// some space for drawing the 'nested' markers (in pixel)