mirror of
https://git.lyx.org/repos/lyx.git
synced 2025-01-17 21:36:00 +00:00
Let getRowNearY use getPitNearY
This avoids code duplication. Return a pointer to a Row instead of a reference to handle the case where something went wrong. Make these methods private.
This commit is contained in:
parent
a25d94c315
commit
2d59031c3e
@ -1515,8 +1515,10 @@ pit_type TextMetrics::getPitNearY(int y)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Row const & TextMetrics::getRowNearY(int & y, pit_type pit)
|
Row const * TextMetrics::getRowNearY(int & y)
|
||||||
{
|
{
|
||||||
|
pit_type const pit = getPitNearY(y);
|
||||||
|
LASSERT(pit != -1, return nullptr);
|
||||||
ParagraphMetrics const & pm = par_metrics_[pit];
|
ParagraphMetrics const & pm = par_metrics_[pit];
|
||||||
|
|
||||||
int yy = pm.top();
|
int yy = pm.top();
|
||||||
@ -1528,7 +1530,7 @@ Row const & TextMetrics::getRowNearY(int & y, pit_type pit)
|
|||||||
if (yy + rit->height() > y)
|
if (yy + rit->height() > y)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
return *rit;
|
return &(*rit);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -1536,17 +1538,16 @@ Row const & TextMetrics::getRowNearY(int & y, pit_type pit)
|
|||||||
// sets cursor recursively descending into nested editable insets
|
// sets cursor recursively descending into nested editable insets
|
||||||
Inset * TextMetrics::editXY(Cursor & cur, int x, int y)
|
Inset * TextMetrics::editXY(Cursor & cur, int x, int y)
|
||||||
{
|
{
|
||||||
pit_type const pit = getPitNearY(y);
|
Row const * row = getRowNearY(y);
|
||||||
LASSERT(pit != -1, return 0);
|
LASSERT(row != nullptr, return nullptr);
|
||||||
Row const & row = getRowNearY(y, pit);
|
cur.pit() = row->pit();
|
||||||
cur.pit() = pit;
|
|
||||||
|
|
||||||
// Do we cover an inset?
|
// Do we cover an inset?
|
||||||
Row::Element const * e = checkInsetHit(row, x);
|
Row::Element const * e = checkInsetHit(*row, x);
|
||||||
|
|
||||||
if (!e) {
|
if (!e) {
|
||||||
// No inset, set position in the text
|
// No inset, set position in the text
|
||||||
auto [pos, bound] = getPosNearX(row, x);
|
auto [pos, bound] = getPosNearX(*row, x);
|
||||||
cur.pos() = pos;
|
cur.pos() = pos;
|
||||||
cur.boundary(bound);
|
cur.boundary(bound);
|
||||||
cur.setCurrentFont();
|
cur.setCurrentFont();
|
||||||
@ -1570,7 +1571,7 @@ Inset * TextMetrics::editXY(Cursor & cur, int x, int y)
|
|||||||
// non-editable inset, set cursor after the inset if x is
|
// non-editable inset, set cursor after the inset if x is
|
||||||
// nearer to that position (bug 9628)
|
// nearer to that position (bug 9628)
|
||||||
// No inset, set position in the text
|
// No inset, set position in the text
|
||||||
auto [pos, bound] = getPosNearX(row, x);
|
auto [pos, bound] = getPosNearX(*row, x);
|
||||||
cur.pos() = pos;
|
cur.pos() = pos;
|
||||||
cur.boundary(bound);
|
cur.boundary(bound);
|
||||||
cur.setCurrentFont();
|
cur.setCurrentFont();
|
||||||
@ -1587,12 +1588,10 @@ void TextMetrics::setCursorFromCoordinates(Cursor & cur, int x, int y)
|
|||||||
{
|
{
|
||||||
LASSERT(text_ == cur.text(), return);
|
LASSERT(text_ == cur.text(), return);
|
||||||
|
|
||||||
pit_type const pit = getPitNearY(y);
|
Row const * row = getRowNearY(y);
|
||||||
LASSERT(pit != -1, return);
|
LASSERT(row != nullptr, return);
|
||||||
|
auto [pos, bound] = getPosNearX(*row, x);
|
||||||
Row const & row = getRowNearY(y, pit);
|
text_->setCursor(cur, row->pit(), pos, true, bound);
|
||||||
auto [pos, bound] = getPosNearX(row, x);
|
|
||||||
text_->setCursor(cur, pit, pos, true, bound);
|
|
||||||
// remember new position.
|
// remember new position.
|
||||||
cur.setTargetX();
|
cur.setTargetX();
|
||||||
}
|
}
|
||||||
@ -1624,10 +1623,9 @@ Row::Element const * TextMetrics::checkInsetHit(Row const & row, int x) const
|
|||||||
//takes screen x,y coordinates
|
//takes screen x,y coordinates
|
||||||
Inset * TextMetrics::checkInsetHit(int x, int y)
|
Inset * TextMetrics::checkInsetHit(int x, int y)
|
||||||
{
|
{
|
||||||
pit_type const pit = getPitNearY(y);
|
Row const * row = getRowNearY(y);
|
||||||
LASSERT(pit != -1, return nullptr);
|
LASSERT(row != nullptr, return nullptr);
|
||||||
Row const & row = getRowNearY(y, pit);
|
Row::Element const * e = checkInsetHit(*row, x);
|
||||||
Row::Element const * e = checkInsetHit(row, x);
|
|
||||||
|
|
||||||
return e ? const_cast<Inset *>(e->inset) : nullptr;
|
return e ? const_cast<Inset *>(e->inset) : nullptr;
|
||||||
}
|
}
|
||||||
|
@ -186,35 +186,31 @@ private:
|
|||||||
// Helper function for the other checkInsetHit method.
|
// Helper function for the other checkInsetHit method.
|
||||||
Row::Element const * checkInsetHit(Row const & row, int x) const;
|
Row::Element const * checkInsetHit(Row const & row, int x) const;
|
||||||
|
|
||||||
|
/// Returns the paragraph number closest to screen y-coordinate.
|
||||||
|
/// This method uses the paragraph metrics to locate the
|
||||||
|
/// paragraph. The y-coordinate is allowed to be off-screen and
|
||||||
|
/// the metrics will be automatically updated if needed. This is
|
||||||
|
/// the reason why we need a non const BufferView.
|
||||||
|
/// FIXME: check whether this is still needed
|
||||||
|
pit_type getPitNearY(int y);
|
||||||
|
|
||||||
|
/// returns the row near the specified y-coordinate in a given paragraph
|
||||||
|
/// (relative to the screen).
|
||||||
|
Row const * getRowNearY(int & y);
|
||||||
|
|
||||||
// Temporary public:
|
|
||||||
public:
|
public:
|
||||||
/// returns the position near the specified x-coordinate of the row.
|
/// returns the position near the specified x-coordinate of the row.
|
||||||
/// x is an absolute screen coord, it is set to the real beginning
|
/// x is an absolute screen coord, it is set to the real beginning
|
||||||
/// of this column. This takes in account horizontal cursor row scrolling.
|
/// of this column. This takes in account horizontal cursor row scrolling.
|
||||||
std::pair<pos_type, bool> getPosNearX(Row const & row, int & x) const;
|
std::pair<pos_type, bool> getPosNearX(Row const & row, int & x) const;
|
||||||
|
|
||||||
/// returns the row near the specified y-coordinate in a given paragraph
|
/** sets cursor recursively descending into nested editable insets
|
||||||
/// (relative to the screen).
|
|
||||||
Row const & getRowNearY(int & y, pit_type pit);
|
|
||||||
|
|
||||||
/// returns the paragraph number closest to screen y-coordinate.
|
|
||||||
/// This method uses the BufferView CoordCache to locate the
|
|
||||||
/// paragraph. The y-coodinate is allowed to be off-screen and
|
|
||||||
/// the CoordCache will be automatically updated if needed. This is
|
|
||||||
/// the reason why we need a non const BufferView.
|
|
||||||
pit_type getPitNearY(int y);
|
|
||||||
|
|
||||||
/// sets cursor recursively descending into nested editable insets
|
|
||||||
/**
|
|
||||||
\return the inset pointer if x,y is covering that inset
|
\return the inset pointer if x,y is covering that inset
|
||||||
\param x,y are absolute screen coordinates.
|
\param x,y are absolute screen coordinates.
|
||||||
\retval inset is null if the cursor is positioned over normal
|
\retval inset is null if the cursor is positioned over normal
|
||||||
text in the current Text object. Otherwise it is the inset
|
text in the current Text object. Otherwise it is the inset
|
||||||
that the cursor points to, like for Inset::editXY.
|
that the cursor points to, like for Inset::editXY.
|
||||||
*/
|
*/
|
||||||
/// FIXME: cleanup to use BufferView::getCoveringInset() and
|
|
||||||
/// setCursorFromCoordinates() instead of checkInsetHit().
|
|
||||||
Inset * editXY(Cursor & cur, int x, int y);
|
Inset * editXY(Cursor & cur, int x, int y);
|
||||||
|
|
||||||
/// sets cursor only within this Text.
|
/// sets cursor only within this Text.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user