never ask for one past last

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@6479 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Lars Gullik Bjønnes 2003-03-13 10:30:28 +00:00
parent a44d452b15
commit a915be94cb
8 changed files with 115 additions and 58 deletions

View File

@ -1,20 +1,16 @@
src/BufferView.C
src/BufferView_pimpl.C
src/Chktex.C
src/CutAndPaste.C
src/LColor.C
src/LaTeX.C
src/LyXAction.C
src/MenuBackend.C
src/buffer.C
src/bufferlist.C
src/BufferView.C
src/bufferview_funcs.C
src/BufferView_pimpl.C
src/Chktex.C
src/converter.C
src/CutAndPaste.C
src/debug.C
src/exporter.C
src/format.C
src/frontends/LyXView.C
src/frontends/controllers/ButtonController.h
src/frontends/controllers/biblio.C
src/frontends/controllers/character.C
src/frontends/controllers/ControlAboutlyx.C
src/frontends/controllers/ControlBibtex.C
src/frontends/controllers/ControlCharacter.C
@ -30,14 +26,14 @@ src/frontends/controllers/ControlSearch.C
src/frontends/controllers/ControlSpellchecker.C
src/frontends/controllers/ControlThesaurus.C
src/frontends/controllers/ControlVCLog.C
src/frontends/controllers/biblio.C
src/frontends/controllers/character.C
src/frontends/controllers/frnt_lang.C
src/frontends/controllers/helper_funcs.C
src/frontends/gnome/GLog.C
src/frontends/LyXView.C
src/frontends/qt2/Alert_pimpl.C
src/frontends/qt2/Dialogs3.C
src/frontends/qt2/FileDialog.C
src/frontends/qt2/lengthcombo.C
src/frontends/qt2/QAbout.C
src/frontends/qt2/QBibitem.C
src/frontends/qt2/QBibtex.C
@ -50,16 +46,16 @@ src/frontends/qt2/QCommandBuffer.C
src/frontends/qt2/QDelimiterDialog.C
src/frontends/qt2/QDocument.C
src/frontends/qt2/QDocumentDialog.C
src/frontends/qt2/QERT.C
src/frontends/qt2/QError.C
src/frontends/qt2/QERT.C
src/frontends/qt2/QExternal.C
src/frontends/qt2/QExternalDialog.C
src/frontends/qt2/QFloat.C
src/frontends/qt2/QGraphics.C
src/frontends/qt2/QGraphicsDialog.C
src/frontends/qt2/QInclude.C
src/frontends/qt2/QLPrintDialog.C
src/frontends/qt2/QLog.C
src/frontends/qt2/QLPrintDialog.C
src/frontends/qt2/QMathDialog.C
src/frontends/qt2/QMathMatrixDialog.C
src/frontends/qt2/QMinipage.C
@ -72,18 +68,19 @@ src/frontends/qt2/QSearch.C
src/frontends/qt2/QSendto.C
src/frontends/qt2/QShowFile.C
src/frontends/qt2/QSpellchecker.C
src/frontends/qt2/Qt2BC.h
src/frontends/qt2/QTabular.C
src/frontends/qt2/QTabularCreate.C
src/frontends/qt2/QTexinfo.C
src/frontends/qt2/QThesaurus.C
src/frontends/qt2/QToc.C
src/frontends/qt2/QtView.C
src/frontends/qt2/QURL.C
src/frontends/qt2/QVCLog.C
src/frontends/qt2/QWrap.C
src/frontends/qt2/QtView.C
src/frontends/qt2/lengthcombo.C
src/frontends/xforms/Alert_pimpl.C
src/frontends/xforms/ColorHandler.C
src/frontends/xforms/combox.C
src/frontends/xforms/Dialogs3.C
src/frontends/xforms/FileDialog.C
src/frontends/xforms/FormAboutlyx.C
@ -95,8 +92,8 @@ src/frontends/xforms/FormCharacter.C
src/frontends/xforms/FormCitation.C
src/frontends/xforms/FormDialogView.C
src/frontends/xforms/FormDocument.C
src/frontends/xforms/FormERT.C
src/frontends/xforms/FormError.C
src/frontends/xforms/FormERT.C
src/frontends/xforms/FormExternal.C
src/frontends/xforms/FormFiledialog.C
src/frontends/xforms/FormFloat.C
@ -128,15 +125,15 @@ src/frontends/xforms/FormToc.C
src/frontends/xforms/FormUrl.C
src/frontends/xforms/FormVCLog.C
src/frontends/xforms/FormWrap.C
src/frontends/xforms/Menubar_pimpl.C
src/frontends/xforms/XMiniBuffer.C
src/frontends/xforms/combox.C
src/frontends/xforms/input_validators.C
src/frontends/xforms/Menubar_pimpl.C
src/frontends/xforms/xformsBC.h
src/frontends/xforms/xforms_helpers.C
src/frontends/xforms/XMiniBuffer.C
src/gettext.h
src/importer.C
src/insets/inset.C
src/insets/insetbibtex.C
src/insets/inset.C
src/insets/insetcaption.C
src/insets/inseterror.C
src/insets/insetert.C
@ -163,12 +160,15 @@ src/insets/insetwrap.C
src/ispell.C
src/kbsequence.C
src/language.C
src/LaTeX.C
src/LColor.C
src/lengthcommon.C
src/LyXAction.C
src/lyx_cb.C
src/lyx_main.C
src/lyxfind.C
src/lyxfont.C
src/lyxfunc.C
src/lyx_main.C
src/lyxrc.C
src/lyxtextclasslist.C
src/lyxvc.C
@ -177,10 +177,12 @@ src/mathed/formulamacro.C
src/mathed/math_hullinset.C
src/mathed/math_parboxinset.C
src/mathed/ref_inset.C
src/MenuBackend.C
src/paragraph.C
src/paragraph_funcs.C
src/rowpainter.C
src/support/filetools.C
src/tabular.C
src/text.C
src/text2.C
src/text3.C
src/text.C

