diff --git a/src/ChangeLog b/src/ChangeLog index 085c86854c..1cac600253 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,12 @@ +2003-08-25 Alfredo Braunstein + + * 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 * *.[Ch]: clean-up of licence and author blurbs. diff --git a/src/lyxtext.h b/src/lyxtext.h index bb9914342e..f3d4305e1e 100644 --- a/src/lyxtext.h +++ b/src/lyxtext.h @@ -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(); /// diff --git a/src/rowpainter.C b/src/rowpainter.C index 65318174b9..f90f0f2cbf 100644 --- a/src/rowpainter.C +++ b/src/rowpainter.C @@ -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); } diff --git a/src/text.C b/src/text.C index 8d2da41fd8..36ea605fe8 100644 --- a/src/text.C +++ b/src/text.C @@ -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(rit->y()) > y) + previousRow(pit, rit); - previousRow(pit, rit); - y = rit->y(); return rit; } diff --git a/src/text2.C b/src/text2.C index ad590c86ac..080eed5201 100644 --- a/src/text2.C +++ b/src/text2.C @@ -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); diff --git a/src/text3.C b/src/text3.C index 5ec9b25a46..a13e519283 100644 --- a/src/text3.C +++ b/src/text3.C @@ -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());