using lyx::support::bformat;
using lyx::support::MakeAbsPath;
+using std::distance;
using std::find;
using std::string;
+using std::swap;
using std::vector;
BufferView::BufferView(LyXView * owner, int xpos, int ypos,
int width, int height)
- : pimpl_(new Pimpl(this, owner, xpos, ypos, width, height)),
- x_target_(0)
+ : pimpl_(new Pimpl(*this, owner, xpos, ypos, width, height))
{}
string const fname = MakeAbsPath(filen);
- clearSelection();
+ cursor().clearSelection();
text()->breakParagraph(buffer()->paragraphs());
bool res = buffer()->readFile(fname, text()->cursorPar());
}
-bool BufferView::insertInset(InsetOld * inset, string const & lout)
+bool BufferView::insertInset(InsetBase * inset, string const & lout)
{
return pimpl_->insertInset(inset, lout);
}
vector<string> labels;
it->getLabelList(*buffer(), labels);
if (find(labels.begin(),labels.end(),label) != labels.end()) {
- clearSelection();
+ cursor().clearSelection();
text()->setCursor(
- std::distance(text()->paragraphs().begin(), it.getPar()),
+ distance(text()->paragraphs().begin(), it.getPar()),
it.getPos());
- resetAnchor();
+ cursor().resetAnchor();
update();
return;
}
return;
owner()->message(_("Undo"));
- clearSelection();
- if (!textUndo(this))
+ cursor().clearSelection();
+ if (!textUndo(*this))
owner()->message(_("No further undo information"));
update();
switchKeyMap();
return;
owner()->message(_("Redo"));
- clearSelection();
- if (!textRedo(this))
+ cursor().clearSelection();
+ if (!textRedo(*this))
owner()->message(_("No further redo information"));
update();
switchKeyMap();
}
-UpdatableInset * BufferView::innerInset() const
-{
- return static_cast<UpdatableInset*>(fullCursor().innerInset());
-}
-
-
LyXText * BufferView::getLyXText() const
{
- return fullCursor().innerText();
+ return cursor().innerText();
}
LyXText * t = getLyXText();
if (!t)
return 0;
- return t->cursorPar()->getFont(
- buffer()->params(),
- t->cursor().pos(),
- outerFont(t->cursorPar(), t->paragraphs())
+ CursorSlice const & cur = cursor().innerTextSlice();
+ return t->getPar(cur.par())->getFont(
+ buffer()->params(), cur.pos(),
+ outerFont(t->getPar(cur.par()), t->paragraphs())
).language()->encoding();
}
}
-void BufferView::fullCursor(LCursor const & cur)
-{
- pimpl_->cursor_ = cur;
-}
-
-
-LCursor & BufferView::fullCursor()
-{
- return pimpl_->cursor_;
-}
-
-
-LCursor const & BufferView::fullCursor() const
-{
- return pimpl_->cursor_;
-}
-
-
-CursorSlice & BufferView::cursor()
-{
- return fullCursor().cursor_.back();
-}
-
-
-CursorSlice const & BufferView::cursor() const
-{
- return fullCursor().cursor_.back();
-}
-
-
-CursorSlice & BufferView::anchor()
-{
- return fullCursor().anchor_.back();
-}
-
-
-CursorSlice const & BufferView::anchor() const
-{
- return fullCursor().anchor_.back();
-}
-
-
-Selection & BufferView::selection()
-{
- return selection_;
-}
-
-
-Selection const & BufferView::selection() const
-{
- return selection_;
-}
-
-
-void BufferView::x_target(int x)
-{
- x_target_ = x;
-}
-
-
-int BufferView::x_target() const
-{
- return x_target_;
-}
-
-
void BufferView::updateParagraphDialog()
{
pimpl_->updateParagraphDialog();
}
-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()
+void BufferView::setCursor(ParIterator const & par,
+ lyx::pos_type pos)
{
- if (selection().set())
- return cursor();
- return anchor() > cursor() ? anchor() : cursor();
+ LCursor & cur = cursor();
+ cur.reset();
+ ParIterator::PosHolder const & positions = par.positions();
+ int const last = par.size() - 1;
+ for (int i = 0; i < last; ++i)
+ (*positions[i].it)->inset->edit(cur, true);
+ cur.resetAnchor();
+ LyXText * lt = par.text(*buffer());
+ lt->setCursor(par.pit(), pos);
}
-void BufferView::setSelection()
-{
- selection().set(true);
- // a selection with no contents is not a selection
- if (cursor().par() == anchor().par() && cursor().pos() == anchor().pos())
- selection().set(false);
-}
-
-
-void BufferView::clearSelection()
-{
- selection().set(false);
- selection().mark(false);
- resetAnchor();
- unsetXSel();
-}
-
-
-
/*
if the fitCursor call refers to some point in never-explored-land, then we
don't have y information in insets there, then we cannot even do an update
to get it (because we need the y infomation for setting top_y first). So
-this is solved in put_selection_at with:
+this is solved in putSelectionAt with:
- setting top_y to the y of the outerPar (that has good info)
- calling update
int length, bool backwards)
{
ParIterator par(cur);
-
- clearSelection();
+
+ cursor().clearSelection();
LyXText * text = par.text(*buffer());
- par.lockPath(this);
+ setCursor(par, cur.pos());
+
// hack for the chicken and egg problem
if (par.inset())
top_y(par.outerPar()->y);
update();
text->setCursor(cur.pit(), cur.pos());
- fullCursor().updatePos();
+ cursor().updatePos();
if (length) {
text->setSelectionRange(length);
- setSelection();
+ cursor().setSelection();
if (backwards)
- std::swap(cursor(), anchor());
+ swap(cursor().cursor_, cursor().anchor_);
}
fitCursor();
update();
}
+
+LCursor & BufferView::cursor()
+{
+ return pimpl_->cursor_;
+}
+
+
+LCursor const & BufferView::cursor() const
+{
+ return pimpl_->cursor_;
+}