Rationalise the position of calls to updateRowPostitions, remove the returned (and computed) y position from getRow and getRowNearY (and solve a bug in this one).

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@7603 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Alfredo Braunstein 2003-08-25 10:24:26 +00:00
parent 495ba12545
commit 189b00a5c9
6 changed files with 56 additions and 75 deletions

View File

@ -1,3 +1,12 @@
2003-08-25 Alfredo Braunstein <abraunst@libero.it>
* text2.C (redoParagraphInternal, redoParagraphs):
* text.C (redoParagraph): add a call to updateRowPositions at the
end of each 'metrics-like' call. Remove all others.
(getRow): remove the 'y-computing' version.
(getRowNearY): do not compute nor return the real y. Solve the
'y < 0' problem and simplify.
2003-08-22 Angus Leeming <leeming@lyx.org>
* *.[Ch]: clean-up of licence and author blurbs.

View File

@ -131,8 +131,13 @@ public:
ParagraphList::iterator end);
/// rebreaks the given par
void redoParagraph(ParagraphList::iterator pit);
/// rebreaks the cursor par
void redoParagraph();
private:
/// rebreaks the given par
void redoParagraphInternal(ParagraphList::iterator pit);
public:
///
void toggleFree(LyXFont const &, bool toggleall = false);
@ -186,7 +191,7 @@ public:
(relative to the whole text). y is set to the real beginning
of this row
*/
RowList::iterator getRowNearY(int & y,
RowList::iterator getRowNearY(int y,
ParagraphList::iterator & pit) const;
/** returns the column near the specified x-coordinate of the row
@ -195,12 +200,6 @@ public:
lyx::pos_type getColumnNearX(ParagraphList::iterator pit,
RowList::iterator rit, int & x, bool & boundary) const;
/** returns a pointer to a specified row. y is set to the beginning
of the row
*/
RowList::iterator
getRow(ParagraphList::iterator pit, lyx::pos_type pos, int & y) const;
/// need the selection cursor:
void setSelection();
///

View File

@ -1083,10 +1083,9 @@ int paintRows(BufferView const & bv, LyXText const & text,
int paintText(BufferView & bv, LyXText & text)
{
int const topy = text.top_y();
int y_text = topy;
ParagraphList::iterator pit;
RowList::iterator rit = text.getRowNearY(y_text, pit);
int y = y_text - topy;
RowList::iterator rit = text.getRowNearY(topy, pit);
int y = rit->y() - topy;
return paintRows(bv, text, pit, rit, 0, y, y, 0);
}

View File

@ -2047,46 +2047,11 @@ RowList::iterator LyXText::getRow(LyXCursor const & cur) const
RowList::iterator
LyXText::getRow(ParagraphList::iterator pit, pos_type pos) const
{
RowList::iterator rit = pit->rows.begin();
RowList::iterator end = pit->rows.end();
RowList::iterator rit = boost::prior(pit->rows.end());
RowList::iterator const begin = pit->rows.begin();
#warning Why is this next thing needed? (Andre)
while (rit != end
&& rit->pos() < pos
&& boost::next(rit) != end
&& boost::next(rit)->pos() <= pos)
++rit;
return rit;
}
// returns pointer to a specified row
RowList::iterator
LyXText::getRow(ParagraphList::iterator pit, pos_type pos, int & y) const
{
y = 0;
if (noRows())
return firstRow();
ParagraphList::iterator it = ownerParagraphs().begin();
for ( ; it != pit; ++it) {
RowList::iterator beg = it->rows.begin();
RowList::iterator end = it->rows.end();
for (RowList::iterator rit = beg; rit != end; ++rit)
y += rit->height();
}
RowList::iterator rit = pit->rows.begin();
RowList::iterator end = pit->rows.end();
while (rit != end
&& rit->pos() < pos
&& boost::next(rit) != end
&& boost::next(rit)->pos() <= pos) {
y += rit->height();
++rit;
}
while (rit != begin && rit->pos() > pos)
--rit;
return rit;
}
@ -2095,25 +2060,23 @@ LyXText::getRow(ParagraphList::iterator pit, pos_type pos, int & y) const
// returns pointer to some fancy row 'below' specified row
RowList::iterator LyXText::cursorIRow() const
{
int y = 0;
return getRow(cursor.par(), cursor.pos(), y);
return getRow(cursor.par(), cursor.pos());
}
RowList::iterator LyXText::getRowNearY(int & y,
RowList::iterator LyXText::getRowNearY(int y,
ParagraphList::iterator & pit) const
{
//lyxerr << "getRowNearY: y " << y << endl;
pit = ownerParagraphs().begin();
RowList::iterator rit = firstRow();
RowList::iterator rend = endRow();
for (; rit != rend; nextRow(pit, rit))
if (rit->y() > y)
break;
pit = boost::prior(ownerParagraphs().end());
RowList::iterator rit = lastRow();
RowList::iterator rbegin = firstRow();
while (rit != rbegin && static_cast<int>(rit->y()) > y)
previousRow(pit, rit);
previousRow(pit, rit);
y = rit->y();
return rit;
}

View File

@ -544,17 +544,7 @@ void LyXText::setFont(LyXFont const & font, bool toggleall)
}
// rebreaks all paragraphs between the specified pars
// This function is needed after SetLayout and SetFont etc.
void LyXText::redoParagraphs(ParagraphList::iterator start,
ParagraphList::iterator end)
{
for ( ; start != end; ++start)
redoParagraph(start);
}
void LyXText::redoParagraph(ParagraphList::iterator pit)
void LyXText::redoParagraphInternal(ParagraphList::iterator pit)
{
RowList::iterator rit = pit->rows.begin();
RowList::iterator end = pit->rows.end();
@ -593,6 +583,24 @@ void LyXText::redoParagraph(ParagraphList::iterator pit)
}
// rebreaks all paragraphs between the specified pars
// This function is needed after SetLayout and SetFont etc.
void LyXText::redoParagraphs(ParagraphList::iterator start,
ParagraphList::iterator end)
{
for ( ; start != end; ++start)
redoParagraphInternal(start);
updateRowPositions();
}
void LyXText::redoParagraph(ParagraphList::iterator pit)
{
redoParagraphInternal(pit);
updateRowPositions();
}
void LyXText::fullRebreak()
{
redoParagraphs(ownerParagraphs().begin(), ownerParagraphs().end());
@ -613,7 +621,6 @@ void LyXText::metrics(MetricsInfo & mi, Dimension & dim)
//anchor_y_ = 0;
redoParagraphs(ownerParagraphs().begin(), ownerParagraphs().end());
updateRowPositions();
// final dimension
dim.asc = firstRow()->ascent_of_text();
@ -1340,8 +1347,10 @@ void LyXText::setCursor(LyXCursor & cur, ParagraphList::iterator pit,
return;
// get the cursor y position in text
int y = 0;
RowList::iterator row = getRow(pit, pos, y);
RowList::iterator row = getRow(pit, pos);
int y = row->y();
RowList::iterator old_row = row;
// if we are before the first char of this row and are still in the
// same paragraph and there is a previous row then put the cursor on
@ -1655,6 +1664,8 @@ void LyXText::setCursorFromCoordinates(LyXCursor & cur, int x, int y)
// Get the row first.
ParagraphList::iterator pit;
RowList::iterator rit = getRowNearY(y, pit);
y = rit->y();
bool bound = false;
pos_type const column = getColumnNearX(pit, rit, x, bound);
cur.par(pit);

View File

@ -308,7 +308,7 @@ void LyXText::cursorNext()
}
ParagraphList::iterator dummypit;
getRowNearY(y, dummypit);
y = getRowNearY(y, dummypit)->y();
setCursorFromCoordinates(cursor.x_fix(), y);
// + bv->workHeight());