- // Yes it has. Store the params used to check this.
- synthetic_mouse_event_.min_scrollbar_old = min_scrollbar;
- synthetic_mouse_event_.max_scrollbar_old = max_scrollbar;
- // ... and dispatch the event to the LyX core.
- dispatch(synthetic_mouse_event_.cmd);
+
+ // Scroll
+ if (step <= 2 * wh) {
+ buffer_view_->scroll(up ? -step : step);
+ buffer_view_->updateMetrics();
+ } else {
+ buffer_view_->scrollDocView(value + up ? -step : step, false);
+ }
+
+ // In which paragraph do we have to set the cursor ?
+ Cursor & cur = buffer_view_->cursor();
+ TextMetrics const & tm = buffer_view_->textMetrics(cur.text());
+
+ pair<pit_type, const ParagraphMetrics *> p = up ? tm.first() : tm.last();
+ ParagraphMetrics const & pm = *p.second;
+ pit_type const pit = p.first;
+
+ if (pm.rows().empty())
+ return;
+
+ // Find the row at which we set the cursor.
+ RowList::const_iterator rit = pm.rows().begin();
+ RowList::const_iterator rlast = pm.rows().end();
+ int yy = pm.position() - pm.ascent();
+ for (--rlast; rit != rlast; ++rit) {
+ int h = rit->height();
+ if ((up && yy + h > 0)
+ || (!up && yy + h > wh - defaultRowHeight()))
+ break;
+ yy += h;
+ }
+
+ // Find the position of the cursor
+ bool bound;
+ int x = synthetic_mouse_event_.cmd.x();
+ pos_type const pos = rit->pos() + tm.getColumnNearX(pit, *rit, x, bound);
+
+ // Set the cursor
+ cur.pit() = pit;
+ cur.pos() = pos;
+ cur.boundary(bound);
+
+ buffer_view_->buffer().changed(false);
+ return;