mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-25 10:58:52 +00:00
Move some horizontal scrolling code from TextMetrics to BufferView
It is better to have all the code in the same place, and it will avoid code duplication later.
This commit is contained in:
parent
77ef48d093
commit
96fee0ed7a
@ -2914,15 +2914,26 @@ int BufferView::horizScrollOffset() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
CursorSlice const & BufferView::currentRowSlice() const
|
int BufferView::horizScrollOffset(Text const * text,
|
||||||
|
pit_type pit, pos_type pos) const
|
||||||
{
|
{
|
||||||
return d->current_row_slice_;
|
// Is this a row that is currently scrolled?
|
||||||
|
if (!d->current_row_slice_.empty()
|
||||||
|
&& &text->inset() == d->current_row_slice_.inset().asInsetText()
|
||||||
|
&& pit == d->current_row_slice_.pit()
|
||||||
|
&& pos == d->current_row_slice_.pos())
|
||||||
|
return d->horiz_scroll_offset_;
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
CursorSlice const & BufferView::lastRowSlice() const
|
bool BufferView::hadHorizScrollOffset(Text const * text,
|
||||||
|
pit_type pit, pos_type pos) const
|
||||||
{
|
{
|
||||||
return d->last_row_slice_;
|
return !d->last_row_slice_.empty()
|
||||||
|
&& &text->inset() == d->last_row_slice_.inset().asInsetText()
|
||||||
|
&& pit == d->last_row_slice_.pit()
|
||||||
|
&& pos == d->last_row_slice_.pos();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -125,12 +125,15 @@ public:
|
|||||||
// Returns the amount of horizontal scrolling applied to the
|
// Returns the amount of horizontal scrolling applied to the
|
||||||
// top-level row where the cursor lies
|
// top-level row where the cursor lies
|
||||||
int horizScrollOffset() const;
|
int horizScrollOffset() const;
|
||||||
|
// Returns the amount of horizontal scrolling applied to the
|
||||||
|
// row of text starting at (pit, pos)
|
||||||
|
int horizScrollOffset(Text const * text,
|
||||||
|
pit_type pit, pos_type pos) const;
|
||||||
|
|
||||||
// Points to the top-level row where the cursor lies (during draw).
|
// Returns true if the row of text starting at (pit, pos) was scrolled
|
||||||
CursorSlice const & currentRowSlice() const;
|
// at the last draw event.
|
||||||
|
bool hadHorizScrollOffset(Text const * text,
|
||||||
// Points to the top-level row where the cursor lied at last draw event.
|
pit_type pit, pos_type pos) const;
|
||||||
CursorSlice const & lastRowSlice() const;
|
|
||||||
|
|
||||||
/// reset the scrollbar to reflect current view position.
|
/// reset the scrollbar to reflect current view position.
|
||||||
void updateScrollbar();
|
void updateScrollbar();
|
||||||
|
@ -1113,14 +1113,8 @@ pos_type TextMetrics::getPosNearX(Row const & row, int & x,
|
|||||||
int const xo = origin_.x_;
|
int const xo = origin_.x_;
|
||||||
x -= xo;
|
x -= xo;
|
||||||
|
|
||||||
int offset = 0;
|
|
||||||
CursorSlice rowSlice(const_cast<InsetText &>(text_->inset()));
|
|
||||||
rowSlice.pit() = row.pit();
|
|
||||||
rowSlice.pos() = row.pos();
|
|
||||||
|
|
||||||
// Adapt to cursor row scroll offset if applicable.
|
// Adapt to cursor row scroll offset if applicable.
|
||||||
if (bv_->currentRowSlice() == rowSlice)
|
int const offset = bv_->horizScrollOffset(text_, row.pit(), row.pos());
|
||||||
offset = bv_->horizScrollOffset();
|
|
||||||
x += offset;
|
x += offset;
|
||||||
|
|
||||||
pos_type pos = row.pos();
|
pos_type pos = row.pos();
|
||||||
@ -1908,26 +1902,18 @@ void TextMetrics::drawParagraph(PainterInfo & pi, pit_type const pit, int const
|
|||||||
for (size_t i = 0; i != nrows; ++i) {
|
for (size_t i = 0; i != nrows; ++i) {
|
||||||
|
|
||||||
Row const & row = pm.rows()[i];
|
Row const & row = pm.rows()[i];
|
||||||
int row_x = x;
|
// Adapt to cursor row scroll offset if applicable.
|
||||||
|
int row_x = x - bv_->horizScrollOffset(text_, pit, row.pos());
|
||||||
if (i)
|
if (i)
|
||||||
y += row.ascent();
|
y += row.ascent();
|
||||||
|
|
||||||
CursorSlice rowSlice(const_cast<InsetText &>(text_->inset()));
|
RowPainter rp(pi, *text_, pit, row, row_x, y);
|
||||||
rowSlice.pit() = pit;
|
|
||||||
rowSlice.pos() = row.pos();
|
|
||||||
|
|
||||||
bool const inside = (y + row.descent() >= 0
|
bool const inside = (y + row.descent() >= 0
|
||||||
&& y - row.ascent() < ww);
|
&& y - row.ascent() < ww);
|
||||||
|
|
||||||
// Adapt to cursor row scroll offset if applicable.
|
|
||||||
if (bv_->currentRowSlice() == rowSlice)
|
|
||||||
row_x -= bv_->horizScrollOffset();
|
|
||||||
|
|
||||||
// It is not needed to draw on screen if we are not inside.
|
// It is not needed to draw on screen if we are not inside.
|
||||||
pi.pain.setDrawingEnabled(inside && original_drawing_state);
|
pi.pain.setDrawingEnabled(inside && original_drawing_state);
|
||||||
|
|
||||||
RowPainter rp(pi, *text_, pit, row, row_x, y);
|
|
||||||
|
|
||||||
if (selection)
|
if (selection)
|
||||||
row.setSelectionAndMargins(sel_beg_par, sel_end_par);
|
row.setSelectionAndMargins(sel_beg_par, sel_end_par);
|
||||||
else
|
else
|
||||||
@ -1946,7 +1932,7 @@ void TextMetrics::drawParagraph(PainterInfo & pi, pit_type const pit, int const
|
|||||||
if (pi.pain.isDrawingEnabled())
|
if (pi.pain.isDrawingEnabled())
|
||||||
row.setCrc(pm.computeRowSignature(row, bparams));
|
row.setCrc(pm.computeRowSignature(row, bparams));
|
||||||
bool row_has_changed = row.changed()
|
bool row_has_changed = row.changed()
|
||||||
|| rowSlice == bv_->lastRowSlice();
|
|| bv_->hadHorizScrollOffset(text_, pit, row.pos());
|
||||||
|
|
||||||
// Take this opportunity to spellcheck the row contents.
|
// Take this opportunity to spellcheck the row contents.
|
||||||
if (row_has_changed && pi.do_spellcheck && lyxrc.spellcheck_continuously) {
|
if (row_has_changed && pi.do_spellcheck && lyxrc.spellcheck_continuously) {
|
||||||
|
Loading…
Reference in New Issue
Block a user