mirror of
https://git.lyx.org/repos/lyx.git
synced 2025-01-11 11:08:41 +00:00
remove lastPos and use endpos instead
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@7984 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
1d9eeae1ea
commit
5be51b4fb7
@ -11,13 +11,13 @@
|
||||
|
||||
#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;
|
||||
|
||||
@ -68,7 +68,7 @@ void Bidi::computeTables(Paragraph const & par,
|
||||
}
|
||||
|
||||
start_ = row.pos();
|
||||
end_ = lastPos(par, row);
|
||||
end_ = row.endpos() - 1;
|
||||
|
||||
if (start_ > end_) {
|
||||
start_ = -1;
|
||||
|
@ -1,3 +1,14 @@
|
||||
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
|
||||
|
@ -24,25 +24,16 @@ using std::min;
|
||||
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;
|
||||
}
|
||||
|
||||
@ -51,7 +42,7 @@ int numberOfSeparators(Paragraph const & par, Row const & row)
|
||||
// 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!
|
||||
@ -78,7 +69,7 @@ int numberOfHfills(Paragraph const & par, Row const & row)
|
||||
// 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!
|
||||
|
@ -18,8 +18,6 @@
|
||||
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);
|
||||
|
@ -343,8 +343,7 @@ public:
|
||||
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);
|
||||
|
||||
|
@ -414,7 +414,7 @@ Paragraph::highestFontInRange(pos_type startpos, pos_type endpos,
|
||||
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;
|
||||
|
@ -257,7 +257,7 @@ void RowPainter::paintArabicComposeChar(pos_type & vpos)
|
||||
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
|
||||
@ -274,7 +274,7 @@ void RowPainter::paintChars(pos_type & vpos, bool hebrew, bool arabic)
|
||||
++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))
|
||||
@ -437,10 +437,10 @@ void RowPainter::paintSelection()
|
||||
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) {
|
||||
@ -489,9 +489,9 @@ void RowPainter::paintSelection()
|
||||
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_)
|
||||
@ -906,10 +906,10 @@ void RowPainter::paintLast()
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@ -920,7 +920,7 @@ void RowPainter::paintText()
|
||||
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);
|
||||
|
43
src/text.C
43
src/text.C
@ -507,6 +507,7 @@ void LyXText::rowBreakPoint(ParagraphList::iterator pit, Row & row) const
|
||||
// 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);
|
||||
@ -534,6 +535,7 @@ void LyXText::rowBreakPoint(ParagraphList::iterator pit, Row & row) const
|
||||
}
|
||||
|
||||
char const c = pit->getChar(i);
|
||||
|
||||
if (i > endPosOfFontSpan) {
|
||||
font = getFont(pit, i);
|
||||
endPosOfFontSpan = pit->getEndPosOfFontSpan(i);
|
||||
@ -571,7 +573,7 @@ void LyXText::rowBreakPoint(ParagraphList::iterator pit, Row & row) const
|
||||
}
|
||||
// exit on last registered breakpoint:
|
||||
if (i + 1 < end)
|
||||
break;
|
||||
break;
|
||||
}
|
||||
|
||||
InsetOld * in = pit->getInset(i);
|
||||
@ -608,11 +610,13 @@ void LyXText::fill(ParagraphList::iterator pit, Row & row, int paper_width) cons
|
||||
{
|
||||
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()
|
||||
@ -621,15 +625,18 @@ void LyXText::fill(ParagraphList::iterator pit, Row & row, int paper_width) cons
|
||||
} 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))
|
||||
@ -648,10 +655,10 @@ void LyXText::fill(ParagraphList::iterator pit, Row & row, int paper_width) cons
|
||||
++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;
|
||||
@ -752,7 +759,7 @@ void LyXText::setHeightOfRow(ParagraphList::iterator pit, Row & row)
|
||||
// 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);
|
||||
@ -1150,7 +1157,7 @@ void LyXText::insertChar(char c)
|
||||
|
||||
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) {
|
||||
@ -1193,9 +1200,8 @@ void LyXText::prepareToPrint(ParagraphList::iterator pit, Row & row) const
|
||||
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?
|
||||
@ -1271,13 +1277,13 @@ void LyXText::prepareToPrint(ParagraphList::iterator pit, Row & row) const
|
||||
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;
|
||||
}
|
||||
}
|
||||
@ -1539,10 +1545,10 @@ void LyXText::deleteWordBackward()
|
||||
// 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.
|
||||
@ -1553,11 +1559,10 @@ void LyXText::deleteLineForward()
|
||||
cursor = tmpcursor;
|
||||
setSelection();
|
||||
// What is this test for ??? (JMarc)
|
||||
if (!selection.set()) {
|
||||
if (!selection.set())
|
||||
deleteWordForward();
|
||||
} else {
|
||||
else
|
||||
cutSelection(true, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
62
src/text2.C
62
src/text2.C
@ -1307,10 +1307,15 @@ void LyXText::setCursor(LyXCursor & cur, paroffset_type par,
|
||||
// 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()
|
||||
@ -1318,10 +1323,10 @@ void LyXText::setCursor(LyXCursor & cur, paroffset_type par,
|
||||
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()) {
|
||||
@ -1333,16 +1338,15 @@ void LyXText::setCursor(LyXCursor & cur, paroffset_type par,
|
||||
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();
|
||||
@ -1350,13 +1354,14 @@ float LyXText::getCursorX(ParagraphList::iterator pit, Row const & row,
|
||||
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);
|
||||
@ -1367,15 +1372,15 @@ float LyXText::getCursorX(ParagraphList::iterator pit, Row const & row,
|
||||
|
||||
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);
|
||||
}
|
||||
@ -1456,7 +1461,7 @@ pos_type LyXText::getColumnNearX(ParagraphList::iterator pit,
|
||||
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();
|
||||
|
||||
@ -1466,17 +1471,17 @@ pos_type LyXText::getColumnNearX(ParagraphList::iterator pit,
|
||||
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) {
|
||||
@ -1507,8 +1512,7 @@ pos_type LyXText::getColumnNearX(ParagraphList::iterator pit,
|
||||
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
|
||||
@ -1522,8 +1526,8 @@ pos_type LyXText::getColumnNearX(ParagraphList::iterator pit,
|
||||
: 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)
|
||||
@ -1537,12 +1541,12 @@ pos_type LyXText::getColumnNearX(ParagraphList::iterator pit,
|
||||
}
|
||||
}
|
||||
|
||||
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();
|
||||
|
@ -76,8 +76,8 @@ namespace {
|
||||
{
|
||||
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();
|
||||
|
Loading…
Reference in New Issue
Block a user