#include "lyxtext.h"
#include "paragraph.h"
#include "paragraph_funcs.h"
+#include "PosIterator.h"
#include "texrow.h"
#include "undo.h"
#include "WordLangTuple.h"
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))
{}
}
+void BufferView::unsetXSel()
+{
+ pimpl_->xsel_cache_.set = false;
+}
+
+
Buffer * BufferView::buffer() const
{
return pimpl_->buffer_;
string const fname = MakeAbsPath(filen);
- text()->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()) {
- text()->clearSelection();
+ cursor().clearSelection();
text()->setCursor(
- std::distance(text()->ownerParagraphs().begin(), it.getPar()),
+ distance(text()->paragraphs().begin(), it.getPar()),
it.getPos());
- text()->selection.cursor = text()->cursor;
+ cursor().resetAnchor();
update();
return;
}
return;
owner()->message(_("Undo"));
- text()->clearSelection();
- if (!textUndo(this))
+ cursor().clearSelection();
+ if (!textUndo(*this))
owner()->message(_("No further undo information"));
update();
switchKeyMap();
return;
owner()->message(_("Redo"));
- text()->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*>(cursor().innerInset());
-}
-
-
LyXText * BufferView::getLyXText() const
{
return cursor().innerText();
LyXText * t = getLyXText();
if (!t)
return 0;
- return t->cursorPar()->getFont(
- buffer()->params(),
- t->cursor.pos(),
- outerFont(t->cursorPar(), t->ownerParagraphs())
+ CursorSlice const & cur = cursor().innerTextSlice();
+ return t->getPar(cur.par())->getFont(
+ buffer()->params(), cur.pos(),
+ outerFont(t->getPar(cur.par()), t->paragraphs())
).language()->encoding();
}
}
-LCursor & BufferView::cursor()
+void BufferView::updateParagraphDialog()
{
- return pimpl_->cursor_;
+ pimpl_->updateParagraphDialog();
}
-LCursor const & BufferView::cursor() const
+LyXText * BufferView::text() const
{
- return pimpl_->cursor_;
+ return pimpl_->buffer_ ? &pimpl_->buffer_->text() : 0;
}
-void BufferView::x_target(int x)
+void BufferView::setCursor(ParIterator const & par,
+ lyx::pos_type pos)
{
- x_target_ = x;
+ 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);
}
-int BufferView::x_target() const
+/*
+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 putSelectionAt with:
+
+- setting top_y to the y of the outerPar (that has good info)
+- calling update
+- calling cursor().updatePos()
+- then call fitCursor()
+
+Ab.
+*/
+
+void BufferView::putSelectionAt(PosIterator const & cur,
+ int length, bool backwards)
{
- return x_target_;
+ ParIterator par(cur);
+
+ cursor().clearSelection();
+
+ LyXText * text = par.text(*buffer());
+ 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());
+ cursor().updatePos();
+
+ if (length) {
+ text->setSelectionRange(length);
+ cursor().setSelection();
+ if (backwards)
+ swap(cursor().cursor_, cursor().anchor_);
+ }
+
+ fitCursor();
+ update();
}
-void BufferView::updateParagraphDialog()
+LCursor & BufferView::cursor()
{
- pimpl_->updateParagraphDialog();
+ return pimpl_->cursor_;
}
-LyXText * BufferView::text() const
+LCursor const & BufferView::cursor() const
{
- return pimpl_->buffer_ ? &pimpl_->buffer_->text() : 0;
+ return pimpl_->cursor_;
}