#include "TextClass.h"
#include "TextMetrics.h"
#include "TexRow.h"
-#include "Undo.h"
#include "VSpace.h"
#include "WordLangTuple.h"
/// Return an inset of this class if it exists at the current cursor position
template <class T>
-T * getInsetByCode(Cursor const & cur, Inset::Code code)
+T * getInsetByCode(Cursor const & cur, InsetCode code)
{
DocIterator it = cur;
Inset * inset = it.nextInset();
}
-bool findInset(DocIterator & dit, vector<Inset_code> const & codes,
+bool findInset(DocIterator & dit, vector<InsetCode> const & codes,
bool same_content);
-bool findNextInset(DocIterator & dit, vector<Inset_code> const & codes,
+bool findNextInset(DocIterator & dit, vector<InsetCode> const & codes,
string const & contents)
{
DocIterator tmpdit = dit;
/// Looks for next inset with one of the the given code
-bool findInset(DocIterator & dit, vector<Inset_code> const & codes,
+bool findInset(DocIterator & dit, vector<InsetCode> const & codes,
bool same_content)
{
string contents;
/// Looks for next inset with the given code
-void findInset(DocIterator & dit, Inset_code code, bool same_content)
+void findInset(DocIterator & dit, InsetCode code, bool same_content)
{
- findInset(dit, vector<Inset_code>(1, code), same_content);
+ findInset(dit, vector<InsetCode>(1, code), same_content);
}
/// Moves cursor to the next inset with one of the given codes.
-void gotoInset(BufferView * bv, vector<Inset_code> const & codes,
+void gotoInset(BufferView * bv, vector<InsetCode> const & codes,
bool same_content)
{
Cursor tmpcur = bv->cursor();
/// Moves cursor to the next inset with given code.
-void gotoInset(BufferView * bv, Inset_code code, bool same_content)
+void gotoInset(BufferView * bv, InsetCode code, bool same_content)
{
- gotoInset(bv, vector<Inset_code>(1, code), same_content);
+ gotoInset(bv, vector<InsetCode>(1, code), same_content);
}
pit_type const newpit = std::distance(bgn, dest);
pit_type const len = std::distance(start, finish);
pit_type const deletepit = pit + len;
- recordUndo(cur, Undo::ATOMIC, newpit, deletepit - 1);
+ buf.undo().recordUndo(cur, ATOMIC_UNDO, newpit, deletepit - 1);
pars.insert(dest, start, finish);
start = boost::next(pars.begin(), deletepit);
pit = newpit;
// One such was found:
pit_type newpit = std::distance(bgn, dest);
pit_type const len = std::distance(start, finish);
- recordUndo(cur, Undo::ATOMIC, pit, newpit - 1);
+ buf.undo().recordUndo(cur, ATOMIC_UNDO, pit, newpit - 1);
pars.insert(dest, start, finish);
start = boost::next(bgn, pit);
pit = newpit - len;
break;
}
case OutlineIn:
- recordUndo(cur);
+ buf.undo().recordUndo(cur);
for (; lit != lend; ++lit) {
if ((*lit)->toclevel == thistoclevel + 1 &&
start->layout()->labeltype == (*lit)->labeltype) {
}
break;
case OutlineOut:
- recordUndo(cur);
+ buf.undo().recordUndo(cur);
for (; lit != lend; ++lit) {
if ((*lit)->toclevel == thistoclevel - 1 &&
start->layout()->labeltype == (*lit)->labeltype) {
//
/////////////////////////////////////////////////////////////////////
-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)
{}
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_);
// 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_;
}
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;
}
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_;
}
// 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
// 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;
}
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;
}
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();
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_;
}
<< "[ 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();
}
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:
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());
}
// 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)
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
// 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();
}
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);
}
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
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;
}
{
FuncStatus flag;
- Cursor & cur = d.cursor_;
+ Cursor & cur = d->cursor_;
switch (cmd.action) {
case LFUN_UNDO:
- flag.enabled(!buffer_.undostack().empty());
+ flag.enabled(buffer_.undo().hasUndoStack());
break;
case LFUN_REDO:
- flag.enabled(!buffer_.redostack().empty());
+ flag.enabled(buffer_.undo().hasRedoStack());
break;
case LFUN_FILE_INSERT:
case LFUN_FILE_INSERT_PLAINTEXT_PARA:
case LFUN_LABEL_GOTO: {
flag.enabled(!cmd.argument().empty()
- || getInsetByCode<InsetRef>(cur, Inset::REF_CODE));
+ || getInsetByCode<InsetRef>(cur, REF_CODE));
break;
}
break;
case LFUN_LAYOUT_TABULAR:
- flag.enabled(cur.innerInsetOfType(Inset::TABULAR_CODE));
+ flag.enabled(cur.innerInsetOfType(TABULAR_CODE));
break;
case LFUN_LAYOUT:
break;
case LFUN_INSET_SETTINGS: {
- Inset::Code code = cur.inset().lyxCode();
+ InsetCode code = cur.inset().lyxCode();
bool enable = false;
switch (code) {
- case Inset::TABULAR_CODE:
+ case TABULAR_CODE:
enable = cmd.argument() == "tabular";
break;
- case Inset::ERT_CODE:
+ case ERT_CODE:
enable = cmd.argument() == "ert";
break;
- case Inset::FLOAT_CODE:
+ case FLOAT_CODE:
enable = cmd.argument() == "float";
break;
- case Inset::WRAP_CODE:
+ case WRAP_CODE:
enable = cmd.argument() == "wrap";
break;
- case Inset::NOTE_CODE:
+ case NOTE_CODE:
enable = cmd.argument() == "note";
break;
- case Inset::BRANCH_CODE:
+ case BRANCH_CODE:
enable = cmd.argument() == "branch";
break;
- case Inset::BOX_CODE:
+ case BOX_CODE:
enable = cmd.argument() == "box";
break;
- case Inset::LISTINGS_CODE:
+ case LISTINGS_CODE:
enable = cmd.argument() == "listings";
break;
default:
}
case LFUN_DIALOG_SHOW_NEW_INSET:
- flag.enabled(cur.inset().lyxCode() != Inset::ERT_CODE &&
- cur.inset().lyxCode() != Inset::LISTINGS_CODE);
- if (cur.inset().lyxCode() == Inset::CAPTION_CODE) {
+ flag.enabled(cur.inset().lyxCode() != ERT_CODE &&
+ cur.inset().lyxCode() != LISTINGS_CODE);
+ if (cur.inset().lyxCode() == CAPTION_CODE) {
FuncStatus flag;
if (cur.inset().getStatus(cur, cmd, flag))
return flag;
<< " button[" << cmd.button() << ']'
<< endl;
- Cursor & cur = d.cursor_;
+ Cursor & cur = d->cursor_;
// Default Update flags.
Update::flags updateFlags = Update::Force | Update::FitCursor;
case LFUN_UNDO:
cur.message(_("Undo"));
cur.clearSelection();
- if (!textUndo(*this)) {
+ if (!cur.textUndo()) {
cur.message(_("No further undo information"));
updateFlags = Update::None;
}
case LFUN_REDO:
cur.message(_("Redo"));
cur.clearSelection();
- if (!textRedo(*this)) {
+ if (!cur.textRedo()) {
cur.message(_("No further redo information"));
updateFlags = Update::None;
}
docstring label = cmd.argument();
if (label.empty()) {
InsetRef * inset =
- getInsetByCode<InsetRef>(d.cursor_,
- Inset::REF_CODE);
+ getInsetByCode<InsetRef>(d->cursor_,
+ REF_CODE);
if (inset) {
label = inset->getParam("reference");
// persistent=false: use temp_bookmark
}
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;
case LFUN_NOTE_NEXT:
- gotoInset(this, Inset::NOTE_CODE, false);
+ gotoInset(this, NOTE_CODE, false);
break;
case LFUN_REFERENCE_NEXT: {
- vector<Inset_code> tmp;
- tmp.push_back(Inset::LABEL_CODE);
- tmp.push_back(Inset::REF_CODE);
+ vector<InsetCode> tmp;
+ tmp.push_back(LABEL_CODE);
+ tmp.push_back(REF_CODE);
gotoInset(this, tmp, true);
break;
}
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:
break;
case LFUN_BIBTEX_DATABASE_ADD: {
- Cursor tmpcur = d.cursor_;
- findInset(tmpcur, Inset::BIBTEX_CODE, false);
+ Cursor tmpcur = d->cursor_;
+ findInset(tmpcur, BIBTEX_CODE, false);
InsetBibtex * inset = getInsetByCode<InsetBibtex>(tmpcur,
- Inset::BIBTEX_CODE);
+ BIBTEX_CODE);
if (inset) {
if (inset->addDatabase(to_utf8(cmd.argument())))
buffer_.updateBibfilesCache();
}
case LFUN_BIBTEX_DATABASE_DEL: {
- Cursor tmpcur = d.cursor_;
- findInset(tmpcur, Inset::BIBTEX_CODE, false);
+ Cursor tmpcur = d->cursor_;
+ findInset(tmpcur, BIBTEX_CODE, false);
InsetBibtex * inset = getInsetByCode<InsetBibtex>(tmpcur,
- Inset::BIBTEX_CODE);
+ BIBTEX_CODE);
if (inset) {
if (inset->delDatabase(to_utf8(cmd.argument())))
buffer_.updateBibfilesCache();
}
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();
+ cur.finishUndo();
// The metrics are already up to date. see scroll()
updateFlags = Update::None;
break;
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_);
- finishUndo();
+ d->text_metrics_[&buffer_.text()].editXY(cur, p.x_, p.y_);
+ cur.finishUndo();
while (cur.depth() > initial_depth) {
cur.forwardInset();
}
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();
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();
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;
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.
// 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<Inset *>(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<pit_type, ParagraphMetrics const *> firstpm = tm.first();
std::pair<pit_type, ParagraphMetrics const *> 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
}
// 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();
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<pit_type, ParagraphMetrics const *> last = tm.last();
break;
tm.newParMetricsDown();
}
- d.offset_ref_ += offset;
+ d->offset_ref_ += offset;
updateMetrics(false);
buffer_.changed();
}
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<pit_type, ParagraphMetrics const *> first = tm.first();
break;
tm.newParMetricsUp();
}
- d.offset_ref_ -= offset;
+ d->offset_ref_ -= offset;
updateMetrics(false);
buffer_.changed();
}
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);
}
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<Text *>(t)))).first;
}
return tmc_it->second;
{
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;
}
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)
// 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
}
//lyxerr << "5 cur after" << dit <<std::endl;
- d.cursor_.setCursor(dit);
- d.cursor_.boundary(cur.boundary());
+ d->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();
+ d->cursor_.finishUndo();
return update;
}
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();
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
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;
// 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;
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.
<< " 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()) {
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(),
+ buffer_.undo().recordUndo(d->cursor_);
+ cap::pasteParagraphList(d->cursor_, buf.paragraphs(),
buf.params().getTextClassPtr(), el);
res = _("Document %1$s inserted.");
} else
// 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;
}
Cursor & cur = cursor();
cap::replaceSelection(cur);
- recordUndo(cur);
+ buffer_.undo().recordUndo(cur);
if (asParagraph)
cur.innerText()->insertStringAsParagraphs(cur, tmpstr);
else
cur.innerText()->insertStringAsLines(cur, tmpstr);
}
-
} // namespace lyx