using lyx::pos_type;
-LyXText::LyXText(BufferView * bv)
- : height(0), width(0), anchor_row_offset_(0),
- inset_owner(0), the_locking_inset(0), bv_owner(bv)
+LyXText::LyXText(BufferView * bv, InsetText * inset, bool ininset,
+ ParagraphList & paragraphs)
+ : height(0), width(0), anchor_y_(0),
+ inset_owner(inset), the_locking_inset(0), bv_owner(bv),
+ in_inset_(ininset), paragraphs_(paragraphs)
{
- anchor_row_ = rows().end();
-}
-
-
-LyXText::LyXText(BufferView * bv, InsetText * inset)
- : height(0), width(0), anchor_row_offset_(0),
- inset_owner(inset), the_locking_inset(0), bv_owner(bv)
-{
- anchor_row_ = rows().end();
}
{
bv_owner = bview;
- rowlist_.clear();
+ ParagraphList::iterator const beg = ownerParagraphs().begin();
+ ParagraphList::iterator const end = ownerParagraphs().end();
+ for (ParagraphList::iterator pit = beg; pit != end; ++pit)
+ pit->rows.clear();
+
width = 0;
height = 0;
- anchor_row_ = rows().end();
- anchor_row_offset_ = 0;
+ anchor_y_ = 0;
- current_font = getFont(ownerParagraphs().begin(), 0);
+ current_font = getFont(beg, 0);
- redoParagraphs(ownerParagraphs().begin(), ownerParagraphs().end());
- setCursorIntern(ownerParagraphs().begin(), 0);
+ redoParagraphs(beg, end);
+ setCursorIntern(beg, 0);
selection.cursor = cursor;
updateCounters();
}
-// removes the row and reset the touched counters
-void LyXText::removeRow(RowList::iterator rit)
-{
- if (anchor_row_ == rit) {
- if (rit != rows().begin()) {
- anchor_row_ = boost::prior(rit);
- anchor_row_offset_ += anchor_row_->height();
- } else {
- anchor_row_ = boost::next(rit);
- anchor_row_offset_ -= rit->height();
- }
- }
-
- // the text becomes smaller
- height -= rit->height();
-
- rowlist_.erase(rit);
-}
-
-
-// remove all following rows of the paragraph of the specified row.
-void LyXText::removeParagraph(RowList::iterator rit)
-{
- ParagraphList::iterator tmppit = getPar(rit);
- ++rit;
-
- while (rit != rows().end() && getPar(rit) == tmppit) {
- RowList::iterator tmprit = boost::next(rit);
- removeRow(rit);
- rit = tmprit;
- }
-}
-
-
-void LyXText::insertParagraph(ParagraphList::iterator pit,
- RowList::iterator rit)
-{
- // insert a new row, starting at position 0
- rit = rowlist_.insert(rit, Row(0));
-
- // and now append the whole paragraph before the new row
-
- pos_type const last = pit->size();
- bool done = false;
-
- do {
- pos_type z = rowBreakPoint(pit, *rit);
-
- RowList::iterator tmprow = rit;
-
- if (z < last) {
- ++z;
- rit = rowlist_.insert(boost::next(rit), Row(z));
- } else {
- done = true;
- }
-
- // Set the dimensions of the row
- // fixed fill setting now by calling inset->update() in
- // SingleWidth when needed!
- tmprow->fill(fill(tmprow, workWidth()));
- setHeightOfRow(tmprow);
-
- } while (!done);
-}
-
-
InsetOld * LyXText::getInset() const
{
ParagraphList::iterator pit = cursor.par();
void LyXText::redoParagraph(ParagraphList::iterator pit)
{
-#if 0
- // find first row of given par
- RowList::iterator first;
- for (first = rows().begin(); first != rows().end(); ++first)
- if (getPar(first) == pit)
- break;
-
- // find last row of given par
- RowList::iterator last = first;
- for ( ; last != rows().end() && getPar(last) == pit; ++last)
- ;
+ RowList::iterator rit = pit->rows.begin();
+ RowList::iterator end = pit->rows.end();
- Assert(first == beginRow(pit));
- Assert(last == endRow(pit));
-#else
- RowList::iterator first = beginRow(pit);
- RowList::iterator last = endRow(pit);
-#endif
+ // remove rows of paragraph
+ for (int i = 0; rit != end; ++rit, ++i)
+ height -= rit->height();
+
+ pit->rows.clear();
+
+ // rebreak the paragraph
+ // insert a new row, starting at position 0
+
+ pos_type z = 0;
+ pit->rows.push_back(Row(z));
+ bool done = false;
+ while (!done) {
+ z = rowBreakPoint(pit, pit->rows.back());
- // remove paragraph from rowlist
- while (first != last) {
- RowList::iterator rit2 = first;
- ++first;
- removeRow(rit2);
+ RowList::iterator tmprow = boost::prior(pit->rows.end());
+
+ if (z >= pit->size())
+ done = true;
+ else {
+ ++z;
+ pit->rows.push_back(Row(z));
+ }
+
+ tmprow->fill(fill(pit, tmprow, workWidth()));
+ setHeightOfRow(pit, tmprow);
}
- // reinsert the paragraph
- insertParagraph(pit, last);
+ //lyxerr << "redoParagraph: " << pit->rows.size() << " rows\n";
}
void LyXText::metrics(MetricsInfo & mi, Dimension & dim)
{
- //lyxerr << "LyXText::metrics: width: " << mi.base.textwidth << endl;
+ //lyxerr << "LyXText::metrics: width: " << mi.base.textwidth
+ // << " workWidth: " << workWidth() << endl;
//Assert(mi.base.textwidth);
// rebuild row cache
- rowlist_.clear();
width = 0;
height = 0;
- anchor_row_ = rows().end();
- anchor_row_offset_ = 0;
+ //anchor_y_ = 0;
ParagraphList::iterator pit = ownerParagraphs().begin();
ParagraphList::iterator end = ownerParagraphs().end();
for (; pit != end; ++pit) {
+ pit->rows.clear();
+
InsetList::iterator ii = pit->insetlist.begin();
InsetList::iterator iend = pit->insetlist.end();
for (; ii != iend; ++ii) {
}
// final dimension
- dim.asc = rows().begin()->ascent_of_text();
+ dim.asc = firstRow()->ascent_of_text();
dim.des = height - dim.asc;
dim.wid = std::max(mi.base.textwidth, int(width));
}
RowList::iterator rit = cursorRow();
RowList::iterator next_rit = boost::next(rit);
+ RowList::iterator end = boost::next(rit);
ParagraphList::iterator pit = cursor.par();
- pos_type last_pos = lastPos(*this, pit, rit);
+ pos_type last_pos = lastPos(*pit, rit);
- if (next_rit == rows().end() || getPar(next_rit) != pit) {
+ if (next_rit == end) {
++last_pos;
} else {
if (pit->empty() ||
cur.par(pit);
cur.pos(pos);
cur.boundary(boundary);
- if (rows().empty())
+ if (noRows())
return;
// get the cursor y position in text
int y = 0;
RowList::iterator row = getRow(pit, pos, y);
- RowList::iterator beg = rows().begin();
-
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
// the end of the previous row
cur.iy(y + row->baseline());
- if (row != beg &&
- pos &&
- getPar(boost::prior(row)) == getPar(row) &&
- pos < pit->size() &&
- pit->getChar(pos) == Paragraph::META_INSET) {
+ if (row != pit->rows.begin()
+ && pos
+ && pos < pit->size()
+ && pit->getChar(pos) == Paragraph::META_INSET) {
InsetOld * ins = pit->getInset(pos);
if (ins && (ins->needFullRow() || ins->display())) {
--row;
// y is now the cursor baseline
cur.y(y);
- pos_type last = lastPrintablePos(*this, pit, old_row);
+ pos_type last = lastPrintablePos(*pit, old_row);
// None of these should happen, but we're scaredy-cats
if (pos > pit->size()) {
- lyxerr << "dont like 1 please report" << endl;
+ lyxerr << "dont like 1, pos: " << pos << " size: " << pit->size() << endl;
pos = 0;
cur.pos(0);
} else if (pos > last + 1) {
x -= singleWidth(pit, body_pos - 1);
}
- if (hfillExpansion(*this, pit, rit, pos)) {
+ if (hfillExpansion(*pit, rit, pos)) {
x += singleWidth(pit, pos);
if (pos >= body_pos)
x += fill_hfill;
prepareToPrint(pit, rit, tmpx, fill_separator, fill_hfill, fill_label_hfill);
pos_type vc = rit->pos();
- pos_type last = lastPrintablePos(*this, pit, rit);
+ pos_type last = lastPrintablePos(*pit, rit);
pos_type c = 0;
LyXLayout_ptr const & layout = pit->layout();
tmpx -= singleWidth(pit, body_pos - 1);
}
- if (hfillExpansion(*this, pit, rit, c)) {
+ if (hfillExpansion(*pit, rit, c)) {
tmpx += singleWidth(pit, c);
if (c >= body_pos)
tmpx += fill_hfill;
boundary = false;
// This (rtl_support test) is not needed, but gives
- // some speedup if rtl_support=false
- RowList::iterator next_rit = boost::next(rit);
-
- bool const lastrow = lyxrc.rtl_support &&
- (next_rit == rowlist_.end() || getPar(next_rit) != pit);
+ // some speedup if rtl_support == false
+ bool const lastrow = lyxrc.rtl_support
+ && boost::next(rit) == pit->rows.end();
// If lastrow is false, we don't need to compute
// the value of rtl.
? pit->isRightToLeftPar(bv()->buffer()->params)
: false;
if (lastrow &&
- ((rtl && left_side && vc == rit->pos() && x < tmpx - 5) ||
- (!rtl && !left_side && vc == last + 1 && x > tmpx + 5)))
+ ((rtl && left_side && vc == rit->pos() && x < tmpx - 5) ||
+ (!rtl && !left_side && vc == last + 1 && x > tmpx + 5)))
c = last + 1;
else if (vc == rit->pos()) {
c = vis2log(vc);
void LyXText::setCursorFromCoordinates(int x, int y)
{
- //LyXCursor old_cursor = cursor;
+ LyXCursor old_cursor = cursor;
setCursorFromCoordinates(cursor, x, y);
setCurrentFont();
-#warning DEPM disabled, otherwise crash when entering new table
- //deleteEmptyParagraphMechanism(old_cursor);
+ deleteEmptyParagraphMechanism(old_cursor);
}
bool beforeFullRowInset(LyXText & lt, LyXCursor const & cur)
{
RowList::iterator row = lt.getRow(cur);
- if (boost::next(row) == lt.rows().end())
- return false;
-
RowList::iterator next = boost::next(row);
- if (next->pos() != cur.pos() || lt.getPar(next) != cur.par())
+ if (next == cur.par()->rows.end() || next->pos() != cur.pos())
return false;
- if (cur.pos() == cur.par()->size()
- || !cur.par()->isInset(cur.pos()))
+ if (cur.pos() == cur.par()->size() || !cur.par()->isInset(cur.pos()))
return false;
InsetOld const * inset = cur.par()->getInset(cur.pos());
void LyXText::setCursorFromCoordinates(LyXCursor & cur, int x, int y)
{
// Get the row first.
-
- RowList::iterator row = getRowNearY(y);
- ParagraphList::iterator pit = getPar(row);
+ ParagraphList::iterator pit;
+ RowList::iterator row = getRowNearY(y, pit);
bool bound = false;
pos_type const column = getColumnNearX(pit, row, x, bound);
cur.par(pit);
cur.x(x);
cur.y(y + row->baseline());
- if (beforeFullRowInset(*this, cur)) {
- pos_type const last = lastPrintablePos(*this, pit, row);
- RowList::iterator next_row = boost::next(row);
- cur.ix(int(getCursorX(pit, next_row, cur.pos(), last, bound)));
- cur.iy(y + row->height() + next_row->baseline());
- } else {
+// if (beforeFullRowInset(*this, cur)) {
+// pos_type const last = lastPrintablePos(*this, pit, row);
+// RowList::iterator next_row = nextRow(row);
+// cur.ix(int(getCursorX(pit, next_row, cur.pos(), last, bound)));
+// cur.iy(y + row->height() + next_row->baseline());
+// } else {
cur.iy(cur.y());
cur.ix(cur.x());
- }
+// }
cur.boundary(bound);
}
}
}
#else
- setCursorFromCoordinates(bv(), cursor.x_fix(),
- cursor.y() - cursorRow()->baseline() - 1);
+ lyxerr << "cursorUp: y " << cursor.y() << " bl: " <<
+ cursorRow()->baseline() << endl;
+ setCursorFromCoordinates(cursor.x_fix(),
+ cursor.y() - cursorRow()->baseline() - 1);
#endif
}
}
}
#else
- setCursorFromCoordinates(bv(), cursor.x_fix(),
- cursor.y() - cursorRow()->baseline()
- + cursorRow()->height() + 1);
+ setCursorFromCoordinates(cursor.x_fix(),
+ cursor.y() - cursorRow()->baseline() + cursorRow()->height() + 1);
#endif
}
selection.cursor.par() == old_cursor.par()
&& selection.cursor.pos() == old_cursor.pos());
- if (getRow(old_cursor) != rows().begin()) {
- RowList::iterator prevrow = boost::prior(getRow(old_cursor));
- tmpcursor = cursor;
- cursor = old_cursor; // that undo can restore the right cursor position
- #warning FIXME. --end() iterator is usable here
- ParagraphList::iterator endpit = boost::next(old_cursor.par());
- while (endpit != ownerParagraphs().end() &&
- endpit->getDepth()) {
- ++endpit;
- }
+ tmpcursor = cursor;
+ cursor = old_cursor; // that undo can restore the right cursor position
- recordUndo(bv(), Undo::DELETE, old_cursor.par(),
- boost::prior(endpit));
- cursor = tmpcursor;
-
- // delete old row
- removeRow(getRow(old_cursor));
- // delete old par
- ownerParagraphs().erase(old_cursor.par());
-
- /* Breakagain the next par. Needed because of
- * the parindent that can occur or dissappear.
- * The next row can change its height, if
- * there is another layout before */
- RowList::iterator tmprit = boost::next(prevrow);
- if (tmprit != rows().end()) {
- redoParagraph(getPar(tmprit));
- updateCounters();
- }
- setHeightOfRow(prevrow);
- } else {
- RowList::iterator nextrow = boost::next(getRow(old_cursor));
-
- tmpcursor = cursor;
- cursor = old_cursor; // that undo can restore the right cursor position
-#warning FIXME. --end() iterator is usable here
- ParagraphList::iterator endpit = boost::next(old_cursor.par());
- while (endpit != ownerParagraphs().end() &&
- endpit->getDepth()) {
- ++endpit;
- }
+ ParagraphList::iterator endpit = boost::next(old_cursor.par());
+ while (endpit != ownerParagraphs().end() && endpit->getDepth())
+ ++endpit;
+
+ recordUndo(bv(), Undo::DELETE, old_cursor.par(), boost::prior(endpit));
+ cursor = tmpcursor;
- recordUndo(bv(), Undo::DELETE, old_cursor.par(), boost::prior(endpit));
- cursor = tmpcursor;
-
- // delete old row
- removeRow(getRow(old_cursor));
- // delete old par
- ownerParagraphs().erase(old_cursor.par());
-
- /* Breakagain the next par. Needed because of
- the parindent that can occur or dissappear.
- The next row can change its height, if
- there is another layout before */
- if (nextrow != rows().end()) {
- redoParagraph(getPar(nextrow));
- updateCounters();
- }
- }
+ // delete old par
+ ownerParagraphs().erase(old_cursor.par());
+ redoParagraph();
// correct cursor y
setCursorIntern(cursor.par(), cursor.pos());
ParagraphList & LyXText::ownerParagraphs() const
{
- if (inset_owner) {
- return inset_owner->paragraphs;
- }
- return bv_owner->buffer()->paragraphs;
+ return paragraphs_;
}
bool LyXText::isInInset() const
{
// Sub-level has non-null bv owner and non-null inset owner.
- return inset_owner != 0 && bv_owner != 0;
+ return inset_owner != 0;
}