View File

@ -1,3 +1,28 @@
2003-03-13 Lars Gullik Bjønnes <larsbj@gullik.net>
* text2.C (setCursor): never ask for one past last
(setCursor): add some debugging messages.
* text.C (singleWidth): never ask for one past last
(singleWidth): ditto
(leftMargin): ditto
(rightMargin): ditto
(rowBreakPoint): ditto
(setHeightOfRow): ditto
(prepareToPrint): ditto
* rowpainter.C (paintBackground): never ask for one past last
(paintText): never ask for one past last
* paragraph_pimpl.C (getChar): make the assert stricter, never
allow the one past last pos to be taken
* paragraph.C (getChar): ws changes only
* lyxrow.C (nextRowIsAllInset): never ask for one past last
(numberOfSeparators): ditto
(numberOfHfills): ditto
2003-03-12 John Levon <levon@movementarian.org>
* author.h:

View File

@ -159,6 +159,9 @@ namespace {
bool nextRowIsAllInset(Row const & row, pos_type last)
{
if (last + 1 >= row.par()->size())
return false;
if (!row.par()->isInset(last + 1))
return false;
@ -192,7 +195,7 @@ int Row::numberOfSeparators() const
pos_type p = max(pos(), par()->beginningOfBody());
int n = 0;
for (; p <= last; ++p) {
for (; p < last; ++p) {
if (par()->isSeparator(p)) {
++n;
}
@ -208,7 +211,7 @@ int Row::numberOfHfills() const
// hfill *DO* count at the beginning of paragraphs!
if (first) {
while (first <= last && par()->isHfill(first)) {
while (first < last && par()->isHfill(first)) {
++first;
}
}
@ -218,7 +221,7 @@ int Row::numberOfHfills() const
int n = 0;
// last, because the end is ignored!
for (pos_type p = first; p <= last; ++p) {
for (pos_type p = first; p < last; ++p) {
if (par()->isHfill(p))
++n;
}

View File

@ -788,7 +788,7 @@ int Paragraph::beginningOfBody() const
char previous_char = 0;
char temp = 0;
if (i < size()) {
previous_char = getChar(i);
previous_char = getChar(i);
if (!isNewline(i)) {
++i;
while (i < size() && previous_char != ' ') {

View File

@ -252,12 +252,14 @@ void Paragraph::Pimpl::rejectChange(pos_type start, pos_type end)
Paragraph::value_type Paragraph::Pimpl::getChar(pos_type pos) const
{
// This is in the critical path for loading!
pos_type const siz = size();
lyx::Assert(pos <= siz);
//lyx::Assert(pos <= siz);
// This is stronger, and I belive that this is the assertion
// that we should really use. (Lgb)
//Assert(pos < size());
lyx::Assert(pos < size());
#if 0
// This is in the critical path for loading!
pos_type const siz = size();
// Then this has no meaning. (Lgb)
if (!siz || pos == siz) {
@ -266,7 +268,7 @@ Paragraph::value_type Paragraph::Pimpl::getChar(pos_type pos) const
<< " is a bit silly !" << endl;
return '\0';
}
#endif
return text[pos];
}

View File

@ -312,7 +312,8 @@ bool RowPainter::paintBackground()
Inset const * inset = 0;
if (!bv_.screen().forceClear() && last == row_.pos()
&& par_.isInset(row_.pos())) {
&& row_.pos() < par_.size()
&& par_.isInset(row_.pos())) {
inset = par_.getInset(row_.pos());
clear_area = inset->doClearArea();
}
@ -898,6 +899,11 @@ bool RowPainter::paintText()
break;
pos_type pos = text_.vis2log(vpos);
if (pos >= par_.size()) {
++vpos;
continue;
}
if (x_ + singleWidth(pos) < 0) {
x_ += singleWidth(pos);
++vpos;

View File

@ -206,6 +206,9 @@ unsigned char LyXText::transformChar(unsigned char c, Paragraph * par,
int LyXText::singleWidth(BufferView * bview, Paragraph * par,
pos_type pos) const
{
if (pos >= par->size())
return 0;
char const c = par->getChar(pos);
return singleWidth(bview, par, pos, c);
}
@ -214,6 +217,9 @@ int LyXText::singleWidth(BufferView * bview, Paragraph * par,
int LyXText::singleWidth(BufferView * bview, Paragraph * par,
pos_type pos, char c) const
{
if (pos >= par->size())
return 0;
LyXFont const font = getFont(bview->buffer(), par, pos);
// The most common case is handled first (Asger)
@ -422,10 +428,12 @@ bool LyXText::isBoundary(Buffer const * buf, Paragraph * par,
int LyXText::leftMargin(BufferView * bview, Row const * row) const
{
Inset * ins;
if ((row->par()->getChar(row->pos()) == Paragraph::META_INSET) &&
(ins=row->par()->getInset(row->pos())) &&
(ins->needFullRow() || ins->display()))
return LEFT_MARGIN;
if (row->pos() < row->par()->size())
if ((row->par()->getChar(row->pos()) == Paragraph::META_INSET) &&
(ins = row->par()->getInset(row->pos())) &&
(ins->needFullRow() || ins->display()))
return LEFT_MARGIN;
LyXTextClass const & tclass =
bview->buffer()->params.getLyXTextClass();
@ -615,10 +623,12 @@ int LyXText::leftMargin(BufferView * bview, Row const * row) const
int LyXText::rightMargin(Buffer const & buf, Row const & row) const
{
Inset * ins;
if ((row.par()->getChar(row.pos()) == Paragraph::META_INSET) &&
(ins=row.par()->getInset(row.pos())) &&
(ins->needFullRow() || ins->display()))
return PAPER_MARGIN;
if (row.pos() < row.par()->size())
if ((row.par()->getChar(row.pos()) == Paragraph::META_INSET) &&
(ins=row.par()->getInset(row.pos())) &&
(ins->needFullRow() || ins->display()))
return PAPER_MARGIN;
LyXTextClass const & tclass = buf.params.getLyXTextClass();
LyXLayout_ptr const & layout = row.par()->layout();
@ -722,7 +732,9 @@ LyXText::rowBreakPoint(BufferView & bv, Row const & row) const
pos_type const body_pos = par->beginningOfBody();
pos_type const last = par->size();
pos_type point = last;
pos_type i = pos;
if (pos == last)
return last;
// Now we iterate through until we reach the right margin
// or the end of the par, then choose the possible break
@ -734,7 +746,8 @@ LyXText::rowBreakPoint(BufferView & bv, Row const & row) const
// pixel width since last breakpoint
int chunkwidth = 0;
for (i = pos; i < last; ++i) {
pos_type i = pos;
for (; i < last; ++i) {
if (par->isNewline(i)) {
point = i;
@ -976,7 +989,7 @@ void LyXText::setHeightOfRow(BufferView * bview, Row * row) const
int maxwidth = 0;
// Check if any insets are larger
for (pos_type pos = row->pos(); pos <= pos_end; ++pos) {
for (pos_type pos = row->pos(); pos < pos_end; ++pos) {
if (row->par()->isInset(pos)) {
tmpfont = getFont(bview->buffer(), row->par(), pos);
tmpinset = row->par()->getInset(pos);
@ -1594,7 +1607,8 @@ void LyXText::insertChar(BufferView * bview, char c)
}
// the display inset stuff
if (cursor.row()->par()->isInset(cursor.row()->pos())) {
if (cursor.row()->pos() < cursor.row()->par()->size()
&& cursor.row()->par()->isInset(cursor.row()->pos())) {
Inset * inset = cursor.row()->par()->getInset(cursor.row()->pos());
if (inset && (inset->display() || inset->needFullRow())) {
// force a new break
@ -1814,8 +1828,9 @@ void LyXText::prepareToPrint(BufferView * bview,
// center displayed insets
Inset * inset;
if (row->par()->isInset(row->pos())
&& (inset=row->par()->getInset(row->pos()))
if (row->pos() < row->par()->size()
&& row->par()->isInset(row->pos())
&& (inset = row->par()->getInset(row->pos()))
&& (inset->display())) // || (inset->scroll() < 0)))
align = (inset->lyxCode() == Inset::MATHMACRO_CODE)
? LYX_ALIGN_BLOCK : LYX_ALIGN_CENTER;
@ -1991,7 +2006,7 @@ void LyXText::getWord(LyXCursor & from, LyXCursor & to,
// Move cursor to the beginning, when not already there.
if (from.pos() && !from.par()->isSeparator(from.pos() - 1)
&& !(from.par()->isKomma(from.pos() - 1)
|| from.par()->isNewline(from.pos() - 1)))
|| from.par()->isNewline(from.pos() - 1)))
cursorLeftOneWord(from);
break;
case PREVIOUS_WORD:

View File

@ -1769,8 +1769,9 @@ void LyXText::setCursor(BufferView * bview, LyXCursor & cur, Paragraph * par,
Inset * ins;
if (row->previous() && pos &&
row->previous()->par() == row->par() &&
pos < par->size() &&
par->getChar(pos) == Paragraph::META_INSET &&
(ins=par->getInset(pos)) && (ins->needFullRow() || ins->display()))
(ins = par->getInset(pos)) && (ins->needFullRow() || ins->display()))
{
row = row->previous();
y -= row->height();
@ -1786,13 +1787,16 @@ void LyXText::setCursor(BufferView * bview, LyXCursor & cur, Paragraph * par,
// None of these should happen, but we're scaredy-cats
if (pos > par->size()) {
lyxerr << "dont like 1 please report" << endl;
pos = 0;
cur.pos(0);
} else if (pos > last + 1) {
lyxerr << "dont like 2 please report" << endl;
// This shouldn't happen.
pos = last + 1;
cur.pos(pos);
} else if (pos < row->pos()) {
lyxerr << "dont like 3 please report" << endl;
pos = row->pos();
cur.pos(pos);
}