* BufferView
- showCursor(DocIterator): new DocIterator argument.
- showCursor(): use above method.
- scrollDocView(): take care of top and bottom special cases early in the method.
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@22707
a592a061-630c-0410-9148-
cb99ea01b6c8
void BufferView::scrollDocView(int value)
{
void BufferView::scrollDocView(int value)
{
+ // cut off at the top
+ if (value <= d->scrollbarParameters_.min) {
+ DocIterator dit = doc_iterator_begin(buffer_.inset());
+ showCursor(dit);
+ LYXERR(Debug::SCROLLING, "scroll to top");
+ return;
+ }
+
+ // cut off at the top
+ if (value >= d->scrollbarParameters_.max) {
+ DocIterator dit = doc_iterator_end(buffer_.inset());
+ dit.backwardPos();
+ showCursor(dit);
+ LYXERR(Debug::SCROLLING, "scroll to bottom");
+ return;
+ }
+
+
int const offset = value - d->scrollbarParameters_.position;
// If the offset is less than 2 screen height, prefer to scroll instead.
if (abs(offset) <= 2 * height_) {
int const offset = value - d->scrollbarParameters_.position;
// If the offset is less than 2 screen height, prefer to scroll instead.
if (abs(offset) <= 2 * height_) {
- // cut off at the top
- if (value < d->scrollbarParameters_.min)
- value = d->scrollbarParameters_.min;
-
// find paragraph at target positin
int par_pos = d->scrollbarParameters_.min;
for (size_t i = 0; i != d->par_height_.size(); ++i) {
// find paragraph at target positin
int par_pos = d->scrollbarParameters_.min;
for (size_t i = 0; i != d->par_height_.size(); ++i) {
void BufferView::showCursor()
void BufferView::showCursor()
+{
+ showCursor(d->cursor_);
+}
+
+
+void BufferView::showCursor(DocIterator const & dit)
{
// We are not properly started yet, delay until resizing is
// done.
{
// We are not properly started yet, delay until resizing is
// done.
LYXERR(Debug::SCROLLING, "recentering!");
LYXERR(Debug::SCROLLING, "recentering!");
- CursorSlice & bot = d->cursor_.bottom();
+ CursorSlice const & bot = dit.bottom();
TextMetrics & tm = d->text_metrics_[bot.text()];
pos_type const max_pit = pos_type(bot.text()->paragraphs().size() - 1);
TextMetrics & tm = d->text_metrics_[bot.text()];
pos_type const max_pit = pos_type(bot.text()->paragraphs().size() - 1);
- int bot_pit = d->cursor_.bottom().pit();
+ int bot_pit = bot.pit();
if (bot_pit > max_pit) {
// FIXME: Why does this happen?
LYXERR0("bottom pit is greater that max pit: "
if (bot_pit > max_pit) {
// FIXME: Why does this happen?
LYXERR0("bottom pit is greater that max pit: "
if (tm.has(bot_pit)) {
ParagraphMetrics const & pm = tm.parMetrics(bot_pit);
if (tm.has(bot_pit)) {
ParagraphMetrics const & pm = tm.parMetrics(bot_pit);
- int offset = coordOffset(d->cursor_, d->cursor_.boundary()).y_;
+ BOOST_ASSERT(!pm.rows().empty());
+ // FIXME: smooth scrolling doesn't work in mathed.
+ CursorSlice const & cs = dit.innerTextSlice();
+ int offset = coordOffset(dit, dit.boundary()).y_;
int ypos = pm.position() + offset;
int ypos = pm.position() + offset;
- Dimension const & row_dim = d->cursor_.textRow().dimension();
+ Dimension const & row_dim =
+ pm.getRow(cs.pos(), dit.boundary()).dimension();
if (ypos - row_dim.ascent() < 0)
scrollUp(- ypos + row_dim.ascent());
else if (ypos + row_dim.descent() > height_)
if (ypos - row_dim.ascent() < 0)
scrollUp(- ypos + row_dim.ascent());
else if (ypos + row_dim.descent() > height_)
tm.redoParagraph(bot_pit);
ParagraphMetrics const & pm = tm.parMetrics(bot_pit);
tm.redoParagraph(bot_pit);
ParagraphMetrics const & pm = tm.parMetrics(bot_pit);
- int offset = coordOffset(d->cursor_, d->cursor_.boundary()).y_;
+ int offset = coordOffset(dit, dit.boundary()).y_;
d->anchor_pit_ = bot_pit;
d->anchor_pit_ = bot_pit;
- Dimension const & row_dim = d->cursor_.textRow().dimension();
+ CursorSlice const & cs = dit.innerTextSlice();
+ Dimension const & row_dim =
+ pm.getRow(cs.pos(), dit.boundary()).dimension();
if (d->anchor_pit_ == 0)
d->anchor_ypos_ = offset + pm.ascent();
if (d->anchor_pit_ == 0)
d->anchor_ypos_ = offset + pm.ascent();
/// set the cursor based on the given TeX source row.
void setCursorFromRow(int row);
/// set the cursor based on the given TeX source row.
void setCursorFromRow(int row);
- /// Ensure the cursor is visible.
- /// This method will automatically scroll and update the BufferView and updated
+ /// Ensure that the BufferView cursor is visible.
+ /// This method will automatically scroll and update the BufferView
/// if needed.
void showCursor();
/// if needed.
void showCursor();
+ /// Ensure the passed cursor \p dit is visible.
+ /// This method will automatically scroll and update the BufferView
+ /// if needed.
+ void showCursor(DocIterator const & dit);
/// LFUN_SCROLL Helper.
void lfunScroll(FuncRequest const & cmd);
/// scroll down document by the given number of pixels.
/// LFUN_SCROLL Helper.
void lfunScroll(FuncRequest const & cmd);
/// scroll down document by the given number of pixels.