#include "Bidi.h"
#include "buffer.h"
-#include "insets/updatableinset.h"
#include "lyxfont.h"
#include "lyxrow.h"
#include "lyxrow_funcs.h"
#include "lyxrc.h"
#include "paragraph.h"
+#include "insets/updatableinset.h"
using lyx::pos_type;
}
start_ = row.pos();
- end_ = lastPos(par, row);
+ end_ = row.endpos() - 1;
if (start_ > end_) {
start_ = -1;
+2003-10-27 Alfredo Braunstein <abraunst@libero.it>
+
+ * text.C:
+ * lyxrow_funcs.[Ch]:
+ * Bidi.C:
+ * paragraph.C:
+ * lyxtext.h:
+ * rowpainter.C:
+ * text2.C:
+ * text3.C: remove lastPos uses in favour of Row::endpos
+
2003-10-27 Alfredo Braunstein <abraunst@libero.it>
* undo.C (performUndoOrRedo): fix two crashes by setting a
using std::endl;
-pos_type lastPos(Paragraph const & par, Row const & row)
-{
- if (par.empty())
- return 0;
- pos_type pos = row.endpos() - 1;
-// if (pos == par.size())
-// --pos;
- return pos;
-}
-
-
int numberOfSeparators(Paragraph const & par, Row const & row)
{
- pos_type const last = lastPos(par, row);
+ pos_type const first = max(row.pos(), par.beginningOfBody());
+ pos_type const last = row.endpos() - 1;
int n = 0;
- pos_type p = max(row.pos(), par.beginningOfBody());
- for ( ; p < last; ++p)
+ for (pos_type p = first; p < last; ++p) {
if (par.isSeparator(p))
++n;
+ }
+
return n;
}
// an anonymous namespace there. (Lgb)
int numberOfHfills(Paragraph const & par, Row const & row)
{
- pos_type const last = lastPos(par, row);
+ pos_type const last = row.endpos() - 1;
pos_type first = row.pos();
// hfill *DO* count at the beginning of paragraphs!
// an anonymous namespace there. (Lgb)
int numberOfLabelHfills(Paragraph const & par, Row const & row)
{
- pos_type last = lastPos(par, row);
+ pos_type last = row.endpos() - 1;
pos_type first = row.pos();
// hfill *DO* count at the beginning of paragraphs!
class Paragraph;
class Row;
-lyx::pos_type lastPos(Paragraph const & par, Row const & row);
-
int numberOfSeparators(Paragraph const & par, Row const & row);
int numberOfHfills(Paragraph const & par, Row const & row);
private:
///
float getCursorX(ParagraphList::iterator pit,
- Row const & row, lyx::pos_type pos,
- lyx::pos_type last, bool boundary) const;
+ Row const & row, lyx::pos_type pos, bool boundary) const;
/// used in setlayout
void makeFontEntriesLayoutSpecific(BufferParams const &, Paragraph & par);
return def_size;
Pimpl::FontList::const_iterator end_it = pimpl_->fontlist.begin();
- Pimpl::FontList::const_iterator end = pimpl_->fontlist.end();
+ Pimpl::FontList::const_iterator const end = pimpl_->fontlist.end();
for (; end_it != end; ++end_it) {
if (end_it->pos() >= endpos)
break;
void RowPainter::paintChars(pos_type & vpos, bool hebrew, bool arabic)
{
pos_type pos = text_.bidi.vis2log(vpos);
- pos_type const last = lastPos(*pit_, row_);
+ pos_type const end = row_.endpos();
LyXFont orig_font = getFont(pos);
// first character
++vpos;
// collect as much similar chars as we can
- while (vpos <= last && (pos = text_.bidi.vis2log(vpos)) >= 0) {
+ while (vpos < end && (pos = text_.bidi.vis2log(vpos)) >= 0) {
char c = pit_->getChar(pos);
if (!IsPrintableNonspace(c))
int(x_), row_.height(), LColor::selection);
pos_type const body_pos = pit_->beginningOfBody();
- pos_type const last = lastPos(*pit_, row_);
+ pos_type const end = row_.endpos();
double tmpx = x_;
- for (pos_type vpos = row_.pos(); vpos <= last; ++vpos) {
+ for (pos_type vpos = row_.pos(); vpos < end; ++vpos) {
pos_type pos = text_.bidi.vis2log(vpos);
double const old_tmpx = tmpx;
if (body_pos > 0 && pos == body_pos - 1) {
void RowPainter::paintChangeBar()
{
pos_type const start = row_.pos();
- pos_type const end = lastPos(*pit_, row_);
+ pos_type const end = row_.endpos();
- if (!pit_->isChanged(start, end))
+ if (start == end || !pit_->isChanged(start, end - 1))
return;
int const height = text_.isLastRow(pit_, row_)
void RowPainter::paintText()
{
- pos_type const last = lastPos(*pit_, row_);
+ pos_type const end = row_.endpos();
pos_type body_pos = pit_->beginningOfBody();
if (body_pos > 0 &&
- (body_pos - 1 > last || !pit_->isLineSeparator(body_pos - 1))) {
+ (body_pos > end || !pit_->isLineSeparator(body_pos - 1))) {
body_pos = 0;
}
int last_strikeout_x = 0;
pos_type vpos = row_.pos();
- while (vpos <= last) {
+ while (vpos < end) {
if (x_ > bv_.workWidth())
break;
pos_type pos = text_.bidi.vis2log(vpos);
// pixel width since last breakpoint
int chunkwidth = 0;
+
// We re-use the font resolution for the entire font span when possible
LyXFont font = getFont(pit, pos);
lyx::pos_type endPosOfFontSpan = pit->getEndPosOfFontSpan(pos);
}
char const c = pit->getChar(i);
+
if (i > endPosOfFontSpan) {
font = getFont(pit, i);
endPosOfFontSpan = pit->getEndPosOfFontSpan(i);
}
// exit on last registered breakpoint:
if (i + 1 < end)
- break;
+ break;
}
InsetOld * in = pit->getInset(i);
{
int w;
// get the pure distance
- pos_type const last = lastPos(*pit, row);
+ pos_type const end = row.endpos();
LyXLayout_ptr const & layout = pit->layout();
// special handling of the right address boxes
+#if 0
+//this is not working anymore
if (layout->margintype == MARGIN_RIGHT_ADDRESS_BOX) {
int const tmpfill = row.fill();
row.fill(0); // the minfill in leftMargin()
} else {
w = leftMargin(pit, row);
}
+#else
+ w = leftMargin(pit, row);
+#endif
pos_type const body_pos = pit->beginningOfBody();
pos_type i = row.pos();
- if (! pit->empty() && i <= last) {
+ if (i < end) {
// We re-use the font resolution for the entire span when possible
LyXFont font = getFont(pit, i);
lyx::pos_type endPosOfFontSpan = pit->getEndPosOfFontSpan(i);
- while (i <= last) {
+ while (i < end) {
if (body_pos > 0 && i == body_pos) {
w += font_metrics::width(layout->labelsep, getLabelFont(pit));
if (pit->isLineSeparator(i - 1))
++i;
}
}
- if (body_pos > 0 && body_pos > last) {
+ if (body_pos > 0 && body_pos >= end) {
w += font_metrics::width(layout->labelsep, getLabelFont(pit));
- if (last >= 0 && pit->isLineSeparator(last))
- w -= singleWidth(pit, last);
+ if (end > 0 && pit->isLineSeparator(end - 1))
+ w -= singleWidth(pit, end - 1);
int const left_margin = labelEnd(pit, row);
if (w < left_margin)
w = left_margin;
// This is not completely correct, but we can live with the small,
// cosmetic error for now.
int labeladdon = 0;
- pos_type const pos_end = lastPos(*pit, row);
+ pos_type const pos_end = row.endpos();
LyXFont::FONT_SIZE maxsize =
pit->highestFontInRange(row.pos(), pos_end, size);
void LyXText::charInserted()
{
- // Here we could call finishUndo for every 20 characters inserted.
+ // Here we call finishUndo for every 20 characters inserted.
// This is from my experience how emacs does it. (Lgb)
static unsigned int counter;
if (counter < 20) {
if (!pit->empty())
++nlh;
- if (nlh && !pit->getLabelWidthString().empty()) {
+ if (nlh && !pit->getLabelWidthString().empty())
fill_label_hfill = labelFill(pit, row) / double(nlh);
- }
}
// are there any hfills in the row?
bidi.computeTables(*pit, *bv()->buffer(), row);
if (is_rtl) {
pos_type body_pos = pit->beginningOfBody();
- pos_type last = lastPos(*pit, row);
+ pos_type end = row.endpos();
if (body_pos > 0 &&
- (body_pos - 1 > last ||
+ (body_pos > end ||
!pit->isLineSeparator(body_pos - 1))) {
x += font_metrics::width(layout->labelsep, getLabelFont(pit));
- if (body_pos - 1 <= last)
+ if (body_pos <= end)
x += fill_label_hfill;
}
}
// Kill to end of line.
void LyXText::deleteLineForward()
{
- if (cursorPar()->empty())
+ if (cursorPar()->empty()) {
// Paragraph is empty, so we just go to the right
cursorRight(bv());
- else {
+ } else {
LyXCursor tmpcursor = cursor;
// We can't store the row over a regular setCursor
// so we set it to 0 and reset it afterwards.
cursor = tmpcursor;
setSelection();
// What is this test for ??? (JMarc)
- if (!selection.set()) {
+ if (!selection.set())
deleteWordForward();
- } else {
+ else
cutSelection(true, false);
- }
}
}
// y is now the cursor baseline
cur.y(y);
- pos_type last = lastPos(*pit, row);
+ pos_type const end = row.endpos();
// None of these should happen, but we're scaredy-cats
- if (pos > pit->size()) {
+ if (pos < 0) {
+ lyxerr << "dont like -1" << endl;
+ pos = 0;
+ cur.pos(0);
+ BOOST_ASSERT(false);
+ } else if (pos > pit->size()) {
lyxerr << "dont like 1, pos: " << pos
<< " size: " << pit->size()
<< " row.pos():" << row.pos()
pos = 0;
cur.pos(0);
BOOST_ASSERT(false);
- } else if (pos > last + 1) {
+ } else if (pos > end) {
lyxerr << "dont like 2 please report" << endl;
// This shouldn't happen.
- pos = last + 1;
+ pos = end;
cur.pos(pos);
BOOST_ASSERT(false);
} else if (pos < row.pos()) {
cur.pos(pos);
BOOST_ASSERT(false);
}
-
// now get the cursors x position
- float x = getCursorX(pit, row, pos, last, boundary);
+ float x = getCursorX(pit, row, pos, boundary);
cur.x(int(x));
cur.x_fix(cur.x());
}
float LyXText::getCursorX(ParagraphList::iterator pit, Row const & row,
- pos_type pos, pos_type last, bool boundary) const
+ pos_type pos, bool boundary) const
{
pos_type cursor_vpos = 0;
double x = row.x();
double fill_hfill = row.fill_hfill();
double fill_label_hfill = row.fill_label_hfill();
pos_type const row_pos = row.pos();
-
- if (last < row_pos)
+ pos_type const end = row.endpos();
+
+ if (end <= row_pos)
cursor_vpos = row_pos;
- else if (pos > last && !boundary)
+ else if (pos >= end && !boundary)
cursor_vpos = (pit->isRightToLeftPar(bv()->buffer()->params()))
- ? row_pos : last + 1;
- else if (pos > row_pos && (pos > last || boundary))
+ ? row_pos : end;
+ else if (pos > row_pos && (pos >= end || boundary))
// Place cursor after char at (logical) position pos - 1
cursor_vpos = (bidi.level(pos - 1) % 2 == 0)
? bidi.log2vis(pos - 1) + 1 : bidi.log2vis(pos - 1);
pos_type body_pos = pit->beginningOfBody();
if (body_pos > 0 &&
- (body_pos - 1 > last || !pit->isLineSeparator(body_pos - 1)))
+ (body_pos > end || !pit->isLineSeparator(body_pos - 1)))
body_pos = 0;
for (pos_type vpos = row_pos; vpos < cursor_vpos; ++vpos) {
pos_type pos = bidi.vis2log(vpos);
if (body_pos > 0 && pos == body_pos - 1) {
- x += fill_label_hfill +
- font_metrics::width(
- pit->layout()->labelsep, getLabelFont(pit));
+ x += fill_label_hfill
+ + font_metrics::width(pit->layout()->labelsep,
+ getLabelFont(pit));
if (pit->isLineSeparator(body_pos - 1))
x -= singleWidth(pit, body_pos - 1);
}
double fill_label_hfill = row.fill_label_hfill();
pos_type vc = row.pos();
- pos_type last = lastPos(*pit, row);
+ pos_type end = row.endpos();
pos_type c = 0;
LyXLayout_ptr const & layout = pit->layout();
double last_tmpx = tmpx;
if (body_pos > 0 &&
- (body_pos - 1 > last ||
+ (body_pos > end ||
!pit->isLineSeparator(body_pos - 1)))
body_pos = 0;
// check for empty row
- if (!pit->size()) {
+ if (vc == end) {
x = int(tmpx);
return 0;
}
- while (vc <= last && tmpx <= x) {
+ while (vc < end && tmpx <= x) {
c = bidi.vis2log(vc);
last_tmpx = tmpx;
if (body_pos > 0 && c == body_pos - 1) {
left_side = true;
}
- if (vc > last + 1) // This shouldn't happen.
- vc = last + 1;
+ BOOST_ASSERT(vc <= end); // This shouldn't happen.
boundary = false;
// This (rtl_support test) is not needed, but gives
: false;
if (lastrow &&
((rtl && left_side && vc == row.pos() && x < tmpx - 5) ||
- (!rtl && !left_side && vc == last + 1 && x > tmpx + 5)))
- c = last + 1;
+ (!rtl && !left_side && vc == end && x > tmpx + 5)))
+ c = end;
else if (vc == row.pos()) {
c = bidi.vis2log(vc);
if (bidi.level(c) % 2 == 1)
}
}
- if (row.pos() <= last && c > last && pit->isNewline(last)) {
- if (bidi.level(last) % 2 == 0)
- tmpx -= singleWidth(pit, last);
+ if (row.pos() < end && c >= end && pit->isNewline(end - 1)) {
+ if (bidi.level(end -1) % 2 == 0)
+ tmpx -= singleWidth(pit, end - 1);
else
- tmpx += singleWidth(pit, last);
- c = last;
+ tmpx += singleWidth(pit, end - 1);
+ c = end - 1;
}
c -= row.pos();
{
LyXText * lt = bv->getLyXText();
- //if (!lt->selection.set())
- // lt->selection.cursor = lt->cursor;
+// if (!lt->selection.set())
+// lt->selection.cursor = lt->cursor;
if (selecting || lt->selection.mark())
lt->setSelection();